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

OrderFixture::getShippingMethod()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
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