1 | <?php |
||
19 | trait HasInterfaces |
||
20 | { |
||
21 | /** |
||
22 | * @var array|string[] |
||
23 | */ |
||
24 | protected $interfaces = []; |
||
25 | |||
26 | /** |
||
27 | * @param string|TypeDefinition $type |
||
28 | * @return TypeDefinition |
||
29 | */ |
||
30 | abstract protected function fetch($type): TypeDefinition; |
||
31 | |||
32 | /** |
||
33 | * @param string|TypeDefinition $interface |
||
34 | * @return bool |
||
35 | */ |
||
36 | 2 | public function isImplements($interface): bool |
|
52 | |||
53 | /** |
||
54 | * @return iterable|InterfaceDefinition[] |
||
55 | */ |
||
56 | 2 | public function getInterfaces(): iterable |
|
62 | |||
63 | /** |
||
64 | * @param string $name |
||
65 | * @return bool |
||
66 | */ |
||
67 | public function hasInterface(string $name): bool |
||
71 | |||
72 | /** |
||
73 | * @param string $name |
||
74 | * @return InterfaceDefinition|TypeDefinition|null |
||
75 | */ |
||
76 | public function getInterface(string $name): ?InterfaceDefinition |
||
80 | |||
81 | /** |
||
82 | * @param string|TypeDefinition ...$interfaces |
||
83 | * @return ProvidesInterfaces|$this |
||
84 | */ |
||
85 | public function withInterface(...$interfaces): ProvidesInterfaces |
||
93 | } |
||
94 | |||
95 |
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.