1 | <?php |
||
21 | trait HasInheritance |
||
22 | { |
||
23 | /** |
||
24 | * @var array|string[] |
||
25 | */ |
||
26 | protected $parents = []; |
||
27 | |||
28 | /** |
||
29 | * @param string|TypeDefinition $type |
||
30 | * @return TypeDefinition |
||
31 | */ |
||
32 | abstract protected function fetch($type): TypeDefinition; |
||
33 | |||
34 | /** |
||
35 | * @return iterable|TypeDefinition[] |
||
36 | */ |
||
37 | 8 | public function getParents(): iterable |
|
43 | |||
44 | /** |
||
45 | * @param string $name |
||
46 | * @return bool |
||
47 | */ |
||
48 | public function hasParent(string $name): bool |
||
52 | |||
53 | /** |
||
54 | * @param string $name |
||
55 | * @return null|TypeDefinition |
||
56 | */ |
||
57 | public function getParent(string $name): ?TypeDefinition |
||
61 | |||
62 | /** |
||
63 | * @param TypeDefinition ...$definitions |
||
64 | * @return ProvidesInheritance|$this |
||
65 | * @throws TypeConflictException |
||
66 | */ |
||
67 | 81 | public function extends(TypeDefinition ...$definitions): ProvidesInheritance |
|
77 | |||
78 | /** |
||
79 | * @param TypeDefinition $def |
||
80 | * @throws TypeConflictException |
||
81 | */ |
||
82 | 81 | private function verifyExtensionType(TypeDefinition $def): void |
|
89 | |||
90 | /** |
||
91 | * @param string|TypeDefinition $type |
||
92 | * @return bool |
||
93 | */ |
||
94 | 8 | public function isExtends($type): 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.