1 | <?php |
||
18 | abstract class AbstractTarget implements TargetInterface |
||
19 | { |
||
20 | /** |
||
21 | * @var int|string |
||
22 | */ |
||
23 | protected $id; |
||
24 | |||
25 | /** |
||
26 | * @var string |
||
27 | */ |
||
28 | protected $type; |
||
29 | |||
30 | 7 | public function __construct($id, $type) |
|
35 | |||
36 | /** |
||
37 | * @return int |
||
38 | */ |
||
39 | 1 | public function getId() |
|
40 | { |
||
41 | 1 | return $this->id; |
|
42 | } |
||
43 | |||
44 | /** |
||
45 | * {@inheritdoc} |
||
46 | */ |
||
47 | public function getType() |
||
51 | |||
52 | /** |
||
53 | * @return string |
||
54 | */ |
||
55 | 3 | public function getUniqueId() |
|
56 | { |
||
57 | 3 | return implode(':', array_filter([$this->type, $this->id])); |
|
58 | } |
||
59 | |||
60 | /** |
||
61 | * @return bool |
||
62 | */ |
||
63 | 5 | public function equals(TargetInterface $other) |
|
64 | { |
||
65 | 5 | return $this->id === null && $other->id === null |
|
|
|||
66 | ? (string) $this->type === (string) $other->type |
||
67 | 5 | : (string) $this->id === (string) $other->id; |
|
68 | } |
||
69 | |||
70 | public function jsonSerialize() |
||
74 | } |
||
75 |
If you access a property on an interface, you most likely code against a concrete implementation of the interface.
Available Fixes
Adding an additional type check:
Changing the type hint: