1 | <?php |
||
21 | trait HasInheritance |
||
22 | { |
||
23 | /** |
||
24 | * @var string|null |
||
25 | */ |
||
26 | protected $extends; |
||
27 | |||
28 | /** |
||
29 | * @var string[]|array |
||
30 | */ |
||
31 | protected $extendedBy = []; |
||
32 | |||
33 | /** |
||
34 | * @param string|TypeDefinition $type |
||
35 | * @return TypeDefinition |
||
36 | */ |
||
37 | abstract protected function fetch($type): TypeDefinition; |
||
38 | |||
39 | /** |
||
40 | * @return iterable|TypeDefinition[] |
||
41 | */ |
||
42 | public function inheritedBy(): iterable |
||
48 | |||
49 | /** |
||
50 | * @return null|TypeDefinition |
||
51 | */ |
||
52 | 8 | public function getInheritedParent(): ?TypeDefinition |
|
56 | |||
57 | /** |
||
58 | * @return bool |
||
59 | */ |
||
60 | public function hasInheritance(): bool |
||
64 | |||
65 | /** |
||
66 | * @param TypeDefinition|string $definition |
||
67 | * @return ProvidesInheritance|$this |
||
68 | */ |
||
69 | 25 | public function extends($definition): ProvidesInheritance |
|
80 | |||
81 | /** |
||
82 | * @param TypeDefinition|string $definition |
||
83 | * @return ProvidesInheritance|$this |
||
84 | */ |
||
85 | public function extendsBy($definition): ProvidesInheritance |
||
94 | |||
95 | /** |
||
96 | * @param TypeDefinition|string $type |
||
97 | * @return bool |
||
98 | */ |
||
99 | 8 | public function extendsOf($type): bool |
|
103 | |||
104 | /** |
||
105 | * @param TypeDefinition|string $type |
||
106 | * @return bool |
||
107 | */ |
||
108 | 8 | public function instanceOf($type): bool |
|
154 | } |
||
155 |
This check looks for methods that are used by a trait but not required by it.
To illustrate, let’s look at the following code example
The trait
Idable
provides a methodequalsId
that in turn relies on the methodgetId()
. If this method does not exist on a class mixing in this trait, the method will fail.Adding the
getId()
as an abstract method to the trait will make sure it is available.