1 | <?php |
||
4 | trait OrderLineArrayTrait |
||
5 | { |
||
6 | /** |
||
7 | * @var OrderLineInterface[] |
||
8 | */ |
||
9 | private $orderLines; |
||
10 | |||
11 | /** |
||
12 | * @return OrderLineInterface[] |
||
13 | */ |
||
14 | 9 | public function getOrderLines() : array |
|
18 | |||
19 | /** |
||
20 | * @param OrderLine[] $orderLines |
||
21 | * @return OrderLineArrayTrait |
||
|
|||
22 | */ |
||
23 | 6 | public function setOrderLines(array $orderLines) |
|
28 | |||
29 | /** |
||
30 | * @param OrderLineInterface $orderLine |
||
31 | * @return OrderLineArrayTrait |
||
32 | */ |
||
33 | 9 | public function addOrderLine(OrderLineInterface $orderLine) : self |
|
38 | |||
39 | /** |
||
40 | * @param OrderLineInterface $orderLine |
||
41 | * @return OrderLineArrayTrait |
||
42 | */ |
||
43 | 3 | public function removeOrderLine(OrderLineInterface $orderLine) : self |
|
53 | } |
||
54 |
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.