Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
3 / 3
CRAP
100.00% covered (success)
100.00%
1 / 1
Animal
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
3 / 3
3
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getId
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getDiscriminatorMapping
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2namespace Apie\Fixtures\Entities\Polymorphic;
3
4use Apie\Core\Attributes\ClassStoreOptions;
5use Apie\Core\Entities\PolymorphicEntityInterface;
6use Apie\Core\Enums\SortingOrder;
7use Apie\Core\Other\DiscriminatorConfig;
8use Apie\Core\Other\DiscriminatorMapping;
9
10#[ClassStoreOptions(defaultSortingOrder: SortingOrder::Ascending)]
11abstract class Animal implements PolymorphicEntityInterface
12{
13    private AnimalIdentifier $id;
14
15    public function __construct(?AnimalIdentifier $id = null)
16    {
17        $this->id = $id ?? AnimalIdentifier::createRandom();
18    }
19
20    public function getId(): AnimalIdentifier
21    {
22        return $this->id;
23    }
24
25    final public static function getDiscriminatorMapping(): DiscriminatorMapping
26    {
27        return new DiscriminatorMapping(
28            'animalType',
29            new DiscriminatorConfig('cow', Cow::class),
30            new DiscriminatorConfig('elephant', Elephant::class),
31            new DiscriminatorConfig('fish', Fish::class)
32        );
33    }
34}