Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
11 / 11 |
|
100.00% |
5 / 5 |
CRAP | |
100.00% |
1 / 1 |
| Animal | |
100.00% |
11 / 11 |
|
100.00% |
5 / 5 |
5 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getId | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| setAnimalName | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| getAnimalName | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getDiscriminatorMapping | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | namespace Apie\IntegrationTests\Apie\TypeDemo\Resources; |
| 3 | |
| 4 | use Apie\Core\Attributes\ExampleValue; |
| 5 | use Apie\Core\Entities\PolymorphicEntityInterface; |
| 6 | use Apie\Core\Other\DiscriminatorConfig; |
| 7 | use Apie\Core\Other\DiscriminatorMapping; |
| 8 | use Apie\IntegrationTests\Apie\TypeDemo\Entities\Bird; |
| 9 | use Apie\IntegrationTests\Apie\TypeDemo\Entities\Fish; |
| 10 | use Apie\IntegrationTests\Apie\TypeDemo\Entities\Mammal; |
| 11 | use Apie\IntegrationTests\Apie\TypeDemo\Identifiers\AnimalIdentifier; |
| 12 | use Apie\Serializer\Lists\SerializedHashmap; |
| 13 | use Apie\TextValueObjects\FirstName; |
| 14 | |
| 15 | #[ExampleValue( |
| 16 | example: new SerializedHashmap([ |
| 17 | 'id' => '123e4567-e89b-12d3-a456-426614174000', |
| 18 | 'animalName' => 'Charlie', |
| 19 | 'name' => 'elephant', |
| 20 | 'type' => 'mammal' |
| 21 | ]), |
| 22 | name: 'Example elephant' |
| 23 | )] |
| 24 | #[ExampleValue( |
| 25 | example: new SerializedHashmap([ |
| 26 | 'id' => '123e4567-e89b-12d3-a456-426614174001', |
| 27 | 'animalName' => 'Polly', |
| 28 | 'name' => 'ostrich', |
| 29 | 'type' => 'bird' |
| 30 | ]), |
| 31 | name: 'Example ostrich' |
| 32 | )] |
| 33 | #[ExampleValue( |
| 34 | example: new SerializedHashmap([ |
| 35 | 'id' => '123e4567-e89b-12d3-a456-426614174002', |
| 36 | 'animalName' => 'Nemo', |
| 37 | 'name' => 'shark', |
| 38 | 'type' => 'fish' |
| 39 | ]), |
| 40 | name: 'Example fish' |
| 41 | )] |
| 42 | abstract class Animal implements PolymorphicEntityInterface |
| 43 | { |
| 44 | public function __construct( |
| 45 | protected AnimalIdentifier $id, |
| 46 | private FirstName $animalName, |
| 47 | ) { |
| 48 | } |
| 49 | |
| 50 | final public function getId(): AnimalIdentifier |
| 51 | { |
| 52 | return $this->id; |
| 53 | } |
| 54 | |
| 55 | final public function setAnimalName(FirstName $animalName): self |
| 56 | { |
| 57 | $this->animalName = $animalName; |
| 58 | return $this; |
| 59 | } |
| 60 | |
| 61 | final public function getAnimalName(): FirstName |
| 62 | { |
| 63 | return $this->animalName; |
| 64 | } |
| 65 | |
| 66 | public static function getDiscriminatorMapping(): DiscriminatorMapping |
| 67 | { |
| 68 | return new DiscriminatorMapping( |
| 69 | 'type', |
| 70 | new DiscriminatorConfig('mammal', Mammal::class), |
| 71 | new DiscriminatorConfig('bird', Bird::class), |
| 72 | new DiscriminatorConfig('fish', Fish::class) |
| 73 | ); |
| 74 | } |
| 75 | } |