1 | <?php |
||
18 | trait HasDefinitions |
||
19 | { |
||
20 | /** |
||
21 | * @var array|string[] |
||
22 | */ |
||
23 | protected $types = []; |
||
24 | |||
25 | /** |
||
26 | * @param string|TypeDefinition $type |
||
27 | * @return TypeDefinition |
||
28 | */ |
||
29 | abstract protected function fetch($type): TypeDefinition; |
||
30 | |||
31 | /** |
||
32 | * @return iterable|TypeDefinition[] |
||
33 | */ |
||
34 | 3 | public function getDefinitions(): iterable |
|
40 | |||
41 | /** |
||
42 | * @param string $name |
||
43 | * @return bool |
||
44 | */ |
||
45 | 5 | public function hasDefinition(string $name): bool |
|
49 | |||
50 | /** |
||
51 | * @param string $name |
||
52 | * @return null|TypeDefinition |
||
53 | */ |
||
54 | 3 | public function getDefinition(string $name): ?TypeDefinition |
|
62 | |||
63 | /** |
||
64 | * @param string|TypeDefinition ...$types |
||
65 | * @return ProvidesTypeDefinitions|$this |
||
66 | */ |
||
67 | 17 | public function withDefinition(...$types): ProvidesTypeDefinitions |
|
75 | |||
76 | /** |
||
77 | * @param string|TypeDefinition ...$types |
||
78 | * @return ProvidesTypeDefinitions|$this |
||
79 | */ |
||
80 | public function withoutDefinition(...$types): ProvidesTypeDefinitions |
||
90 | } |
||
91 |
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.