Passed
Push — bugfix/eco-2800-paid-notificat... ( 786e71...9fba1f )
by Aleksey
03:11
created

mapOrderItemEntitiesToOrderItemCollection()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 17
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 9
nc 2
nop 2
dl 0
loc 17
rs 9.9666
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\Persistence;
9
10
use ArrayObject;
11
use Generated\Shared\Transfer\PaymentCrefoPayOrderItemCollectionTransfer;
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...
12
use Generated\Shared\Transfer\PaymentCrefoPayOrderItemToCrefoPayApiLogTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...oCrefoPayApiLogTransfer 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\PaymentCrefoPayOrderItemToCrefoPayNotificationTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...PayNotificationTransfer 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\PaymentCrefoPayOrderItemTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...efoPayOrderItemTransfer 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 Generated\Shared\Transfer\PaymentCrefoPayTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\PaymentCrefoPayTransfer 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...
16
use Orm\Zed\CrefoPay\Persistence\SpyPaymentCrefoPayOrderItemQuery;
0 ignored issues
show
Bug introduced by
The type Orm\Zed\CrefoPay\Persist...tCrefoPayOrderItemQuery 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...
17
use Orm\Zed\CrefoPay\Persistence\SpyPaymentCrefoPayOrderItemToCrefoPayApiLogQuery;
0 ignored issues
show
Bug introduced by
The type Orm\Zed\CrefoPay\Persist...emToCrefoPayApiLogQuery 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...
18
use Orm\Zed\CrefoPay\Persistence\SpyPaymentCrefoPayOrderItemToCrefoPayNotificationQuery;
0 ignored issues
show
Bug introduced by
The type Orm\Zed\CrefoPay\Persist...efoPayNotificationQuery 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...
19
use Orm\Zed\CrefoPay\Persistence\SpyPaymentCrefoPayQuery;
0 ignored issues
show
Bug introduced by
The type Orm\Zed\CrefoPay\Persist...SpyPaymentCrefoPayQuery 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...
20
use Orm\Zed\Sales\Persistence\SpySalesOrderItemQuery;
0 ignored issues
show
Bug introduced by
The type Orm\Zed\Sales\Persistence\SpySalesOrderItemQuery 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
use Spryker\Zed\Kernel\Persistence\AbstractRepository;
22
use SprykerEco\Zed\CrefoPay\Persistence\Mapper\CrefoPayPersistenceMapperInterface;
23
24
/**
25
 * @method \SprykerEco\Zed\CrefoPay\Persistence\CrefoPayPersistenceFactory getFactory()
26
 */
27
class CrefoPayRepository extends AbstractRepository implements CrefoPayRepositoryInterface
28
{
29
    /**
30
     * @param int $fkSalesOrder
31
     *
32
     * @return \Generated\Shared\Transfer\PaymentCrefoPayTransfer
33
     */
34
    public function findPaymentCrefoPayByFkSalesOrder(int $fkSalesOrder): PaymentCrefoPayTransfer
35
    {
36
        $paymentCrefoPayEntity = $this->getPaymentCrefoPayQuery()
37
            ->filterByFkSalesOrder($fkSalesOrder)
38
            ->findOne();
39
40
        $paymentCrefoPayTransfer = new PaymentCrefoPayTransfer();
41
42
        if ($paymentCrefoPayEntity === null) {
43
            return $paymentCrefoPayTransfer;
44
        }
45
46
        return $this->getMapper()
47
            ->mapEntityToPaymentCrefoPayTransfer($paymentCrefoPayEntity, $paymentCrefoPayTransfer);
48
    }
49
50
    /**
51
     * @param string $crefoPayOrderId
52
     *
53
     * @return \Generated\Shared\Transfer\PaymentCrefoPayTransfer
54
     */
55
    public function findPaymentCrefoPayByCrefoPayOrderId(string $crefoPayOrderId): PaymentCrefoPayTransfer
56
    {
57
        $paymentCrefoPayEntity = $this->getPaymentCrefoPayQuery()
58
            ->filterByCrefoPayOrderId($crefoPayOrderId)
59
            ->findOne();
60
61
        $paymentCrefoPayTransfer = new PaymentCrefoPayTransfer();
62
63
        if ($paymentCrefoPayEntity === null) {
64
            return $paymentCrefoPayTransfer;
65
        }
66
67
        return $this->getMapper()
68
            ->mapEntityToPaymentCrefoPayTransfer($paymentCrefoPayEntity, $paymentCrefoPayTransfer);
69
    }
70
71
    /**
72
     * @param int $idSalesOrderItem
73
     *
74
     * @return \Generated\Shared\Transfer\PaymentCrefoPayTransfer
75
     */
76
    public function findPaymentCrefoPayByIdSalesOrderItem(int $idSalesOrderItem): PaymentCrefoPayTransfer
77
    {
78
        /** @var \Orm\Zed\CrefoPay\Persistence\SpyPaymentCrefoPay|null $paymentCrefoPayEntity */
79
        $paymentCrefoPayEntity = $this->getPaymentCrefoPayQuery()
80
            ->useSpyPaymentCrefoPayOrderItemQuery()
81
                ->filterByFkSalesOrderItem($idSalesOrderItem)
82
            ->endUse()
83
            ->findOne();
84
85
        $paymentCrefoPayTransfer = new PaymentCrefoPayTransfer();
86
87
        if ($paymentCrefoPayEntity === null) {
88
            return $paymentCrefoPayTransfer;
89
        }
90
91
        return $this->getMapper()
92
            ->mapEntityToPaymentCrefoPayTransfer($paymentCrefoPayEntity, $paymentCrefoPayTransfer);
93
    }
94
95
    /**
96
     * @param string $crefoPayOrderId
97
     *
98
     * @return \Generated\Shared\Transfer\PaymentCrefoPayOrderItemCollectionTransfer
99
     */
100
    public function findPaymentCrefoPayOrderItemsByCrefoPayOrderId(string $crefoPayOrderId): PaymentCrefoPayOrderItemCollectionTransfer
101
    {
102
        /** @var \Orm\Zed\CrefoPay\Persistence\SpyPaymentCrefoPayOrderItem[] $paymentCrefoPayOrderItemEntities */
103
        $paymentCrefoPayOrderItemEntities = $this->getPaymentCrefoPayOrderItemQuery()
104
            ->useSpyPaymentCrefoPayQuery()
105
                ->filterByCrefoPayOrderId($crefoPayOrderId)
106
            ->endUse()
107
            ->find();
108
109
        return $this->mapOrderItemEntitiesToOrderItemCollection(
110
            $paymentCrefoPayOrderItemEntities,
111
            new PaymentCrefoPayOrderItemCollectionTransfer()
112
        );
113
    }
114
115
    /**
116
     * @param string $captureId
117
     *
118
     * @return \Generated\Shared\Transfer\PaymentCrefoPayOrderItemCollectionTransfer
119
     */
120
    public function findPaymentCrefoPayOrderItemsByCaptureId(string $captureId): PaymentCrefoPayOrderItemCollectionTransfer
121
    {
122
        /** @var \Orm\Zed\CrefoPay\Persistence\SpyPaymentCrefoPayOrderItem[] $paymentCrefoPayOrderItemEntities */
123
        $paymentCrefoPayOrderItemEntities = $this->getPaymentCrefoPayOrderItemQuery()
124
            ->filterByCaptureId($captureId)
125
            ->find();
126
127
        return $this->mapOrderItemEntitiesToOrderItemCollection(
128
            $paymentCrefoPayOrderItemEntities,
129
            new PaymentCrefoPayOrderItemCollectionTransfer()
130
        );
131
    }
132
133
    /**
134
     * @param int[] $salesOrderItemIds
135
     *
136
     * @return \Generated\Shared\Transfer\PaymentCrefoPayOrderItemCollectionTransfer
137
     */
138
    public function findPaymentCrefoPayOrderItemsBySalesOrderItemIds(array $salesOrderItemIds): PaymentCrefoPayOrderItemCollectionTransfer
139
    {
140
        /** @var \Orm\Zed\CrefoPay\Persistence\SpyPaymentCrefoPayOrderItem[] $paymentCrefoPayOrderItemEntities */
141
        $paymentCrefoPayOrderItemEntities = $this->getPaymentCrefoPayOrderItemQuery()
142
            ->filterByFkSalesOrderItem_In($salesOrderItemIds)
143
            ->find();
144
145
        return $this->mapOrderItemEntitiesToOrderItemCollection(
146
            $paymentCrefoPayOrderItemEntities,
147
            new PaymentCrefoPayOrderItemCollectionTransfer()
148
        );
149
    }
150
151
    /**
152
     * @param int $idSalesOrderItem
153
     * @param string $apiLogRequestType
154
     * @param int[] $resultCodes
155
     *
156
     * @return \Generated\Shared\Transfer\PaymentCrefoPayOrderItemToCrefoPayApiLogTransfer
157
     */
158
    public function findPaymentCrefoPayOrderItemToCrefoPayApiLogByIdSalesOrderItemAndRequestTypeAndResultCodes(
159
        int $idSalesOrderItem,
160
        string $apiLogRequestType,
161
        array $resultCodes
162
    ): PaymentCrefoPayOrderItemToCrefoPayApiLogTransfer {
163
        $paymentCrefoPayOrderItemToCrefoPayApiLogEntity = $this->getPaymentCrefoPayOrderItemToCrefoPayApiLogQuery()
164
            ->useSpyPaymentCrefoPayOrderItemQuery()
165
                ->filterByFkSalesOrderItem($idSalesOrderItem)
166
            ->endUse()
167
            ->useSpyPaymentCrefoPayApiLogQuery()
168
                ->filterByRequestType($apiLogRequestType)
169
                ->filterByResultCode_In($resultCodes)
170
            ->endUse()
171
            ->findOne();
172
173
        $paymentCrefoPayOrderItemToCrefoPayApiLogTransfer = new PaymentCrefoPayOrderItemToCrefoPayApiLogTransfer();
174
175
        if ($paymentCrefoPayOrderItemToCrefoPayApiLogEntity === null) {
176
            return $paymentCrefoPayOrderItemToCrefoPayApiLogTransfer;
177
        }
178
179
        return $this->getMapper()
180
            ->mapEntityToPaymentCrefoPayOrderItemToCrefoPayApiLogTransfer(
181
                $paymentCrefoPayOrderItemToCrefoPayApiLogEntity,
182
                $paymentCrefoPayOrderItemToCrefoPayApiLogTransfer
183
            );
184
    }
185
186
    /**
187
     * @param int $idSalesOrderItem
188
     * @param string $notificationTransactionStatus
189
     *
190
     * @return \Generated\Shared\Transfer\PaymentCrefoPayOrderItemToCrefoPayNotificationTransfer
191
     */
192
    public function findPaymentCrefoPayOrderItemToCrefoPayNotificationByIdSalesOrderItemAndTransactionStatus(
193
        int $idSalesOrderItem,
194
        string $notificationTransactionStatus
195
    ): PaymentCrefoPayOrderItemToCrefoPayNotificationTransfer {
196
        $paymentCrefoPayOrderItemToCrefoPayNotificationEntity = $this->getPaymentCrefoPayOrderItemToCrefoPayNotificationQuery()
197
            ->useSpyPaymentCrefoPayOrderItemQuery()
198
                ->filterByFkSalesOrderItem($idSalesOrderItem)
199
            ->endUse()
200
            ->useSpyPaymentCrefoPayNotificationQuery()
201
                ->filterByTransactionStatus($notificationTransactionStatus)
202
            ->endUse()
203
            ->findOne();
204
205
        $paymentCrefoPayOrderItemToCrefoPayNotificationTransfer = new PaymentCrefoPayOrderItemToCrefoPayNotificationTransfer();
206
207
        if ($paymentCrefoPayOrderItemToCrefoPayNotificationEntity === null) {
208
            return $paymentCrefoPayOrderItemToCrefoPayNotificationTransfer;
209
        }
210
211
        return $this->getMapper()
212
            ->mapEntityToPaymentCrefoPayOrderItemToCrefoPayNotificationTransfer(
213
                $paymentCrefoPayOrderItemToCrefoPayNotificationEntity,
214
                $paymentCrefoPayOrderItemToCrefoPayNotificationTransfer
215
            );
216
    }
217
218
    /**
219
     * @param int $idSalesOrderItem
220
     * @param string $notificationOrderStatus
221
     *
222
     * @return \Generated\Shared\Transfer\PaymentCrefoPayOrderItemToCrefoPayNotificationTransfer
223
     */
224
    public function findPaymentCrefoPayOrderItemToCrefoPayNotificationByIdSalesOrderItemAndOrderStatus(
225
        int $idSalesOrderItem,
226
        string $notificationOrderStatus
227
    ): PaymentCrefoPayOrderItemToCrefoPayNotificationTransfer {
228
        $paymentCrefoPayOrderItemToCrefoPayNotificationEntity = $this->getPaymentCrefoPayOrderItemToCrefoPayNotificationQuery()
229
            ->useSpyPaymentCrefoPayOrderItemQuery()
230
                ->filterByFkSalesOrderItem($idSalesOrderItem)
231
            ->endUse()
232
            ->useSpyPaymentCrefoPayNotificationQuery()
233
                ->filterByOrderStatus($notificationOrderStatus)
234
            ->endUse()
235
            ->findOne();
236
237
        $paymentCrefoPayOrderItemToCrefoPayNotificationTransfer = new PaymentCrefoPayOrderItemToCrefoPayNotificationTransfer();
238
239
        if ($paymentCrefoPayOrderItemToCrefoPayNotificationEntity === null) {
240
            return $paymentCrefoPayOrderItemToCrefoPayNotificationTransfer;
241
        }
242
243
        return $this->getMapper()
244
            ->mapEntityToPaymentCrefoPayOrderItemToCrefoPayNotificationTransfer(
245
                $paymentCrefoPayOrderItemToCrefoPayNotificationEntity,
246
                $paymentCrefoPayOrderItemToCrefoPayNotificationTransfer
247
            );
248
    }
249
250
    /**
251
     * @param \Orm\Zed\CrefoPay\Persistence\SpyPaymentCrefoPayOrderItem[] $paymentCrefoPayOrderItemEntities
252
     * @param \Generated\Shared\Transfer\PaymentCrefoPayOrderItemCollectionTransfer $crefoPayOrderItemCollectionTransfer
253
     *
254
     * @return \Generated\Shared\Transfer\PaymentCrefoPayOrderItemCollectionTransfer
255
     */
256
    protected function mapOrderItemEntitiesToOrderItemCollection(
257
        array $paymentCrefoPayOrderItemEntities,
258
        PaymentCrefoPayOrderItemCollectionTransfer $crefoPayOrderItemCollectionTransfer
259
    ): PaymentCrefoPayOrderItemCollectionTransfer {
260
        $mapper = $this->getMapper();
261
        $result = new ArrayObject();
262
263
        foreach ($paymentCrefoPayOrderItemEntities as $paymentCrefoPayOrderItemEntity) {
264
            $paymentCrefoPayOrderItemTransfer = $mapper->mapEntityToPaymentCrefoPayOrderItemTransfer(
265
                $paymentCrefoPayOrderItemEntity,
266
                new PaymentCrefoPayOrderItemTransfer()
267
            );
268
            $result->append($paymentCrefoPayOrderItemTransfer);
269
        }
270
271
        return $crefoPayOrderItemCollectionTransfer
272
            ->setCrefoPayOrderItems($result);
273
    }
274
275
    /**
276
     * @return \SprykerEco\Zed\CrefoPay\Persistence\Mapper\CrefoPayPersistenceMapperInterface
277
     */
278
    protected function getMapper(): CrefoPayPersistenceMapperInterface
279
    {
280
        return $this->getFactory()->createCrefoPayPersistenceMapper();
281
    }
282
283
    /**
284
     * @return \Orm\Zed\CrefoPay\Persistence\SpyPaymentCrefoPayQuery
285
     */
286
    protected function getPaymentCrefoPayQuery(): SpyPaymentCrefoPayQuery
287
    {
288
        return $this->getFactory()->createPaymentCrefoPayQuery();
289
    }
290
291
    /**
292
     * @return \Orm\Zed\CrefoPay\Persistence\SpyPaymentCrefoPayOrderItemQuery
293
     */
294
    protected function getPaymentCrefoPayOrderItemQuery(): SpyPaymentCrefoPayOrderItemQuery
295
    {
296
        return $this->getFactory()->createPaymentCrefoPayOrderItemQuery();
297
    }
298
299
    /**
300
     * @return \Orm\Zed\CrefoPay\Persistence\SpyPaymentCrefoPayOrderItemToCrefoPayApiLogQuery
301
     */
302
    protected function getPaymentCrefoPayOrderItemToCrefoPayApiLogQuery(): SpyPaymentCrefoPayOrderItemToCrefoPayApiLogQuery
303
    {
304
        return $this->getFactory()->createPaymentCrefoPayOrderItemToCrefoPayApiLogQuery();
305
    }
306
307
    /**
308
     * @return \Orm\Zed\CrefoPay\Persistence\SpyPaymentCrefoPayOrderItemToCrefoPayNotificationQuery
309
     */
310
    protected function getPaymentCrefoPayOrderItemToCrefoPayNotificationQuery(): SpyPaymentCrefoPayOrderItemToCrefoPayNotificationQuery
311
    {
312
        return $this->getFactory()->createPaymentCrefoPayOrderItemToCrefoPayNotificationQuery();
313
    }
314
315
    /**
316
     * @return \Orm\Zed\Sales\Persistence\SpySalesOrderItemQuery
317
     */
318
    protected function getSalesOrderItemQuery(): SpySalesOrderItemQuery
319
    {
320
        return $this->getFactory()->createSpySalesOrderItemQuery();
321
    }
322
}
323