Conditions | 5 |
Paths | 5 |
Total Lines | 17 |
Code Lines | 11 |
Lines | 0 |
Ratio | 0 % |
Tests | 10 |
CRAP Score | 5.0187 |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
15 | 18 | protected function validate(ItemInterface $item, PurchaseContext $context) |
|
16 | { |
||
17 | 18 | if (!$item->isProduct()) { |
|
18 | 2 | return; |
|
19 | } |
||
20 | 18 | if ($item->getProductClass()->getStockUnlimited()) { |
|
21 | 15 | return; |
|
22 | } |
||
23 | 3 | $stock = $item->getProductClass()->getStock(); |
|
24 | 3 | $quantity = $item->getQuantity(); |
|
25 | 3 | if ($stock == 0) { |
|
26 | throw ItemValidateException::fromProductClass('cart.zero.stock', $item->getProductClass()); |
||
27 | } |
||
28 | 3 | if ($stock < $quantity) { |
|
29 | 1 | throw ItemValidateException::fromProductClass('cart.over.stock', $item->getProductClass()); |
|
30 | } |
||
31 | } |
||
32 | |||
39 |