Completed
Push — master ( 3d32fe...b559d6 )
by Fabian
12s queued 10s
created

OrderFixture   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Test Coverage

Coverage 86.96%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 16
c 1
b 0
f 0
dl 0
loc 59
ccs 20
cts 23
cp 0.8696
rs 10
wmc 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
A getCustomerEmail() 0 3 1
A getCustomerId() 0 3 1
A __construct() 0 3 1
A getId() 0 3 1
A getOrderItemQtys() 0 8 2
A getPaymentMethod() 0 7 2
A getShippingMethod() 0 3 1
A rollback() 0 3 1
1
<?php
2
declare(strict_types=1);
3
4
namespace TddWizard\Fixtures\Sales;
5
6
use Magento\Sales\Model\Order;
7
8
class OrderFixture
9
{
10
    /**
11
     * @var Order
12
     */
13
    private $order;
14
15 20
    public function __construct(Order $order)
16
    {
17 20
        $this->order = $order;
18 20
    }
19
20 19
    public function getId(): int
21
    {
22 19
        return (int) $this->order->getEntityId();
23
    }
24
25 17
    public function getCustomerId(): int
26
    {
27 17
        return (int) $this->order->getCustomerId();
28
    }
29
30 2
    public function getCustomerEmail(): string
31
    {
32 2
        return (string) $this->order->getCustomerEmail();
33
    }
34
35
    /**
36
     * Obtain `qty_ordered` per order item, indexed with `item_id`.
37
     *
38
     * @return float[]
39
     */
40 5
    public function getOrderItemQtys(): array
41
    {
42 5
        $qtys = [];
43 5
        foreach ($this->order->getItems() as $item) {
44 5
            $qtys[$item->getItemId()] = (float)$item->getQtyOrdered();
45
        }
46
47 5
        return $qtys;
48
    }
49
50 1
    public function getPaymentMethod(): string
51
    {
52 1
        $payment = $this->order->getPayment();
53 1
        if ($payment === null) {
54
            throw new \RuntimeException('Order does not have any payment information');
55
        }
56 1
        return (string)$payment->getMethod();
57
    }
58
59 1
    public function getShippingMethod(): string
60
    {
61 1
        return (string)$this->order->getShippingMethod();
62
    }
63
64
    public function rollback(): void
65
    {
66
        OrderFixtureRollback::create()->execute($this);
67
    }
68
}
69