Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
16 / 16 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
PropertyDefinition | |
100.00% |
16 / 16 |
|
100.00% |
3 / 3 |
3 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
__toString | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
createRandom | |
100.00% |
14 / 14 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | namespace Apie\Maker\BoundedContext\Dtos; |
3 | |
4 | use Apie\Core\Attributes\FakeMethod; |
5 | use Apie\Core\Dto\DtoInterface; |
6 | use Apie\Maker\Enums\NullableOption; |
7 | use Apie\Maker\Enums\PrimitiveType; |
8 | use Apie\Maker\ValueObjects\ClassNameReference; |
9 | use Apie\Maker\ValueObjects\PropertyDefinitionName; |
10 | use Apie\Maker\ValueObjects\VendorValueObject; |
11 | use Faker\Generator; |
12 | use Stringable; |
13 | |
14 | #[FakeMethod('createRandom')] |
15 | final class PropertyDefinition implements DtoInterface, Stringable |
16 | { |
17 | public function __construct( |
18 | public VendorValueObject|PrimitiveType|ClassNameReference $type, |
19 | public PropertyDefinitionName $name, |
20 | public bool $requiredOnConstruction, |
21 | public bool $writable, |
22 | public bool $readable, |
23 | public NullableOption $nullable = NullableOption::AlwaysNull, |
24 | ) { |
25 | } |
26 | |
27 | public function __toString(): string |
28 | { |
29 | return $this->name->toNative(); |
30 | } |
31 | |
32 | public static function createRandom(Generator $faker): self |
33 | { |
34 | $variableOptions = $faker->randomElement([ |
35 | [true, true, true, NullableOption::AlwaysNull], |
36 | [false, true, true, NullableOption::AlwaysNull], |
37 | [true, false, true, NullableOption::AlwaysNull], |
38 | [true, true, true, NullableOption::NeverNullable], |
39 | [true, false, true, NullableOption::NeverNullable], |
40 | [true, true, true, NullableOption::InitialNull], |
41 | [true, false, true, NullableOption::InitialNull], |
42 | ]); |
43 | return new self( |
44 | $faker->fakeClass($faker->randomElement([VendorValueObject::class, PrimitiveType::class])), |
45 | PropertyDefinitionName::createRandom($faker), |
46 | ...$variableOptions |
47 | ); |
48 | } |
49 | } |