Total Complexity | 9 |
Total Lines | 47 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
8 | class DiscriminatorColumn implements GetterInterface |
||
9 | { |
||
10 | /** |
||
11 | * @var string |
||
12 | */ |
||
13 | private $name; |
||
14 | |||
15 | /** |
||
16 | * @var array |
||
17 | */ |
||
18 | private $discriminatorMapping; |
||
19 | |||
20 | public function __construct(string $name, array $discriminatorMapping) |
||
21 | { |
||
22 | $this->name = $name; |
||
23 | $this->discriminatorMapping = $discriminatorMapping; |
||
24 | } |
||
25 | |||
26 | public function getName(): string |
||
27 | { |
||
28 | return $this->name; |
||
29 | } |
||
30 | |||
31 | public function getValue($object) |
||
32 | { |
||
33 | $objectClassName = get_class($object); |
||
34 | foreach ($this->discriminatorMapping as $value => $className) { |
||
35 | if ($objectClassName === $className) { |
||
36 | return $value; |
||
37 | } |
||
38 | } |
||
39 | foreach ($this->discriminatorMapping as $value => $className) { |
||
40 | if (is_a($objectClassName, $className)) { |
||
41 | return $value; |
||
42 | } |
||
43 | } |
||
44 | return null; |
||
45 | } |
||
46 | |||
47 | public function toType(): ?Type |
||
48 | { |
||
49 | return new Type(Type::BUILTIN_TYPE_STRING); |
||
50 | } |
||
51 | |||
52 | public function getPriority(): int |
||
55 | } |
||
56 | } |
||
57 |