Completed
Pull Request — master (#4)
by Oleksandr
17:46 queued 08:55
created

findPaymentCrefoPayByIdSalesOrderItem()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 17
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

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