1 | <?php |
||
16 | trait AttributesAware |
||
17 | { |
||
18 | /** @var Attribute[] */ |
||
19 | protected $attributes = []; |
||
20 | |||
21 | /** |
||
22 | * @param string $name |
||
23 | * |
||
24 | * @return \phpDocumentor\GraphViz\Attribute |
||
25 | * |
||
26 | * @throws AttributeNotFound |
||
27 | */ |
||
28 | public function getAttribute(string $name): Attribute |
||
36 | |||
37 | /** |
||
38 | * @param string $name |
||
39 | * @param string $value |
||
40 | * |
||
41 | * @return \phpDocumentor\GraphViz\AttributesAware |
||
|
|||
42 | */ |
||
43 | public function setAttribute(string $name, string $value): self |
||
49 | } |
||
50 |
In PHP traits cannot be used for type-hinting as they do not define a well-defined structure. This is because any class that uses a trait can rename that trait’s methods.
If you would like to return an object that has a guaranteed set of methods, you could create a companion interface that lists these methods explicitly.