Completed
Push — master ( 7d6b3f...2df636 )
by Fabian
14s queued 10s
created

OrderFixture   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Test Coverage

Coverage 90%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
c 1
b 0
f 0
dl 0
loc 55
ccs 18
cts 20
cp 0.9
rs 10
wmc 9

8 Methods

Rating   Name   Duplication   Size   Complexity  
A getCustomerEmail() 0 3 1
A getCustomerId() 0 3 1
A __construct() 0 3 1
A getPaymentMethod() 0 3 1
A getId() 0 3 1
A getShippingMethod() 0 3 1
A rollback() 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 19
    public function __construct(Order $order)
16
    {
17 19
        $this->order = $order;
18 19
    }
19
20 18
    public function getId(): int
21
    {
22 18
        return (int) $this->order->getEntityId();
23
    }
24
25 16
    public function getCustomerId(): int
26
    {
27 16
        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()] = $item->getQtyOrdered();
45
        }
46
47 5
        return $qtys;
48
    }
49
50 1
    public function getPaymentMethod(): string
51
    {
52 1
        return $this->order->getPayment()->getMethod();
53
    }
54
55 1
    public function getShippingMethod(): string
56
    {
57 1
        return $this->order->getShippingMethod();
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->order->getShippingMethod() could return the type Magento\Framework\DataObject|null which is incompatible with the type-hinted return string. Consider adding an additional type-check to rule them out.
Loading history...
58
    }
59
60
    public function rollback(): void
61
    {
62
        OrderFixtureRollback::create()->execute($this);
63
    }
64
}
65