Completed
Push — master ( eaf845...272b76 )
by Oleksandr
13s queued 10s
created

FinishOmsCommand::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 3
dl 0
loc 8
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * MIT License
5
 * For full license information, please view the LICENSE file that was distributed with this source code.
6
 */
7
8
namespace SprykerEco\Zed\CrefoPay\Communication\Oms\Command;
9
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 Orm\Zed\Sales\Persistence\SpySalesOrderItem;
0 ignored issues
show
Bug introduced by
The type Orm\Zed\Sales\Persistence\SpySalesOrderItem 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...
12
use Spryker\Zed\Oms\Business\Util\ReadOnlyArrayObject;
13
use SprykerEco\Zed\CrefoPay\Business\CrefoPayFacadeInterface;
14
use SprykerEco\Zed\CrefoPay\Communication\Oms\CrefoPayOmsMapperInterface;
15
use SprykerEco\Zed\CrefoPay\CrefoPayConfig;
16
17
class FinishOmsCommand implements CrefoPayOmsCommandByOrderInterface
18
{
19
    /**
20
     * @var \SprykerEco\Zed\CrefoPay\Communication\Oms\CrefoPayOmsMapperInterface
21
     */
22
    protected $mapper;
23
24
    /**
25
     * @var \SprykerEco\Zed\CrefoPay\Business\CrefoPayFacadeInterface
26
     */
27
    protected $facade;
28
29
    /**
30
     * @var \SprykerEco\Zed\CrefoPay\CrefoPayConfig
31
     */
32
    protected $config;
33
34
    /**
35
     * @param \SprykerEco\Zed\CrefoPay\Communication\Oms\CrefoPayOmsMapperInterface $mapper
36
     * @param \SprykerEco\Zed\CrefoPay\Business\CrefoPayFacadeInterface $facade
37
     * @param \SprykerEco\Zed\CrefoPay\CrefoPayConfig $config
38
     */
39
    public function __construct(
40
        CrefoPayOmsMapperInterface $mapper,
41
        CrefoPayFacadeInterface $facade,
42
        CrefoPayConfig $config
43
    ) {
44
        $this->mapper = $mapper;
45
        $this->facade = $facade;
46
        $this->config = $config;
47
    }
48
49
    /**
50
     * @param \Orm\Zed\Sales\Persistence\SpySalesOrderItem[] $salesOrderItems
51
     * @param \Orm\Zed\Sales\Persistence\SpySalesOrder $salesOrderEntity
52
     * @param \Spryker\Zed\Oms\Business\Util\ReadOnlyArrayObject $data
53
     *
54
     * @return void
55
     */
56
    public function execute(array $salesOrderItems, SpySalesOrder $salesOrderEntity, ReadOnlyArrayObject $data): void
57
    {
58
        if (array_search($this->config->getCrefoPayAutomaticOmsTrigger(), $data->getArrayCopy()) !== false) {
59
            return;
60
        }
61
62
        $orderTransfer = $this->mapper->mapSpySalesOrderToOrderTransfer($salesOrderEntity);
63
64
        $salesOrderItemIds = array_map(
65
            function (SpySalesOrderItem $orderItem) {
66
                return $orderItem->getIdSalesOrderItem();
67
            },
68
            $salesOrderItems
69
        );
70
71
        $this->facade->executeFinishOmsCommand($orderTransfer, $salesOrderItemIds);
72
    }
73
}
74