OmsEntityConverter   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 94
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 10
eloc 23
dl 0
loc 94
rs 10
c 1
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A extractPayolutionOmsOperationRequest() 0 10 1
A extractOrderTransfer() 0 3 1
A extractPaymentEntity() 0 3 1
A extractPartialOrderItems() 0 23 5
A extractPaymentTransfer() 0 3 1
1
<?php
2
3
namespace SprykerEco\Zed\Payolution\Communication\Plugin\Oms\Converter;
4
5
use ArrayObject;
6
use Generated\Shared\Transfer\OrderTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\OrderTransfer 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...
7
use Generated\Shared\Transfer\PayolutionOmsOperationRequestTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...perationRequestTransfer 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...
8
use Generated\Shared\Transfer\PayolutionPaymentTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...yolutionPaymentTransfer 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...
9
use Orm\Zed\Payolution\Persistence\SpyPaymentPayolution;
0 ignored issues
show
Bug introduced by
The type Orm\Zed\Payolution\Persi...ce\SpyPaymentPayolution 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...
10
use Orm\Zed\Sales\Persistence\SpySalesOrder;
0 ignored issues
show
Bug introduced by
The type Orm\Zed\Sales\Persistence\SpySalesOrder 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...
11
use SprykerEco\Zed\Payolution\Dependency\Facade\PayolutionToSalesInterface;
12
13
class OmsEntityConverter implements OmsEntityConverterInterface
14
{
15
    /**
16
     * @var \SprykerEco\Zed\Payolution\Dependency\Facade\PayolutionToSalesInterface $salesFacade
17
     */
18
    protected $salesFacade;
19
20
    /**
21
     * @param array $orderItems
22
     * @param \Orm\Zed\Sales\Persistence\SpySalesOrder $orderEntity
23
     * @param \SprykerEco\Zed\Payolution\Dependency\Facade\PayolutionToSalesInterface $salesFacade
24
     */
25
    public function __construct(PayolutionToSalesInterface $salesFacade)
26
    {
27
        $this->salesFacade = $salesFacade;
28
    }
29
30
    /**
31
     * @param \Orm\Zed\Sales\Persistence\SpySalesOrderItem[] $orderItems
32
     * @param \Orm\Zed\Sales\Persistence\SpySalesOrder $orderEntity
33
     *
34
     * @return \Orm\Zed\Sales\Persistence\SpySalesOrderItem[]|ArrayObject
35
     */
36
    public function extractPartialOrderItems(array $orderItems, SpySalesOrder $orderEntity)
37
    {
38
        if (count($orderItems) < count($orderEntity->getItems())) {
39
            $orderItemIds = [];
40
41
            foreach ($orderItems as $orderItem) {
42
                $orderItemIds[]= $orderItem->getIdSalesOrderItem();
43
            }
44
45
            $orderTransfer = $this->extractOrderTransfer($orderEntity);
46
47
            $orderItemTransfers = new ArrayObject();
48
            /** @var \Generated\Shared\Transfer\ItemTransfer $itemTransfer */
49
            foreach ($orderTransfer->getItems() as $itemTransfer) {
50
                if (in_array($itemTransfer->getIdSalesOrderItem(), $orderItemIds)) {
51
                    $orderItemTransfers->append($itemTransfer);
52
                }
53
            }
54
55
            return $orderItemTransfers;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $orderItemTransfers returns the type ArrayObject which is incompatible with the return type mandated by SprykerEco\Zed\Payolutio...ractPartialOrderItems() of int[].

In the issue above, the returned value is violating the contract defined by the mentioned interface.

Let's take a look at an example:

interface HasName {
    /** @return string */
    public function getName();
}

class Name {
    public $name;
}

class User implements HasName {
    /** @return string|Name */
    public function getName() {
        return new Name('foo'); // This is a violation of the ``HasName`` interface
                                // which only allows a string value to be returned.
    }
}
Loading history...
56
        }
57
58
        return new ArrayObject();
0 ignored issues
show
Bug Best Practice introduced by
The expression return new ArrayObject() returns the type ArrayObject which is incompatible with the return type mandated by SprykerEco\Zed\Payolutio...ractPartialOrderItems() of int[].

In the issue above, the returned value is violating the contract defined by the mentioned interface.

Let's take a look at an example:

interface HasName {
    /** @return string */
    public function getName();
}

class Name {
    public $name;
}

class User implements HasName {
    /** @return string|Name */
    public function getName() {
        return new Name('foo'); // This is a violation of the ``HasName`` interface
                                // which only allows a string value to be returned.
    }
}
Loading history...
59
    }
60
61
    /**
62
     * @param \Orm\Zed\Sales\Persistence\SpySalesOrder $orderEntity
63
     *
64
     * @return \Generated\Shared\Transfer\OrderTransfer
65
     */
66
    public function extractOrderTransfer(SpySalesOrder $orderEntity): OrderTransfer
67
    {
68
        return $this->salesFacade->getOrderByIdSalesOrder($orderEntity->getIdSalesOrder());
69
    }
70
71
    /**
72
     * @param \Orm\Zed\Sales\Persistence\SpySalesOrder $orderEntity
73
     *
74
     * @return \Orm\Zed\Payolution\Persistence\SpyPaymentPayolution
75
     */
76
    public function extractPaymentEntity(SpySalesOrder $orderEntity): SpyPaymentPayolution
77
    {
78
        return $orderEntity->getSpyPaymentPayolutions()->getFirst();
79
    }
80
81
    /**
82
     * @param \Orm\Zed\Sales\Persistence\SpySalesOrder $orderEntity
83
     *
84
     * @return \Generated\Shared\Transfer\PayolutionPaymentTransfer
85
     */
86
    public function extractPaymentTransfer(SpySalesOrder $orderEntity): PayolutionPaymentTransfer
87
    {
88
        return $this->extractOrderTransfer($orderEntity)->getPayolutionPayment();
89
    }
90
91
    /**
92
     * @param \Orm\Zed\Sales\Persistence\SpySalesOrderItem[] $orderItems
93
     * @param \Orm\Zed\Sales\Persistence\SpySalesOrder $orderEntity
94
     *
95
     * @return \Generated\Shared\Transfer\PayolutionOmsOperationRequestTransfer
96
     */
97
    public function extractPayolutionOmsOperationRequest(array $orderItems, SpySalesOrder $orderEntity): PayolutionOmsOperationRequestTransfer
98
    {
99
        $payolutionOmsOperationRequestTransfer = new PayolutionOmsOperationRequestTransfer();
100
        $orderTransfer = $this->extractOrderTransfer($orderEntity);
101
102
        $payolutionOmsOperationRequestTransfer->setIdPayment($this->extractPaymentEntity($orderEntity)->getIdPaymentPayolution());
103
        $payolutionOmsOperationRequestTransfer->setOrder($orderTransfer);
104
        $payolutionOmsOperationRequestTransfer->setSelectedItems($this->extractPartialOrderItems($orderItems, $orderEntity));
105
106
        return $payolutionOmsOperationRequestTransfer;
107
    }
108
}
109