getPaymentFirstDataItemCollection()   A
last analyzed

Complexity

Conditions 4
Paths 6

Size

Total Lines 25
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
c 1
b 0
f 0
dl 0
loc 25
rs 9.8333
cc 4
nc 6
nop 2
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\FirstData\Persistence;
9
10
use Generated\Shared\Transfer\FirstDataNotificationTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...ataNotificationTransfer 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\PaymentFirstDataItemTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...ntFirstDataItemTransfer 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\PaymentFirstDataTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\PaymentFirstDataTransfer 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 Spryker\Zed\Kernel\Persistence\AbstractRepository;
14
15
/**
16
 * @method \SprykerEco\Zed\FirstData\Persistence\FirstDataPersistenceFactory getFactory()
17
 */
18
class FirstDataRepository extends AbstractRepository implements FirstDataRepositoryInterface
19
{
20
    /**
21
     * @param string $transactionId
22
     *
23
     * @return \Generated\Shared\Transfer\FirstDataNotificationTransfer|null
24
     */
25
    public function findPaymentFirstDataNotificationByTransactionId(string $transactionId): ?FirstDataNotificationTransfer
26
    {
27
        $paymentFirstDataNotificationEntity = $this->getFactory()
28
            ->createSpyPaymentFirstDataNotificationQuery()
29
            ->filterByTransactionId($transactionId)
30
            ->findOne();
31
32
        if (!$paymentFirstDataNotificationEntity) {
33
            return null;
34
        }
35
36
        return (new FirstDataNotificationTransfer())
37
            ->fromArray($paymentFirstDataNotificationEntity->toArray(), true);
38
    }
39
40
    /**
41
     * @param int $idSalesOrderItem
42
     *
43
     * @return \Generated\Shared\Transfer\PaymentFirstDataTransfer|null
44
     */
45
    public function findPaymentFirstDataByIdSalesOrderItem(int $idSalesOrderItem): ?PaymentFirstDataTransfer
46
    {
47
        $paymentFirstDataEntity = $this->getFactory()
48
            ->createPaymentFirstDataQuery()
49
            ->usePaymentFirstDataItemQuery()
50
                ->filterByFkSalesOrderItem($idSalesOrderItem)
51
            ->endUse()
52
            ->findOne();
53
54
        if (!$paymentFirstDataEntity) {
55
            return null;
56
        }
57
58
        return (new PaymentFirstDataTransfer())
59
            ->fromArray($paymentFirstDataEntity->toArray(), true);
60
    }
61
62
    /**
63
     * @param \Generated\Shared\Transfer\PaymentFirstDataTransfer $paymentFirstDataTransfer
64
     * @param int[] $salesOrderItemIds
65
     *
66
     * @return \Generated\Shared\Transfer\PaymentFirstDataItemTransfer[]
67
     */
68
    public function getPaymentFirstDataItemCollection(
69
        PaymentFirstDataTransfer $paymentFirstDataTransfer,
70
        array $salesOrderItemIds = []
71
    ): array {
72
        $paymentFirstDataItemEntityCollection = $this->getFactory()
73
            ->createPaymentFirstDataItemQuery()
74
            ->filterByFkPaymentFirstData($paymentFirstDataTransfer->getIdPaymentFirstData());
75
76
        if ($salesOrderItemIds) {
77
            $paymentFirstDataItemEntityCollection->filterByFkSalesOrderItem_In($salesOrderItemIds);
78
        }
79
80
        $paymentFirstDataItemEntityCollection->find();
81
82
        if (!$paymentFirstDataItemEntityCollection->count()) {
83
            return [];
84
        }
85
86
        $paymentFirstDataItemTransfers = [];
87
        foreach ($paymentFirstDataItemEntityCollection as $paymentFirstDataItemEntity) {
88
            $paymentFirstDataItemTransfers[] = (new PaymentFirstDataItemTransfer())
89
                ->fromArray($paymentFirstDataItemEntity->toArray(), true);
90
        }
91
92
        return $paymentFirstDataItemTransfers;
93
    }
94
95
    /**
96
     * @param int $idSalesOrderItem
97
     * @param string $stateName
98
     *
99
     * @return int
100
     */
101
    public function countOmsOrderItemStateHistoryByStateNameAndIdSalesOrderItem(int $idSalesOrderItem, string $stateName): int
102
    {
103
        return $this->getFactory()
104
            ->createOmsOrderItemStateHistoryQuery()
105
            ->filterByFkSalesOrderItem($idSalesOrderItem)
106
            ->useStateQuery()
107
                ->filterByName($stateName)
108
            ->endUse()
109
            ->count();
110
    }
111
112
    /**
113
     * @param int $idSalesOrder
114
     *
115
     * @return \Generated\Shared\Transfer\PaymentFirstDataTransfer|null
116
     */
117
    public function findPaymentFirstDataByIdSalesOrder(int $idSalesOrder): ?PaymentFirstDataTransfer
118
    {
119
        $paymentFirstDataEntity = $this->getFactory()
120
            ->createPaymentFirstDataQuery()
121
            ->filterByFkSalesOrder($idSalesOrder)
122
            ->findOne();
123
124
        if (!$paymentFirstDataEntity) {
125
            return null;
126
        }
127
128
        return (new PaymentFirstDataTransfer())
129
            ->fromArray($paymentFirstDataEntity->toArray(), true);
130
    }
131
}
132