Passed
Pull Request — master (#4)
by Aleksey
11:47 queued 02:44
created

findPaymentCrefoPayOrderItemToCrefoPayNotificationByIdSalesOrderItemAndTransactionStatus()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 23
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 15
nc 2
nop 2
dl 0
loc 23
rs 9.7666
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
     * @param string|null $captureId
98
     *
99
     * @return \Generated\Shared\Transfer\PaymentCrefoPayOrderItemCollectionTransfer
100
     */
101
    public function findPaymentCrefoPayOrderItemsByCrefoPayOrderIdAndCaptureId(
102
        string $crefoPayOrderId,
103
        ?string $captureId = null
104
    ): PaymentCrefoPayOrderItemCollectionTransfer {
105
        $query = $this->getPaymentCrefoPayOrderItemQuery();
106
        $query->useSpyPaymentCrefoPayQuery()
107
                ->filterByCrefoPayOrderId($crefoPayOrderId)
108
            ->endUse();
109
110
        if ($captureId !== null) {
111
            $query->filterByCaptureId($captureId);
112
        }
113
114
        $paymentCrefoPayOrderItemEntities = $query->find();
115
116
        $mapper = $this->getMapper();
117
        $result = new ArrayObject();
118
119
        foreach ($paymentCrefoPayOrderItemEntities as $paymentCrefoPayOrderItemEntity) {
120
            $paymentCrefoPayOrderItemTransfer = $mapper->mapEntityToPaymentCrefoPayOrderItemTransfer(
121
                $paymentCrefoPayOrderItemEntity,
122
                new PaymentCrefoPayOrderItemTransfer()
123
            );
124
            $result->append($paymentCrefoPayOrderItemTransfer);
125
        }
126
127
        return (new PaymentCrefoPayOrderItemCollectionTransfer())
128
            ->setCrefoPayOrderItems($result);
129
    }
130
131
    /**
132
     * @param int[] $salesOrderItemIds
133
     *
134
     * @return \Generated\Shared\Transfer\PaymentCrefoPayOrderItemCollectionTransfer
135
     */
136
    public function findPaymentCrefoPayOrderItemsBySalesOrderItemIds(array $salesOrderItemIds): PaymentCrefoPayOrderItemCollectionTransfer
137
    {
138
        $paymentCrefoPayOrderItemEntities = $this->getPaymentCrefoPayOrderItemQuery()
139
            ->filterByFkSalesOrderItem_In($salesOrderItemIds)
140
            ->find();
141
142
        $mapper = $this->getMapper();
143
        $result = new ArrayObject();
144
145
        foreach ($paymentCrefoPayOrderItemEntities as $paymentCrefoPayOrderItemEntity) {
146
            $paymentCrefoPayOrderItemTransfer = $mapper->mapEntityToPaymentCrefoPayOrderItemTransfer(
147
                $paymentCrefoPayOrderItemEntity,
148
                new PaymentCrefoPayOrderItemTransfer()
149
            );
150
            $result->append($paymentCrefoPayOrderItemTransfer);
151
        }
152
153
        return (new PaymentCrefoPayOrderItemCollectionTransfer())
154
            ->setCrefoPayOrderItems($result);
155
    }
156
157
    /**
158
     * @param int $idSalesOrderItem
159
     * @param string $apiLogRequestType
160
     * @param int[] $resultCodes
161
     *
162
     * @return \Generated\Shared\Transfer\PaymentCrefoPayOrderItemToCrefoPayApiLogTransfer
163
     */
164
    public function findPaymentCrefoPayOrderItemToCrefoPayApiLogByIdSalesOrderItemAndRequestTypeAndResultCodes(
165
        int $idSalesOrderItem,
166
        string $apiLogRequestType,
167
        array $resultCodes
168
    ): PaymentCrefoPayOrderItemToCrefoPayApiLogTransfer {
169
        $paymentCrefoPayOrderItemToCrefoPayApiLogEntity = $this->getPaymentCrefoPayOrderItemToCrefoPayApiLogQuery()
170
            ->useSpyPaymentCrefoPayOrderItemQuery()
171
                ->filterByFkSalesOrderItem($idSalesOrderItem)
172
            ->endUse()
173
            ->useSpyPaymentCrefoPayApiLogQuery()
174
                ->filterByRequestType($apiLogRequestType)
175
                ->filterByResultCode_In($resultCodes)
176
            ->endUse()
177
            ->findOne();
178
179
        $paymentCrefoPayOrderItemToCrefoPayApiLogTransfer = new PaymentCrefoPayOrderItemToCrefoPayApiLogTransfer();
180
181
        if ($paymentCrefoPayOrderItemToCrefoPayApiLogEntity === null) {
182
            return $paymentCrefoPayOrderItemToCrefoPayApiLogTransfer;
183
        }
184
185
        return $this->getMapper()
186
            ->mapEntityToPaymentCrefoPayOrderItemToCrefoPayApiLogTransfer(
187
                $paymentCrefoPayOrderItemToCrefoPayApiLogEntity,
188
                $paymentCrefoPayOrderItemToCrefoPayApiLogTransfer
189
            );
190
    }
191
192
    /**
193
     * @param int $idSalesOrderItem
194
     * @param string $notificationTransactionStatus
195
     *
196
     * @return \Generated\Shared\Transfer\PaymentCrefoPayOrderItemToCrefoPayNotificationTransfer
197
     */
198
    public function findPaymentCrefoPayOrderItemToCrefoPayNotificationByIdSalesOrderItemAndTransactionStatus(
199
        int $idSalesOrderItem,
200
        string $notificationTransactionStatus
201
    ): PaymentCrefoPayOrderItemToCrefoPayNotificationTransfer {
202
        $paymentCrefoPayOrderItemToCrefoPayNotificationEntity = $this->getPaymentCrefoPayOrderItemToCrefoPayNotificationQuery()
203
            ->useSpyPaymentCrefoPayOrderItemQuery()
204
                ->filterByFkSalesOrderItem($idSalesOrderItem)
205
            ->endUse()
206
            ->useSpyPaymentCrefoPayNotificationQuery()
207
                ->filterByTransactionStatus($notificationTransactionStatus)
208
            ->endUse()
209
            ->findOne();
210
211
        $paymentCrefoPayOrderItemToCrefoPayNotificationTransfer = new PaymentCrefoPayOrderItemToCrefoPayNotificationTransfer();
212
213
        if ($paymentCrefoPayOrderItemToCrefoPayNotificationEntity === null) {
214
            return $paymentCrefoPayOrderItemToCrefoPayNotificationTransfer;
215
        }
216
217
        return $this->getMapper()
218
            ->mapEntityToPaymentCrefoPayOrderItemToCrefoPayNotificationTransfer(
219
                $paymentCrefoPayOrderItemToCrefoPayNotificationEntity,
220
                $paymentCrefoPayOrderItemToCrefoPayNotificationTransfer
221
            );
222
    }
223
224
    /**
225
     * @param int $idSalesOrderItem
226
     * @param string $notificationOrderStatus
227
     *
228
     * @return \Generated\Shared\Transfer\PaymentCrefoPayOrderItemToCrefoPayNotificationTransfer
229
     */
230
    public function findPaymentCrefoPayOrderItemToCrefoPayNotificationByIdSalesOrderItemAndOrderStatus(
231
        int $idSalesOrderItem,
232
        string $notificationOrderStatus
233
    ): PaymentCrefoPayOrderItemToCrefoPayNotificationTransfer {
234
        $paymentCrefoPayOrderItemToCrefoPayNotificationEntity = $this->getPaymentCrefoPayOrderItemToCrefoPayNotificationQuery()
235
            ->useSpyPaymentCrefoPayOrderItemQuery()
236
                ->filterByFkSalesOrderItem($idSalesOrderItem)
237
            ->endUse()
238
            ->useSpyPaymentCrefoPayNotificationQuery()
239
                ->filterByOrderStatus($notificationOrderStatus)
240
            ->endUse()
241
            ->findOne();
242
243
        $paymentCrefoPayOrderItemToCrefoPayNotificationTransfer = new PaymentCrefoPayOrderItemToCrefoPayNotificationTransfer();
244
245
        if ($paymentCrefoPayOrderItemToCrefoPayNotificationEntity === null) {
246
            return $paymentCrefoPayOrderItemToCrefoPayNotificationTransfer;
247
        }
248
249
        return $this->getMapper()
250
            ->mapEntityToPaymentCrefoPayOrderItemToCrefoPayNotificationTransfer(
251
                $paymentCrefoPayOrderItemToCrefoPayNotificationEntity,
252
                $paymentCrefoPayOrderItemToCrefoPayNotificationTransfer
253
            );
254
    }
255
256
    /**
257
     * @return \SprykerEco\Zed\CrefoPay\Persistence\Mapper\CrefoPayPersistenceMapperInterface
258
     */
259
    protected function getMapper(): CrefoPayPersistenceMapperInterface
260
    {
261
        return $this->getFactory()->createCrefoPayPersistenceMapper();
262
    }
263
264
    /**
265
     * @return \Orm\Zed\CrefoPay\Persistence\SpyPaymentCrefoPayQuery
266
     */
267
    protected function getPaymentCrefoPayQuery(): SpyPaymentCrefoPayQuery
268
    {
269
        return $this->getFactory()->createPaymentCrefoPayQuery();
270
    }
271
272
    /**
273
     * @return \Orm\Zed\CrefoPay\Persistence\SpyPaymentCrefoPayOrderItemQuery
274
     */
275
    protected function getPaymentCrefoPayOrderItemQuery(): SpyPaymentCrefoPayOrderItemQuery
276
    {
277
        return $this->getFactory()->createPaymentCrefoPayOrderItemQuery();
278
    }
279
280
    /**
281
     * @return \Orm\Zed\CrefoPay\Persistence\SpyPaymentCrefoPayOrderItemToCrefoPayApiLogQuery
282
     */
283
    protected function getPaymentCrefoPayOrderItemToCrefoPayApiLogQuery(): SpyPaymentCrefoPayOrderItemToCrefoPayApiLogQuery
284
    {
285
        return $this->getFactory()->createPaymentCrefoPayOrderItemToCrefoPayApiLogQuery();
286
    }
287
288
    /**
289
     * @return \Orm\Zed\CrefoPay\Persistence\SpyPaymentCrefoPayOrderItemToCrefoPayNotificationQuery
290
     */
291
    protected function getPaymentCrefoPayOrderItemToCrefoPayNotificationQuery(): SpyPaymentCrefoPayOrderItemToCrefoPayNotificationQuery
292
    {
293
        return $this->getFactory()->createPaymentCrefoPayOrderItemToCrefoPayNotificationQuery();
294
    }
295
296
    /**
297
     * @return \Orm\Zed\Sales\Persistence\SpySalesOrderItemQuery
298
     */
299
    protected function getSalesOrderItemQuery(): SpySalesOrderItemQuery
300
    {
301
        return $this->getFactory()->createSpySalesOrderItemQuery();
302
    }
303
}
304