1 | <?php |
||
20 | trait HasDirectives |
||
21 | { |
||
22 | /** |
||
23 | * @var array|DirectiveInvocation[] |
||
24 | */ |
||
25 | protected $directives = []; |
||
26 | |||
27 | /** |
||
28 | * @param string $name |
||
29 | * @return bool |
||
30 | */ |
||
31 | 4 | public function hasDirective(string $name): bool |
|
35 | |||
36 | /** |
||
37 | * @param string|null $name |
||
38 | * @return iterable|DirectiveInvocation[]|\Generator |
||
39 | */ |
||
40 | 4 | public function getDirectives(string $name = null): iterable |
|
48 | |||
49 | /** |
||
50 | * @param DirectiveInvocation ...$invocations |
||
51 | * @return ProvidesDirectives|$this |
||
52 | */ |
||
53 | 1 | public function withDirective(DirectiveInvocation ...$invocations): ProvidesDirectives |
|
65 | |||
66 | /** |
||
67 | * @param DirectiveInvocation $directive |
||
68 | * @return bool |
||
69 | */ |
||
70 | 1 | private function isDeprecatedDirective(DirectiveInvocation $directive): bool |
|
74 | |||
75 | /** |
||
76 | * @param DirectiveInvocation $deprecated |
||
77 | * @return null|string |
||
78 | */ |
||
79 | private function getDirectiveDeprecationReason(DirectiveInvocation $deprecated): ?string |
||
93 | } |
||
94 |
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.