Passed
Pull Request — master (#13)
by Oleksandr
20:56 queued 15:27
created

addOrderItemsToTransactionLog()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 20
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 15
nc 4
nop 3
dl 0
loc 20
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\Braintree\Persistence;
9
10
use Orm\Zed\Braintree\Persistence\SpyPaymentBraintreeTransactionOrderItem;
0 ignored issues
show
Bug introduced by
The type Orm\Zed\Braintree\Persis...reeTransactionOrderItem 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 Spryker\Zed\Kernel\Persistence\AbstractEntityManager;
12
13
/**
14
 * @method \SprykerEco\Zed\Braintree\Persistence\BraintreePersistenceFactory getFactory()
15
 */
16
class BraintreeEntityManager extends AbstractEntityManager implements BraintreeEntityManagerInterface
17
{
18
    /**
19
     * @param int $idPaymentBraintree
20
     * @param bool $isShipmentPaid
21
     *
22
     * @return void
23
     */
24
    public function updateIsShipmentPaidValue(int $idPaymentBraintree, bool $isShipmentPaid): void
25
    {
26
        $paymentBraintreeEntity = $this->getFactory()->createPaymentBraintreeQuery()->findOneByIdPaymentBraintree($idPaymentBraintree);
27
28
        if ($paymentBraintreeEntity) {
29
            $paymentBraintreeEntity->setIsShipmentPaid($isShipmentPaid);
30
            $paymentBraintreeEntity->save();
31
        }
32
    }
33
34
    /**
35
     * @param int $idPaymentBraintree
36
     * @param \Generated\Shared\Transfer\ItemTransfer[] $itemTransfers
37
     * @param string $transactionId
38
     *
39
     * @return void
40
     */
41
    public function addOrderItemsToTransactionLog(int $idPaymentBraintree, iterable $itemTransfers, string $transactionId): void
42
    {
43
        $paymentBraintreeTransactionStatusLogEntity = $this->getFactory()
44
            ->createPaymentBraintreeTransactionStatusLogQuery()
45
            ->filterByTransactionId($transactionId)
46
            ->findOneByFkPaymentBraintree($idPaymentBraintree);
47
48
        if ($paymentBraintreeTransactionStatusLogEntity) {
49
            foreach ($itemTransfers as $itemTransfer) {
50
                $paymentBraintreeOrderItemEntity = $this->getFactory()
51
                    ->createPaymentBraintreeOrderItemQuery()
52
                    ->findOneByFkSalesOrderItem($itemTransfer->getIdSalesOrderItem());
53
54
                if ($paymentBraintreeOrderItemEntity) {
55
                    $paymentBraintreeTransactionOrderItemEntity = new SpyPaymentBraintreeTransactionOrderItem();
56
                    $paymentBraintreeTransactionOrderItemEntity->setFkPaymentBraintreeTransactionStatusLog(
57
                        $paymentBraintreeTransactionStatusLogEntity->getIdPaymentBraintreeTransactionStatusLog()
58
                    );
59
                    $paymentBraintreeTransactionOrderItemEntity->setFkPaymentBraintreeOrderItem($paymentBraintreeOrderItemEntity->getIdPaymentBraintreeOrderItem());
60
                    $paymentBraintreeTransactionOrderItemEntity->save();
61
                }
62
            }
63
        }
64
    }
65
66
    /**
67
     * @param int $idPaymentBraintree
68
     * @param string $transactionId
69
     * @param bool $isShipmentOperation
70
     *
71
     * @return void
72
     */
73
    public function updateIsShipmentOperationValue(int $idPaymentBraintree, string $transactionId, bool $isShipmentOperation): void
74
    {
75
        $paymentBraintreeTransactionStatusLogEntity = $this->getFactory()
76
            ->createPaymentBraintreeTransactionStatusLogQuery()
77
            ->filterByTransactionId($transactionId)
78
            ->findOneByFkPaymentBraintree($idPaymentBraintree);
79
80
        if ($paymentBraintreeTransactionStatusLogEntity) {
81
            $paymentBraintreeTransactionStatusLogEntity->setIsShipmentOperation($isShipmentOperation);
82
            $paymentBraintreeTransactionStatusLogEntity->save();
83
        }
84
    }
85
}
86