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