Completed
Push — master ( ab9bf2...7d6b3f )
by Fabian
09:56 queued 01:25
created

OrderFixture   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Test Coverage

Coverage 25%

Importance

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

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A getId() 0 3 1
A rollback() 0 3 1
A getCustomerEmail() 0 3 1
A getCustomerId() 0 3 1
A getPaymentMethod() 0 3 1
A getShippingMethod() 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 3
    public function __construct(Order $order)
16
    {
17 3
        $this->order = $order;
18 3
    }
19
20 2
    public function getId(): int
21
    {
22 2
        return (int) $this->order->getEntityId();
23
    }
24
25
    public function getCustomerId(): int
26
    {
27
        return (int) $this->order->getCustomerId();
28
    }
29
30
    public function getCustomerEmail(): string
31
    {
32
        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
    public function getOrderItemQtys(): array
41
    {
42
        $qtys = [];
43
        foreach ($this->order->getItems() as $item) {
44
            $qtys[$item->getItemId()] = $item->getQtyOrdered();
45
        }
46
47
        return $qtys;
48
    }
49
50
    public function getPaymentMethod(): string
51
    {
52
        return $this->order->getPayment()->getMethod();
53
    }
54
55
    public function getShippingMethod(): string
56
    {
57
        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