@@ -11,15 +11,15 @@ |
||
| 11 | 11 | |
| 12 | 12 | namespace Plane\Shop; |
| 13 | 13 | |
| 14 | +use Money\Currencies\ISOCurrencies; |
|
| 15 | +use Money\Formatter\DecimalMoneyFormatter; |
|
| 14 | 16 | use Money\Money; |
| 15 | 17 | use Money\MoneyFormatter; |
| 18 | +use Plane\Shop\CartDiscountInterface; |
|
| 16 | 19 | use Plane\Shop\CartInterface; |
| 17 | 20 | use Plane\Shop\CartItemInterface; |
| 18 | -use Plane\Shop\Traits\CartCommon; |
|
| 19 | -use Money\Currencies\ISOCurrencies; |
|
| 20 | -use Plane\Shop\CartDiscountInterface; |
|
| 21 | 21 | use Plane\Shop\CartPresenterInterface; |
| 22 | -use Money\Formatter\DecimalMoneyFormatter; |
|
| 22 | +use Plane\Shop\Traits\CartCommon; |
|
| 23 | 23 | |
| 24 | 24 | class CartPresenter implements CartPresenterInterface |
| 25 | 25 | { |
@@ -68,10 +68,10 @@ discard block |
||
| 68 | 68 | public function toArray(): array |
| 69 | 69 | { |
| 70 | 70 | $array = []; |
| 71 | - $array['items'] = array_map(function (CartItemInterface $item) { |
|
| 71 | + $array['items'] = array_map(function(CartItemInterface $item) { |
|
| 72 | 72 | $itemArray = $item->toArray($this->getCurrency()); |
| 73 | 73 | |
| 74 | - array_walk_recursive($itemArray, function (&$value, $key) { |
|
| 74 | + array_walk_recursive($itemArray, function(&$value, $key) { |
|
| 75 | 75 | if ($value instanceof Money) { |
| 76 | 76 | $value = $this->priceFormatter->format($value); |
| 77 | 77 | } |
@@ -96,7 +96,7 @@ discard block |
||
| 96 | 96 | $array['payment']['fee'] = $this->paymentFee(); |
| 97 | 97 | } |
| 98 | 98 | |
| 99 | - $array['discounts'] = array_map(function (CartDiscountInterface $discount) { |
|
| 99 | + $array['discounts'] = array_map(function(CartDiscountInterface $discount) { |
|
| 100 | 100 | return [ |
| 101 | 101 | 'text' => $discount->getDescription(), |
| 102 | 102 | 'price' => $this->priceFormatter->format($discount->getPriceAfterDiscount()) |
@@ -11,11 +11,11 @@ |
||
| 11 | 11 | |
| 12 | 12 | namespace Plane\Shop\Traits; |
| 13 | 13 | |
| 14 | -use Plane\Shop\PaymentInterface; |
|
| 14 | +use Plane\Shop\CartDiscountInterface; |
|
| 15 | +use Plane\Shop\CartItemCollection; |
|
| 15 | 16 | use Plane\Shop\CartItemInterface; |
| 17 | +use Plane\Shop\PaymentInterface; |
|
| 16 | 18 | use Plane\Shop\ShippingInterface; |
| 17 | -use Plane\Shop\CartItemCollection; |
|
| 18 | -use Plane\Shop\CartDiscountInterface; |
|
| 19 | 19 | |
| 20 | 20 | trait CartCommon |
| 21 | 21 | { |
@@ -44,6 +44,9 @@ discard block |
||
| 44 | 44 | $this->secondCartItem = new CartItem($product, 2); |
| 45 | 45 | } |
| 46 | 46 | |
| 47 | + /** |
|
| 48 | + * @return \Plane\Shop\PaymentInterface |
|
| 49 | + */ |
|
| 47 | 50 | protected function getPaymentMock() |
| 48 | 51 | { |
| 49 | 52 | $payment = $this->createMock(Payment::class); |
@@ -55,6 +58,9 @@ discard block |
||
| 55 | 58 | return $payment; |
| 56 | 59 | } |
| 57 | 60 | |
| 61 | + /** |
|
| 62 | + * @return \Plane\Shop\ShippingInterface |
|
| 63 | + */ |
|
| 58 | 64 | protected function getShippingMock() |
| 59 | 65 | { |
| 60 | 66 | $shipping = $this->createMock(Shipping::class); |
@@ -3,9 +3,9 @@ |
||
| 3 | 3 | namespace Plane\Shop\Tests; |
| 4 | 4 | |
| 5 | 5 | use Plane\Shop\Cart; |
| 6 | +use Plane\Shop\CartItem; |
|
| 6 | 7 | use Plane\Shop\Payment; |
| 7 | 8 | use Plane\Shop\Product; |
| 8 | -use Plane\Shop\CartItem; |
|
| 9 | 9 | use Plane\Shop\Shipping; |
| 10 | 10 | |
| 11 | 11 | trait CartTrait |
@@ -57,7 +57,7 @@ |
||
| 57 | 57 | |
| 58 | 58 | protected function getShippingMock() |
| 59 | 59 | { |
| 60 | - $shipping = $this->createMock(Shipping::class); |
|
| 60 | + $shipping = $this->createMock(Shipping::class); |
|
| 61 | 61 | $shipping->method('getId')->willReturn(1); |
| 62 | 62 | $shipping->method('getName')->willReturn('Test shipping'); |
| 63 | 63 | $shipping->method('getDescription')->willReturn('Shipping description'); |
@@ -2,9 +2,9 @@ |
||
| 2 | 2 | |
| 3 | 3 | namespace Plane\Shop\Tests; |
| 4 | 4 | |
| 5 | +use InvalidArgumentException; |
|
| 5 | 6 | use Money\Money; |
| 6 | 7 | use Plane\Shop\Payment; |
| 7 | -use InvalidArgumentException; |
|
| 8 | 8 | |
| 9 | 9 | /** |
| 10 | 10 | * Payment test suite |
@@ -2,8 +2,8 @@ |
||
| 2 | 2 | |
| 3 | 3 | namespace Plane\Shop\Tests; |
| 4 | 4 | |
| 5 | -use Plane\Shop\Product; |
|
| 6 | 5 | use InvalidArgumentException; |
| 6 | +use Plane\Shop\Product; |
|
| 7 | 7 | |
| 8 | 8 | /** |
| 9 | 9 | * Product test suite |
@@ -72,15 +72,15 @@ |
||
| 72 | 72 | |
| 73 | 73 | $array = $product->toArray(self::CURRENCY); |
| 74 | 74 | |
| 75 | - $this->assertSame(self::PRODUCT_OUTPUT['id'], $array['id']); |
|
| 76 | - $this->assertSame(self::PRODUCT_OUTPUT['name'], $array['name']); |
|
| 77 | - $this->assertSame(self::PRODUCT_OUTPUT['price'], $this->getAmount($array['price'])); |
|
| 78 | - $this->assertSame(self::PRODUCT_OUTPUT['stock'], $array['stock']); |
|
| 79 | - $this->assertSame(self::PRODUCT_OUTPUT['taxRate'], $array['taxRate']); |
|
| 80 | - $this->assertSame(self::PRODUCT_OUTPUT['tax'], $this->getAmount($array['tax'])); |
|
| 75 | + $this->assertSame(self::PRODUCT_OUTPUT['id'], $array['id']); |
|
| 76 | + $this->assertSame(self::PRODUCT_OUTPUT['name'], $array['name']); |
|
| 77 | + $this->assertSame(self::PRODUCT_OUTPUT['price'], $this->getAmount($array['price'])); |
|
| 78 | + $this->assertSame(self::PRODUCT_OUTPUT['stock'], $array['stock']); |
|
| 79 | + $this->assertSame(self::PRODUCT_OUTPUT['taxRate'], $array['taxRate']); |
|
| 80 | + $this->assertSame(self::PRODUCT_OUTPUT['tax'], $this->getAmount($array['tax'])); |
|
| 81 | 81 | $this->assertSame(self::PRODUCT_OUTPUT['priceWithTax'], $this->getAmount($array['priceWithTax'])); |
| 82 | - $this->assertSame(self::PRODUCT_OUTPUT['weight'], $array['weight']); |
|
| 83 | - $this->assertSame(self::PRODUCT_OUTPUT['imagePath'], $array['imagePath']); |
|
| 82 | + $this->assertSame(self::PRODUCT_OUTPUT['weight'], $array['weight']); |
|
| 83 | + $this->assertSame(self::PRODUCT_OUTPUT['imagePath'], $array['imagePath']); |
|
| 84 | 84 | |
| 85 | 85 | } |
| 86 | 86 | } |
@@ -2,9 +2,9 @@ |
||
| 2 | 2 | |
| 3 | 3 | namespace Plane\Shop\Tests; |
| 4 | 4 | |
| 5 | +use InvalidArgumentException; |
|
| 5 | 6 | use Money\Money; |
| 6 | 7 | use Plane\Shop\Shipping; |
| 7 | -use InvalidArgumentException; |
|
| 8 | 8 | |
| 9 | 9 | /** |
| 10 | 10 | * Shipping test suite |
@@ -39,7 +39,7 @@ |
||
| 39 | 39 | |
| 40 | 40 | public function testCreateIncompleteObject() |
| 41 | 41 | { |
| 42 | - $input =self::SHIPPING_INPUT; |
|
| 42 | + $input = self::SHIPPING_INPUT; |
|
| 43 | 43 | unset($input['cost']); |
| 44 | 44 | |
| 45 | 45 | $this->expectException(InvalidArgumentException::class); |
@@ -74,7 +74,7 @@ discard block |
||
| 74 | 74 | |
| 75 | 75 | public function fill(CartItemCollection $collection): void |
| 76 | 76 | { |
| 77 | - array_map(function ($item) { |
|
| 77 | + array_map(function($item) { |
|
| 78 | 78 | $this->addItem($item); |
| 79 | 79 | }, $collection->getItems()); |
| 80 | 80 | } |
@@ -131,7 +131,7 @@ discard block |
||
| 131 | 131 | public function itemsQuantity(): int |
| 132 | 132 | { |
| 133 | 133 | return (int) array_sum( |
| 134 | - array_map(function (CartItemInterface $item) { |
|
| 134 | + array_map(function(CartItemInterface $item) { |
|
| 135 | 135 | return $item->getQuantity(); |
| 136 | 136 | }, $this->items) |
| 137 | 137 | ); |
@@ -140,7 +140,7 @@ discard block |
||
| 140 | 140 | public function weight(): string |
| 141 | 141 | { |
| 142 | 142 | return (string) array_sum( |
| 143 | - array_map(function (CartItemInterface $item) { |
|
| 143 | + array_map(function(CartItemInterface $item) { |
|
| 144 | 144 | return $item->getWeightTotal(); |
| 145 | 145 | }, $this->items) |
| 146 | 146 | ); |
@@ -148,7 +148,7 @@ discard block |
||
| 148 | 148 | |
| 149 | 149 | public function totalNet(): Money |
| 150 | 150 | { |
| 151 | - $total = array_map(function (CartItemInterface $item) { |
|
| 151 | + $total = array_map(function(CartItemInterface $item) { |
|
| 152 | 152 | return $item->getPriceTotal($this->currency); |
| 153 | 153 | }, $this->items); |
| 154 | 154 | |
@@ -157,7 +157,7 @@ discard block |
||
| 157 | 157 | |
| 158 | 158 | public function totalGross(): Money |
| 159 | 159 | { |
| 160 | - $total = array_map(function (CartItemInterface $item) { |
|
| 160 | + $total = array_map(function(CartItemInterface $item) { |
|
| 161 | 161 | return $item->getPriceTotalWithTax($this->currency); |
| 162 | 162 | }, $this->items); |
| 163 | 163 | |
@@ -166,7 +166,7 @@ discard block |
||
| 166 | 166 | |
| 167 | 167 | public function tax(): Money |
| 168 | 168 | { |
| 169 | - $total = array_map(function (CartItemInterface $item) { |
|
| 169 | + $total = array_map(function(CartItemInterface $item) { |
|
| 170 | 170 | return $item->getTaxTotal($this->currency); |
| 171 | 171 | }, $this->items); |
| 172 | 172 | |
@@ -48,7 +48,7 @@ |
||
| 48 | 48 | { |
| 49 | 49 | if (count(array_intersect_key(array_flip($this->requiredFields), $data)) !== count($this->requiredFields)) { |
| 50 | 50 | throw new InvalidArgumentException( |
| 51 | - 'Cannot create object, required array keys: '. implode(', ', $this->requiredFields) |
|
| 51 | + 'Cannot create object, required array keys: ' . implode(', ', $this->requiredFields) |
|
| 52 | 52 | ); |
| 53 | 53 | } |
| 54 | 54 | |
@@ -48,7 +48,7 @@ |
||
| 48 | 48 | { |
| 49 | 49 | if (count(array_intersect_key(array_flip($this->requiredFields), $data)) !== count($this->requiredFields)) { |
| 50 | 50 | throw new InvalidArgumentException( |
| 51 | - 'Cannot create object, required array keys: '. implode(', ', $this->requiredFields) |
|
| 51 | + 'Cannot create object, required array keys: ' . implode(', ', $this->requiredFields) |
|
| 52 | 52 | ); |
| 53 | 53 | } |
| 54 | 54 | |