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