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