Passed
Pull Request — dev (#9)
by Andrey
07:08 queued 03:30
created

RelatedItemsUpdateModel::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 2
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
4
/**
5
 * Apache OSL-2
6
 * Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file.
7
 */
8
9
namespace SprykerEco\Zed\AmazonPay\Business\Order;
10
11
use Generated\Shared\Transfer\AmazonpayCallTransfer;
1 ignored issue
show
Bug introduced by
The type Generated\Shared\Transfer\AmazonpayCallTransfer 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 Generated\Shared\Transfer\ItemTransfer;
1 ignored issue
show
Bug introduced by
The type Generated\Shared\Transfer\ItemTransfer 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...
13
use SprykerEco\Zed\AmazonPay\Dependency\Facade\AmazonPayToOmsInterface;
14
use SprykerEco\Zed\AmazonPay\Persistence\AmazonPayQueryContainerInterface;
15
16
class RelatedItemsUpdateModel implements RelatedItemsUpdateInterface
17
{
18
    /**
19
     * @var \SprykerEco\Zed\AmazonPay\Persistence\AmazonPayQueryContainerInterface
20
     */
21
    protected $queryContainer;
22
23
    /**
24
     * @var \SprykerEco\Zed\AmazonPay\Dependency\Facade\AmazonPayToOmsInterface
25
     */
26
    protected $omsFacade;
27
28
    /**
29
     * @param \SprykerEco\Zed\AmazonPay\Persistence\AmazonPayQueryContainerInterface $queryContainer
30
     * @param \SprykerEco\Zed\AmazonPay\Dependency\Facade\AmazonPayToOmsInterface $omsFacade
31
     */
32
    public function __construct(AmazonPayQueryContainerInterface $queryContainer, AmazonPayToOmsInterface $omsFacade)
33
    {
34
        $this->queryContainer = $queryContainer;
35
        $this->omsFacade = $omsFacade;
36
    }
37
38
    /**
39
     * @param \Generated\Shared\Transfer\AmazonpayCallTransfer $amazonpayCallTransfer
40
     * @param int[] $alreadyAffectedItems
41
     * @param string $eventName
42
     *
43
     * @return void
44
     */
45
    public function triggerEvent(AmazonpayCallTransfer $amazonpayCallTransfer, array $alreadyAffectedItems, $eventName)
46
    {
47
        $affectedItems = $this->getAffectedItemIds($amazonpayCallTransfer);
48
        $affectedItems = array_merge($affectedItems, $alreadyAffectedItems);
49
50
        $toBeUpdatedItems = $this->queryContainer
51
            ->querySalesOrderItemsByPaymentReferenceId(
52
                $amazonpayCallTransfer->getAmazonpayPayment()->getAuthorizationDetails()->getAuthorizationReferenceId(),
53
                $affectedItems
54
            )
55
            ->find();
56
57
        if ($toBeUpdatedItems->count() > 0) {
58
            $this->omsFacade
59
                ->triggerEvent(
60
                    $eventName,
61
                    $toBeUpdatedItems,
62
                    [],
63
                    $affectedItems
64
                );
65
        }
66
    }
67
68
    /**
69
     * @param \Generated\Shared\Transfer\AmazonpayCallTransfer $amazonpayCallTransfer
70
     *
71
     * @return int[]
72
     */
73
    protected function getAffectedItemIds(AmazonpayCallTransfer $amazonpayCallTransfer)
74
    {
75
        return array_map(
76
            function (ItemTransfer $item) {
77
                return $item->getIdSalesOrderItem();
78
            },
79
            $amazonpayCallTransfer->getItems()->getArrayCopy()
80
        );
81
    }
82
}
83