Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
55.56% |
5 / 9 |
|
42.86% |
3 / 7 |
CRAP | |
0.00% |
0 / 1 |
Identifier | |
55.56% |
5 / 9 |
|
42.86% |
3 / 7 |
13.62 | |
0.00% |
0 / 1 |
getRegularExpression | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
createRandom | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 | |||
humanize | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
toCamelCaseSlug | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
toKebabCaseSlug | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
toPascalCaseSlug | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
toSnakeCaseSlug | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | namespace Apie\Core\Identifiers; |
3 | |
4 | use Apie\Core\Attributes\Description; |
5 | use Apie\Core\Utils\IdentifierConstants; |
6 | use Apie\Core\ValueObjects\Interfaces\HasRegexValueObjectInterface; |
7 | use Apie\Core\ValueObjects\IsStringWithRegexValueObject; |
8 | use Faker\Generator; |
9 | |
10 | /** |
11 | * Indicate an identifier as id. |
12 | */ |
13 | #[Description('Simple identifier/slug all in lower case for example "example"')] |
14 | class Identifier implements HasRegexValueObjectInterface |
15 | { |
16 | use IsStringWithRegexValueObject; |
17 | |
18 | public static function getRegularExpression(): string |
19 | { |
20 | return '/^[a-z][a-z0-9]*$/'; |
21 | } |
22 | |
23 | public static function createRandom(Generator $faker): static |
24 | { |
25 | if ($faker->boolean()) { |
26 | return static::fromNative(strtolower($faker->randomElement(IdentifierConstants::RANDOM_IDENTIFIERS))); |
27 | } |
28 | return static::fromNative(implode('', $faker->words($faker->numberBetween(1, 3)))); |
29 | } |
30 | |
31 | public function humanize(): string |
32 | { |
33 | return $this->toNative(); |
34 | } |
35 | |
36 | public function toCamelCaseSlug(): CamelCaseSlug |
37 | { |
38 | return new CamelCaseSlug($this->internal); |
39 | } |
40 | |
41 | public function toKebabCaseSlug(): KebabCaseSlug |
42 | { |
43 | return new KebabCaseSlug($this->internal); |
44 | } |
45 | |
46 | public function toPascalCaseSlug(): PascalCaseSlug |
47 | { |
48 | return new PascalCaseSlug(ucfirst($this->internal)); |
49 | } |
50 | |
51 | public function toSnakeCaseSlug(): SnakeCaseSlug |
52 | { |
53 | return new SnakeCaseSlug($this->internal); |
54 | } |
55 | } |