Passed
Pull Request — master (#52)
by Fabian
19:55
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
3
namespace TddWizard\Fixtures\Sales;
4
5
use Magento\Sales\Api\Data\OrderInterface;
6
7
class OrderFixture
8
{
9
    /**
10
     * @var OrderInterface
11
     */
12
    private $order;
13
14 19
    public function __construct(OrderInterface $order)
15
    {
16 19
        $this->order = $order;
17 19
    }
18
19 18
    public function getId(): int
20
    {
21 18
        return (int) $this->order->getEntityId();
22
    }
23
24 16
    public function getCustomerId(): int
25
    {
26 16
        return (int) $this->order->getCustomerId();
27
    }
28
29 2
    public function getCustomerEmail(): string
30
    {
31 2
        return (string) $this->order->getCustomerEmail();
32
    }
33
34
    /**
35
     * Obtain `qty_ordered` per order item, indexed with `item_id`.
36
     *
37
     * @return int[]
38
     */
39 5
    public function getOrderItemQtys(): array
40
    {
41 5
        $qtys = [];
42 5
        foreach ($this->order->getItems() as $item) {
43 5
            $qtys[$item->getItemId()] = $item->getQtyOrdered();
44
        }
45
46 5
        return $qtys;
47
    }
48
49 1
    public function getPaymentMethod(): string
50
    {
51 1
        return $this->order->getPayment()->getMethod();
52
    }
53
54 1
    public function getShippingMethod(): string
55
    {
56 1
        return $this->order->getShippingMethod();
0 ignored issues
show
Bug introduced by
The method getShippingMethod() does not exist on Magento\Sales\Api\Data\OrderInterface. Did you maybe mean getShippingAmount()? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

56
        return $this->order->/** @scrutinizer ignore-call */ getShippingMethod();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
57
    }
58
59
    public function rollback(): void
60
    {
61
        OrderFixtureRollback::create()->execute($this);
62
    }
63
}
64