Passed
Push — feature/paypal-express ( 8eac93...3cde97 )
by Volodymyr
05:19
created

addOrderItemsToTransactionLog()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 21
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

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