1 | <?php |
||
21 | trait HasInterfaces |
||
22 | { |
||
23 | /** |
||
24 | * @var array|string[] |
||
25 | */ |
||
26 | protected $interfaces = []; |
||
27 | |||
28 | /** |
||
29 | * @param TypeDefinition $definition |
||
30 | * @return bool |
||
31 | */ |
||
32 | protected function isImplementsDefinition(TypeDefinition $definition): bool |
||
42 | |||
43 | /** |
||
44 | * @param string $interface |
||
45 | * @return bool |
||
46 | */ |
||
47 | public function isImplements(string $interface): bool |
||
51 | |||
52 | /** |
||
53 | * @return iterable|InterfaceDefinition[] |
||
54 | */ |
||
55 | public function getInterfaces(): iterable |
||
61 | |||
62 | /** |
||
63 | * @param string $name |
||
64 | * @return bool |
||
65 | */ |
||
66 | public function hasInterface(string $name): bool |
||
70 | |||
71 | /** |
||
72 | * @param string $name |
||
73 | * @return InterfaceDefinition |
||
74 | * @throws TypeNotFoundException |
||
75 | */ |
||
76 | public function getInterface(string $name): InterfaceDefinition |
||
85 | |||
86 | /** |
||
87 | * @param InterfaceDefinition $definition |
||
88 | * @return ProvidesInterfaces |
||
89 | */ |
||
90 | public function withInterface(InterfaceDefinition $definition): ProvidesInterfaces |
||
96 | } |
||
97 | |||
98 |
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.