Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
11 / 11 |
|
100.00% |
4 / 4 |
CRAP | |
100.00% |
1 / 1 |
| SupportedFakerExtension | |
100.00% |
11 / 11 |
|
100.00% |
4 / 4 |
5 | |
100.00% |
1 / 1 |
| createFaker | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
| getSupportedExtensions | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
2 | |||
| getOptions | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getRegularExpression | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace Apie\Faker\ValueObjects; |
| 4 | |
| 5 | use Apie\Core\Attributes\Description; |
| 6 | use Apie\Core\Lists\StringSet; |
| 7 | use Apie\Core\ValueObjects\Interfaces\HasRegexValueObjectInterface; |
| 8 | use Apie\Core\ValueObjects\Interfaces\LimitedOptionsInterface; |
| 9 | use Apie\Core\ValueObjects\Interfaces\StringValueObjectInterface; |
| 10 | use Apie\Core\ValueObjects\IsStringWithRegexValueObject; |
| 11 | use Apie\Faker\ApieObjectFaker; |
| 12 | use Apie\Faker\FileFakerFactory; |
| 13 | |
| 14 | use Faker\Factory; |
| 15 | use Faker\Generator; |
| 16 | |
| 17 | #[Description('A file extension that is supported by the faker library')] |
| 18 | class SupportedFakerExtension implements LimitedOptionsInterface, StringValueObjectInterface, HasRegexValueObjectInterface |
| 19 | { |
| 20 | use IsStringWithRegexValueObject; |
| 21 | |
| 22 | |
| 23 | private static function createFaker(): Generator |
| 24 | { |
| 25 | $faker = Factory::create(); |
| 26 | $faker->addProvider(ApieObjectFaker::createWithDefaultFakers($faker)); |
| 27 | return $faker; |
| 28 | } |
| 29 | |
| 30 | /** |
| 31 | * @return list<string> |
| 32 | */ |
| 33 | private static function getSupportedExtensions(): array |
| 34 | { |
| 35 | $extensions = []; |
| 36 | $faker = self::createFaker(); |
| 37 | foreach (FileFakerFactory::getSupportedFileFakers() as $fileFaker) { |
| 38 | $extensions[] = pathinfo($fileFaker->createOriginalFilename($faker), PATHINFO_EXTENSION); |
| 39 | } |
| 40 | sort($extensions); |
| 41 | |
| 42 | return $extensions; |
| 43 | } |
| 44 | |
| 45 | public static function getOptions(): StringSet |
| 46 | { |
| 47 | return new StringSet(self::getSupportedExtensions()); |
| 48 | } |
| 49 | |
| 50 | public static function getRegularExpression(): string |
| 51 | { |
| 52 | return '/^' . implode('|', self::getSupportedExtensions()) . '$/'; |
| 53 | } |
| 54 | } |