1 | <?php |
||
20 | trait HasInheritance |
||
21 | { |
||
22 | /** |
||
23 | * @var array|string[] |
||
24 | */ |
||
25 | protected $parents = []; |
||
26 | |||
27 | /** |
||
28 | * @return iterable|TypeDefinition[] |
||
29 | */ |
||
30 | 6 | public function getParents(): iterable |
|
36 | |||
37 | /** |
||
38 | * @param string $name |
||
39 | * @return bool |
||
40 | */ |
||
41 | public function hasParent(string $name): bool |
||
45 | |||
46 | /** |
||
47 | * @param string $name |
||
48 | * @return null|TypeDefinition |
||
49 | */ |
||
50 | public function getParent(string $name): ?TypeDefinition |
||
54 | |||
55 | /** |
||
56 | * @param TypeDefinition ...$definitions |
||
57 | * @return ProvidesInheritance|$this |
||
58 | * @throws TypeConflictException |
||
59 | */ |
||
60 | 40 | public function extends(TypeDefinition ...$definitions): ProvidesInheritance |
|
70 | |||
71 | /** |
||
72 | * @param TypeDefinition $def |
||
73 | * @throws TypeConflictException |
||
74 | */ |
||
75 | 40 | private function verifyExtensionType(TypeDefinition $def): void |
|
82 | |||
83 | /** |
||
84 | * @param string $name |
||
85 | * @return bool |
||
86 | */ |
||
87 | public function isExtends(string $name): bool |
||
91 | |||
92 | /** |
||
93 | * @param TypeDefinition $definition |
||
94 | * @return bool |
||
95 | */ |
||
96 | 6 | public function isExtendsDefinition(TypeDefinition $definition): bool |
|
106 | } |
||
107 |
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.