1 | <?php |
||
10 | trait OrderLineTrait |
||
11 | { |
||
12 | /** |
||
13 | * @var StockMovement[]|ArrayCollection |
||
14 | * |
||
15 | * @ORM\OneToMany(targetEntity="Loevgaard\DandomainStockBundle\Entity\StockMovement", mappedBy="orderLine", cascade={"persist"}) |
||
16 | */ |
||
17 | protected $stockMovements; |
||
18 | |||
19 | /** |
||
20 | * @param StockMovement $stockMovement |
||
21 | * |
||
22 | * @return OrderLineTrait |
||
|
|||
23 | * |
||
24 | * @throws \Loevgaard\DandomainStockBundle\Exception\StockMovementProductMismatchException |
||
25 | */ |
||
26 | public function addStockMovement(StockMovement $stockMovement) |
||
44 | |||
45 | /** |
||
46 | * @return \Loevgaard\DandomainStockBundle\Entity\StockMovement[] |
||
47 | */ |
||
48 | public function getStockMovements() |
||
54 | |||
55 | /** |
||
56 | * @param StockMovement $stockMovements |
||
57 | * |
||
58 | * @return OrderLineTrait |
||
59 | * |
||
60 | * @throws \Loevgaard\DandomainStockBundle\Exception\StockMovementProductMismatchException |
||
61 | */ |
||
62 | public function setStockMovements(StockMovement $stockMovements) |
||
70 | |||
71 | /** |
||
72 | * Say you have these two stock movements associated with this order line:. |
||
73 | * |
||
74 | * | qty | product | |
||
75 | * ----------------- |
||
76 | * | 1 | Jeans | |
||
77 | * | -1 | Jeans | |
||
78 | * |
||
79 | * Then the effective stock movement would be |
||
80 | * |
||
81 | * | qty | product | |
||
82 | * ----------------- |
||
83 | * | 0 | Jeans | |
||
84 | * |
||
85 | * And this is what we return in this method |
||
86 | * |
||
87 | * Returns null if the order line has 0 stock movements |
||
88 | * |
||
89 | * @return StockMovement|null |
||
90 | * |
||
91 | * @throws \Loevgaard\DandomainStockBundle\Exception\CurrencyMismatchException |
||
92 | * @throws \Loevgaard\DandomainStockBundle\Exception\UnsetCurrencyException |
||
93 | */ |
||
94 | public function computeEffectiveStockMovement(): ?StockMovement |
||
116 | |||
117 | protected function initStockMovements(): void |
||
125 | } |
||
126 |
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.