Passed
Pull Request — master (#67)
by Laura
42:19
created

OrderFixture::getOrder()   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 0
Metric Value
cc 1
eloc 1
c 0
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 19
    public function getOrder(): OrderInterface
0 ignored issues
show
Bug introduced by
The type TddWizard\Fixtures\Sales\OrderInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
21
    {
22 19
        return $this->order;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->order returns the type Magento\Sales\Model\Order which is incompatible with the type-hinted return TddWizard\Fixtures\Sales\OrderInterface.
Loading history...
23
    }
24
25 17
    public function getId(): int
26
    {
27 17
        return (int) $this->order->getEntityId();
28
    }
29
30 2
    public function getCustomerId(): int
31
    {
32 2
        return (int) $this->order->getCustomerId();
33
    }
34
35
    public function getCustomerEmail(): string
36
    {
37
        return (string) $this->order->getCustomerEmail();
38
    }
39
40 5
    /**
41
     * Obtain `qty_ordered` per order item, indexed with `item_id`.
42 5
     *
43 5
     * @return float[]
44 5
     */
45
    public function getOrderItemQtys(): array
46
    {
47 5
        $qtys = [];
48
        foreach ($this->order->getItems() as $item) {
49
            $qtys[$item->getItemId()] = (float)$item->getQtyOrdered();
50 1
        }
51
52 1
        return $qtys;
53 1
    }
54
55
    public function getPaymentMethod(): string
56 1
    {
57
        $payment = $this->order->getPayment();
58
        if ($payment === null) {
59 1
            throw new \RuntimeException('Order does not have any payment information');
60
        }
61 1
        return (string)$payment->getMethod();
62
    }
63
64
    public function getShippingMethod(): string
65
    {
66
        return (string)$this->order->getShippingMethod();
67
    }
68
69
    public function rollback(): void
70
    {
71
        OrderFixtureRollback::create()->execute($this);
72
    }
73
}
74