Completed
Push — master ( 43dae8...61751c )
by Fabian
24s queued 11s
created

OrderFixture   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Test Coverage

Coverage 80%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 17
c 1
b 0
f 0
dl 0
loc 64
ccs 20
cts 25
cp 0.8
rs 10
wmc 11

9 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A getCustomerId() 0 3 1
A getId() 0 3 1
A getCustomerEmail() 0 3 1
A getPaymentMethod() 0 7 2
A getShippingMethod() 0 3 1
A rollback() 0 3 1
A getOrder() 0 3 1
A getOrderItemQtys() 0 8 2
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
    public function getOrder(): Order
21
    {
22
        return $this->order;
23
    }
24
25 19
    public function getId(): int
26
    {
27 19
        return (int) $this->order->getEntityId();
28
    }
29
30 17
    public function getCustomerId(): int
31
    {
32 17
        return (int) $this->order->getCustomerId();
33
    }
34
35 2
    public function getCustomerEmail(): string
36
    {
37 2
        return (string) $this->order->getCustomerEmail();
38
    }
39
40
    /**
41
     * Obtain `qty_ordered` per order item, indexed with `item_id`.
42
     *
43
     * @return float[]
44
     */
45 5
    public function getOrderItemQtys(): array
46
    {
47 5
        $qtys = [];
48 5
        foreach ($this->order->getItems() as $item) {
49 5
            $qtys[$item->getItemId()] = (float)$item->getQtyOrdered();
50
        }
51
52 5
        return $qtys;
53
    }
54
55 1
    public function getPaymentMethod(): string
56
    {
57 1
        $payment = $this->order->getPayment();
58 1
        if ($payment === null) {
59
            throw new \RuntimeException('Order does not have any payment information');
60
        }
61 1
        return (string)$payment->getMethod();
62
    }
63
64 1
    public function getShippingMethod(): string
65
    {
66 1
        return (string)$this->order->getShippingMethod();
67
    }
68
69
    public function rollback(): void
70
    {
71
        OrderFixtureRollback::create()->execute($this);
72
    }
73
}
74