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