Passed
Push — feature/eco-3656/dev-paypal-ex... ( a9c700...3cc3fd )
by
unknown
04:14
created

updateComputopSalesOrderItemCollection()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 5
c 0
b 0
f 0
dl 0
loc 10
rs 10
cc 3
nc 3
nop 2
1
<?php
2
3
/**
4
 * MIT License
5
 * Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file.
6
 */
7
8
namespace SprykerEco\Zed\Computop\Business\Payment\Handler\Saver\Init;
9
10
use Generated\Shared\Transfer\ComputopPaymentComputopOrderItemCollectionTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...rItemCollectionTransfer 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 Generated\Shared\Transfer\ComputopPaymentComputopTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...PaymentComputopTransfer 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\ComputopPayPalExpressInitResponseTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...essInitResponseTransfer 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 Generated\Shared\Transfer\ComputopSalesOrderItemTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...pSalesOrderItemTransfer 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...
14
use Generated\Shared\Transfer\QuoteTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\QuoteTransfer 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...
15
use Spryker\Zed\Kernel\Persistence\EntityManager\TransactionTrait;
16
use SprykerEco\Zed\Computop\ComputopConfig;
17
use SprykerEco\Zed\Computop\Persistence\ComputopEntityManagerInterface;
18
use SprykerEco\Zed\Computop\Persistence\ComputopRepositoryInterface;
19
20
class PayPalExpressResponseSaver implements InitResponseSaverInterface
21
{
22
    use TransactionTrait;
23
24
    /**
25
     * @var \SprykerEco\Zed\Computop\ComputopConfig
26
     */
27
    protected $computopConfig;
28
29
    /**
30
     * @var \SprykerEco\Zed\Computop\Persistence\ComputopRepositoryInterface
31
     */
32
    protected $computopRepository;
33
34
    /**
35
     * @var \SprykerEco\Zed\Computop\Persistence\ComputopEntityManagerInterface
36
     */
37
    protected $computopEntityManager;
38
39
    /**
40
     * @param \SprykerEco\Zed\Computop\ComputopConfig $computopConfig
41
     * @param \SprykerEco\Zed\Computop\Persistence\ComputopRepositoryInterface $computopRepository
42
     * @param \SprykerEco\Zed\Computop\Persistence\ComputopEntityManagerInterface $computopEntityManager
43
     */
44
    public function __construct(
45
        ComputopConfig $computopConfig,
46
        ComputopRepositoryInterface $computopRepository,
47
        ComputopEntityManagerInterface $computopEntityManager
48
    ) {
49
        $this->computopConfig = $computopConfig;
50
        $this->computopRepository = $computopRepository;
51
        $this->computopEntityManager = $computopEntityManager;
52
    }
53
54
    /**
55
     * @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer
56
     *
57
     * @return \Generated\Shared\Transfer\QuoteTransfer
58
     */
59
    public function save(QuoteTransfer $quoteTransfer): QuoteTransfer
60
    {
61
        $computopPayPalExpressInitResponseTransfer = $quoteTransfer->getPaymentOrFail()
62
            ->getComputopPayPalExpressOrFail()
63
            ->getPayPalExpressInitResponseOrFail();
64
65
        $computopPaymentComputopTransfer = $this->computopRepository
66
            ->findComputopPaymentByComputopTransId(
67
                $computopPayPalExpressInitResponseTransfer->getHeader()->getTransId()
68
            );
69
70
        if ($computopPayPalExpressInitResponseTransfer->getHeader()->getIsSuccess()) {
71
            $this->getTransactionHandler()->handleTransaction(
72
                function () use ($computopPaymentComputopTransfer, $computopPayPalExpressInitResponseTransfer) {
73
                    $this->executeSavePaymentComputopDataTransaction($computopPaymentComputopTransfer, $computopPayPalExpressInitResponseTransfer);
0 ignored issues
show
Bug introduced by
It seems like $computopPaymentComputopTransfer can also be of type null; however, parameter $computopPaymentComputopTransfer of SprykerEco\Zed\Computop\...mputopDataTransaction() does only seem to accept Generated\Shared\Transfe...PaymentComputopTransfer, maybe add an additional type check? ( Ignorable by Annotation )

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

73
                    $this->executeSavePaymentComputopDataTransaction(/** @scrutinizer ignore-type */ $computopPaymentComputopTransfer, $computopPayPalExpressInitResponseTransfer);
Loading history...
74
                }
75
            );
76
        }
77
78
        return $quoteTransfer;
79
    }
80
81
    /**
82
     * @param \Generated\Shared\Transfer\ComputopPaymentComputopTransfer $computopPaymentComputopTransfer
83
     * @param \Generated\Shared\Transfer\ComputopPayPalExpressInitResponseTransfer $computopPayPalExpressInitResponseTransfer
84
     *
85
     * @return void
86
     */
87
    protected function executeSavePaymentComputopDataTransaction(
88
        ComputopPaymentComputopTransfer $computopPaymentComputopTransfer,
89
        ComputopPayPalExpressInitResponseTransfer $computopPayPalExpressInitResponseTransfer
90
    ): void {
91
        $this->savePaymentComputopEntity($computopPaymentComputopTransfer, $computopPayPalExpressInitResponseTransfer);
92
        $this->savePaymentComputopDetailEntity($computopPaymentComputopTransfer, $computopPayPalExpressInitResponseTransfer);
93
        $this->savePaymentComputopOrderItemEntities($computopPaymentComputopTransfer);
94
    }
95
96
    /**
97
     * @param \Generated\Shared\Transfer\ComputopPaymentComputopTransfer $computopPaymentComputopTransfer
98
     * @param \Generated\Shared\Transfer\ComputopPayPalExpressInitResponseTransfer $computopPayPalExpressInitResponseTransfer
99
     *
100
     * @return void
101
     */
102
    protected function savePaymentComputopEntity(
103
        ComputopPaymentComputopTransfer $computopPaymentComputopTransfer,
104
        ComputopPayPalExpressInitResponseTransfer $computopPayPalExpressInitResponseTransfer
105
    ): void {
106
        $computopPaymentComputopTransfer->setPayId($computopPayPalExpressInitResponseTransfer->getHeader()->getPayId());
107
        $computopPaymentComputopTransfer->setXId($computopPayPalExpressInitResponseTransfer->getHeader()->getXId());
108
109
        $this->computopEntityManager->saveComputopPayment($computopPaymentComputopTransfer);
0 ignored issues
show
Bug introduced by
The method saveComputopPayment() does not exist on SprykerEco\Zed\Computop\...pEntityManagerInterface. ( Ignorable by Annotation )

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

109
        $this->computopEntityManager->/** @scrutinizer ignore-call */ 
110
                                      saveComputopPayment($computopPaymentComputopTransfer);

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...
110
    }
111
112
    /**
113
     * @param \Generated\Shared\Transfer\ComputopPaymentComputopTransfer $computopPaymentComputopTransfer
114
     * @param \Generated\Shared\Transfer\ComputopPayPalExpressInitResponseTransfer $computopPayPalExpressInitResponseTransfer
115
     *
116
     * @return void
117
     */
118
    protected function savePaymentComputopDetailEntity(
119
        ComputopPaymentComputopTransfer $computopPaymentComputopTransfer,
120
        ComputopPayPalExpressInitResponseTransfer $computopPayPalExpressInitResponseTransfer
121
    ): void {
122
        $computopPaymentComputopDetailTransfer = $this->computopRepository
123
            ->findComputopPaymentDetail($computopPaymentComputopTransfer);
124
125
        $computopPaymentComputopDetailTransfer->fromArray($computopPayPalExpressInitResponseTransfer->toArray(), true);
126
127
        $this->computopEntityManager->updateComputopPaymentDetail($computopPaymentComputopDetailTransfer);
0 ignored issues
show
Bug introduced by
It seems like $computopPaymentComputopDetailTransfer can also be of type null; however, parameter $computopPaymentComputopDetailTransfer of SprykerEco\Zed\Computop\...ComputopPaymentDetail() does only seem to accept Generated\Shared\Transfe...tComputopDetailTransfer, maybe add an additional type check? ( Ignorable by Annotation )

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

127
        $this->computopEntityManager->updateComputopPaymentDetail(/** @scrutinizer ignore-type */ $computopPaymentComputopDetailTransfer);
Loading history...
128
    }
129
130
    /**
131
     * @param \Generated\Shared\Transfer\ComputopPaymentComputopTransfer $computopPaymentComputopTransfer
132
     *
133
     * @return void
134
     */
135
    protected function savePaymentComputopOrderItemEntities(
136
        ComputopPaymentComputopTransfer $computopPaymentComputopTransfer
137
    ): void {
138
        $salesOrderItemCollectionTransfer = $this->computopRepository
139
            ->getComputopSalesOrderItemCollection($computopPaymentComputopTransfer);
140
141
        $computopPaymentComputopOrderItemCollection = $this->computopRepository
142
            ->getComputopPaymentComputopOrderItemCollection($computopPaymentComputopTransfer);
143
144
        foreach ($salesOrderItemCollectionTransfer->getComputopSalesOrderItems() as $computopSalesOrderItem) {
145
            $this->updateComputopSalesOrderItemCollection(
146
                $computopPaymentComputopOrderItemCollection,
147
                $computopSalesOrderItem
148
            );
149
        }
150
    }
151
152
    /**
153
     * @param \Generated\Shared\Transfer\ComputopPaymentComputopOrderItemCollectionTransfer $computopPaymentComputopOrderItemCollection
154
     * @param \Generated\Shared\Transfer\ComputopSalesOrderItemTransfer $computopSalesOrderItem
155
     *
156
     * @return void
157
     */
158
    protected function updateComputopSalesOrderItemCollection(
159
        ComputopPaymentComputopOrderItemCollectionTransfer $computopPaymentComputopOrderItemCollection,
160
        ComputopSalesOrderItemTransfer $computopSalesOrderItem
161
    ): void {
162
        foreach ($computopPaymentComputopOrderItemCollection->getComputopPaymentComputopOrderItems() as $computopPaymentComputopOrderItem) {
163
            if ($computopSalesOrderItem->getIdSalesOrderItem() !== $computopPaymentComputopOrderItem->getFkSalesOrderItem()) {
164
                continue;
165
            }
166
            $computopPaymentComputopOrderItem->setStatus($this->computopConfig->getOmsStatusInitialized());
167
            $this->computopEntityManager->updateComputopPaymentComputopOrderItem($computopPaymentComputopOrderItem);
168
        }
169
    }
170
}
171