Total Complexity | 17 |
Total Lines | 74 |
Duplicated Lines | 0 % |
Coverage | 84% |
Changes | 0 |
1 | <?php |
||
18 | class Type implements TypeInterface |
||
19 | { |
||
20 | /** |
||
21 | * @var int|string |
||
22 | */ |
||
23 | protected $id; |
||
24 | |||
25 | /** |
||
26 | * @var string |
||
27 | */ |
||
28 | protected $name; |
||
29 | |||
30 | 37 | public function __construct($id, $name = null) |
|
31 | { |
||
32 | 37 | $this->id = $id; |
|
33 | 37 | $this->name = $name; |
|
34 | 37 | } |
|
35 | |||
36 | /** |
||
37 | * {@inheritdoc} |
||
38 | */ |
||
39 | 7 | public function getId() |
|
42 | } |
||
43 | |||
44 | /** |
||
45 | * {@inheritdoc} |
||
46 | */ |
||
47 | 26 | public function getName(): ?string |
|
50 | } |
||
51 | |||
52 | 2 | public function hasName(): bool |
|
53 | { |
||
54 | 2 | return !empty($this->name) && $this->name !== self::ANY && $this->name !== self::NONE; |
|
55 | } |
||
56 | |||
57 | public function getUniqueId() |
||
58 | { |
||
59 | return $this->hasName() ? $this->name : $this->id; |
||
60 | 2 | } |
|
61 | |||
62 | 2 | /** |
|
63 | 2 | * @return bool |
|
64 | */ |
||
65 | public function equals(TypeInterface $other): bool |
||
66 | 22 | { |
|
67 | return $this->id === $other->getId() && |
||
68 | 22 | $this->name === $other->getName(); |
|
69 | 18 | } |
|
70 | 22 | ||
71 | public function matches(TypeInterface $other): bool |
||
72 | { |
||
73 | 22 | return $this->id === self::ANY || $other->getId() === self::ANY |
|
74 | ? $this->checkMatches($this->name, $other->getName()) |
||
75 | 22 | : $this->checkMatches($this->id, $other->getId()); |
|
76 | 1 | } |
|
77 | |||
78 | protected function checkMatches($lhs, $rhs) |
||
85 | } |
||
86 | |||
87 | public function jsonSerialize() |
||
88 | { |
||
92 | ]); |
||
93 | } |
||
95 |