Passed
Push — feature/paypal-express ( ddef87...f7968e )
by Volodymyr
05:46
created

findPaymentBraintreeBySalesOrderId()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 8
nc 2
nop 1
dl 0
loc 13
rs 10
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\Braintree\Persistence;
9
10
use Generated\Shared\Transfer\PaymentBraintreeTransactionRequestLogTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...ctionRequestLogTransfer 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\PaymentBraintreeTransactionStatusLogTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...actionStatusLogTransfer 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\PaymentBraintreeTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\PaymentBraintreeTransfer 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 Orm\Zed\Braintree\Persistence\Map\SpyPaymentBraintreeTransactionRequestLogTableMap;
0 ignored issues
show
Bug introduced by
The type Orm\Zed\Braintree\Persis...ctionRequestLogTableMap 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 Orm\Zed\Braintree\Persistence\Map\SpyPaymentBraintreeTransactionStatusLogTableMap;
0 ignored issues
show
Bug introduced by
The type Orm\Zed\Braintree\Persis...actionStatusLogTableMap 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 Propel\Runtime\ActiveQuery\Criteria;
16
use Propel\Runtime\Propel;
17
use Spryker\Zed\Kernel\Persistence\AbstractRepository;
18
19
/**
20
 * @method \SprykerEco\Zed\Braintree\Persistence\BraintreePersistenceFactory getFactory()
21
 */
22
class BraintreeRepository extends AbstractRepository implements BraintreeRepositoryInterface
23
{
24
    /**
25
     * @param int $idPaymentBraintree
26
     *
27
     * @return \Generated\Shared\Transfer\PaymentBraintreeTransfer|null
28
     */
29
    public function findPaymentBraintreeById(int $idPaymentBraintree): ?PaymentBraintreeTransfer
30
    {
31
        $paymentBraintreeEntity = $this->getFactory()
32
            ->createPaymentBraintreeQuery()
33
            ->findOneByIdPaymentBraintree($idPaymentBraintree);
34
35
        if ($paymentBraintreeEntity === null) {
36
            return null;
37
        }
38
39
        return $this->getFactory()
40
            ->createBraintreePersistenceMapper()
41
            ->mapEntityToPaymentBraintreeTransfer($paymentBraintreeEntity, new PaymentBraintreeTransfer());
42
    }
43
44
    /**
45
     * @param int $idSalesOrder
46
     *
47
     * @return \Generated\Shared\Transfer\PaymentBraintreeTransfer|null
48
     */
49
    public function findPaymentBraintreeBySalesOrderId(int $idSalesOrder): ?PaymentBraintreeTransfer
50
    {
51
        $paymentBraintreeEntity = $this->getFactory()
52
            ->createPaymentBraintreeQuery()
53
            ->findOneByFkSalesOrder($idSalesOrder);
54
55
        if ($paymentBraintreeEntity === null) {
56
            return null;
57
        }
58
59
        return $this->getFactory()
60
            ->createBraintreePersistenceMapper()
61
            ->mapEntityToPaymentBraintreeTransfer($paymentBraintreeEntity, new PaymentBraintreeTransfer());
62
    }
63
64
    /**
65
     * @param int $idPaymentBraintree
66
     *
67
     * @return \Generated\Shared\Transfer\PaymentBraintreeTransactionStatusLogTransfer|null
68
     */
69
    public function findPaymentBraintreeTransactionStatusLogQueryByPaymentBraintreeId(int $idPaymentBraintree): ?PaymentBraintreeTransactionStatusLogTransfer
70
    {
71
        $paymentBraintreeTransactionStatusLogEntity = $this->getFactory()
72
            ->createPaymentBraintreeTransactionStatusLogQuery()
73
            ->findOneByFkPaymentBraintree($idPaymentBraintree);
74
75
        if ($paymentBraintreeTransactionStatusLogEntity === null) {
76
            return null;
77
        }
78
79
        return $this->getFactory()
80
            ->createBraintreePersistenceMapper()
81
            ->mapEntityToPaymentBraintreeTransactionStatusLogTransfer($paymentBraintreeTransactionStatusLogEntity, new PaymentBraintreeTransactionStatusLogTransfer());
82
    }
83
84
    /**
85
     * @param int $idSalesOrder
86
     *
87
     * @return \Generated\Shared\Transfer\PaymentBraintreeTransactionStatusLogTransfer|null
88
     */
89
    public function findPaymentBraintreeTransactionStatusLogQueryBySalesOrderId(int $idSalesOrder): ?PaymentBraintreeTransactionStatusLogTransfer
90
    {
91
        $paymentBraintreeTransactionStatusLogEntity = $this->getFactory()
92
            ->createPaymentBraintreeTransactionStatusLogQuery()
93
            ->useSpyPaymentBraintreeQuery()
94
            ->filterByFkSalesOrder($idSalesOrder)
95
            ->endUse()
96
            ->findOne();
97
98
        if ($paymentBraintreeTransactionStatusLogEntity === null) {
99
            return null;
100
        }
101
102
        return $this->getFactory()
103
            ->createBraintreePersistenceMapper()
104
            ->mapEntityToPaymentBraintreeTransactionStatusLogTransfer($paymentBraintreeTransactionStatusLogEntity, new PaymentBraintreeTransactionStatusLogTransfer());
105
    }
106
107
    /**
108
     * @param int $idSalesOrder
109
     * @param string $transactionCode
110
     * @param string|array $statusCode
111
     *
112
     * @return \Generated\Shared\Transfer\PaymentBraintreeTransactionStatusLogTransfer|null
113
     */
114
    public function findPaymentBraintreeTransactionStatusLogQueryBySalesOrderIdAndTransactionCodeLatestFirst(
115
        int $idSalesOrder,
116
        string $transactionCode,
117
        $statusCode
118
    ): ?PaymentBraintreeTransactionStatusLogTransfer {
119
        $paymentBraintreeTransactionStatusLogEntity = $this->getFactory()
120
            ->createPaymentBraintreeTransactionStatusLogQuery()
121
            ->useSpyPaymentBraintreeQuery()
122
            ->filterByFkSalesOrder($idSalesOrder)
123
            ->endUse()
124
            ->orderByIdPaymentBraintreeTransactionStatusLog(Criteria::DESC)
125
            ->withColumn(SpyPaymentBraintreeTransactionRequestLogTableMap::COL_TRANSACTION_CODE)
126
            ->addJoin(
127
                [
128
                    SpyPaymentBraintreeTransactionStatusLogTableMap::COL_TRANSACTION_ID,
129
                    SpyPaymentBraintreeTransactionRequestLogTableMap::COL_TRANSACTION_CODE,
130
                ],
131
                [
132
                    SpyPaymentBraintreeTransactionRequestLogTableMap::COL_TRANSACTION_ID,
133
                    Propel::getConnection()->quote($transactionCode),
134
                ]
135
            )
136
            ->filterByTransactionStatus((array)$statusCode, Criteria::IN)
137
            ->findOne();
138
139
        if ($paymentBraintreeTransactionStatusLogEntity === null) {
140
            return null;
141
        }
142
143
        return $this->getFactory()
144
            ->createBraintreePersistenceMapper()
145
            ->mapEntityToPaymentBraintreeTransactionStatusLogTransfer($paymentBraintreeTransactionStatusLogEntity, new PaymentBraintreeTransactionStatusLogTransfer());
146
    }
147
148
    /**
149
     * @param int $idSalesOrder
150
     * @param string $transactionCode
151
     * @param string|array $statusCode
152
     *
153
     * @return \Generated\Shared\Transfer\PaymentBraintreeTransactionStatusLogTransfer|null
154
     */
155
    public function findSucceededPaymentBraintreeTransactionStatusLogQueryBySalesOrderIdAndTransactionCode(
156
        int $idSalesOrder,
157
        string $transactionCode,
158
        $statusCode
159
    ): ?PaymentBraintreeTransactionStatusLogTransfer {
160
        $paymentBraintreeTransactionStatusLogEntity = $this->getFactory()
161
            ->createPaymentBraintreeTransactionStatusLogQuery()
162
            ->filterByTransactionCode($transactionCode)
163
            ->filterByTransactionStatus((array)$statusCode, Criteria::IN)
164
            ->useSpyPaymentBraintreeQuery()
165
                ->filterByFkSalesOrder($idSalesOrder)
166
            ->endUse()
167
            ->filterByIsSuccess(true)
168
            ->findOne();
169
170
        if ($paymentBraintreeTransactionStatusLogEntity === null) {
171
            return null;
172
        }
173
174
        return $this->getFactory()
175
            ->createBraintreePersistenceMapper()
176
            ->mapEntityToPaymentBraintreeTransactionStatusLogTransfer($paymentBraintreeTransactionStatusLogEntity, new PaymentBraintreeTransactionStatusLogTransfer());
177
    }
178
179
    /**
180
     * @param int $idSalesOrderItem
181
     *
182
     * @return \Generated\Shared\Transfer\PaymentBraintreeTransactionStatusLogTransfer|null
183
     */
184
    public function findPaymentBraintreeTransactionStatusLogQueryByOrderItem(
185
        int $idSalesOrderItem
186
    ): ?PaymentBraintreeTransactionStatusLogTransfer {
187
        $paymentBraintreeTransactionStatusLogEntity = $this->getFactory()
188
            ->createPaymentBraintreeTransactionStatusLogQuery()
189
            ->filterByFkPaymentBraintreeOrderItem($idSalesOrderItem)
190
            ->findOne();
191
192
        if ($paymentBraintreeTransactionStatusLogEntity === null) {
193
            return null;
194
        }
195
196
        return $this->getFactory()
197
            ->createBraintreePersistenceMapper()
198
            ->mapEntityToPaymentBraintreeTransactionStatusLogTransfer($paymentBraintreeTransactionStatusLogEntity, new PaymentBraintreeTransactionStatusLogTransfer());
199
    }
200
201
    /**
202
     * @param int $idPaymentBraintree
203
     *
204
     * @return \Generated\Shared\Transfer\PaymentBraintreeTransactionRequestLogTransfer|null
205
     */
206
    public function findTransactionRequestLogByPaymentBraintreeId(int $idPaymentBraintree): ?PaymentBraintreeTransactionRequestLogTransfer
207
    {
208
        $paymentBraintreeTransactionRequestLogEntity = $this->getFactory()
209
            ->createPaymentBraintreeTransactionRequestLogQuery()
210
            ->findOneByFkPaymentBraintree($idPaymentBraintree);
211
212
        if ($paymentBraintreeTransactionRequestLogEntity === null) {
213
            return null;
214
        }
215
216
        return $this->getFactory()
217
            ->createBraintreePersistenceMapper()
218
            ->mapEntityToPaymentBraintreeTransactionRequestLogTransfer($paymentBraintreeTransactionRequestLogEntity, new PaymentBraintreeTransactionRequestLogTransfer());
219
    }
220
}
221