1 | <?php |
||
19 | trait HasInheritance |
||
20 | { |
||
21 | /** |
||
22 | * @var string|null |
||
23 | */ |
||
24 | protected $extends; |
||
25 | |||
26 | /** |
||
27 | * @var string[]|array |
||
28 | */ |
||
29 | protected $extendedBy = []; |
||
30 | |||
31 | /** |
||
32 | * @param string|TypeDefinition $type |
||
33 | * @return TypeDefinition |
||
34 | */ |
||
35 | abstract protected function fetch($type): TypeDefinition; |
||
36 | |||
37 | /** |
||
38 | * @return iterable|TypeDefinition[] |
||
39 | */ |
||
40 | public function inheritedBy(): iterable |
||
46 | |||
47 | /** |
||
48 | * @return null|TypeDefinition |
||
49 | */ |
||
50 | 8 | public function getInheritedParent(): ?TypeDefinition |
|
54 | |||
55 | /** |
||
56 | * @return bool |
||
57 | */ |
||
58 | public function hasInheritance(): bool |
||
62 | |||
63 | /** |
||
64 | * @param TypeDefinition|string $definition |
||
65 | * @return ProvidesInheritance|$this |
||
66 | */ |
||
67 | 25 | public function extends($definition): ProvidesInheritance |
|
78 | |||
79 | /** |
||
80 | * @param TypeDefinition|string $definition |
||
81 | * @return ProvidesInheritance|$this |
||
82 | */ |
||
83 | public function extendsBy($definition): ProvidesInheritance |
||
92 | |||
93 | /** |
||
94 | * @param TypeDefinition|string $type |
||
95 | * @return bool |
||
96 | */ |
||
97 | 8 | public function extendsOf($type): bool |
|
101 | |||
102 | /** |
||
103 | * @param TypeDefinition|string $type |
||
104 | * @return bool |
||
105 | */ |
||
106 | 8 | public function instanceOf($type): bool |
|
135 | } |
||
136 |
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.