PaymentAuthorizeWriter   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 15
dl 0
loc 47
rs 10
c 0
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A save() 0 8 1
A getPaymentAuthorizeEntity() 0 10 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\AfterPay\Business\Payment\Transaction\Authorize;
9
10
use Orm\Zed\AfterPay\Persistence\SpyPaymentAfterPayAuthorization;
0 ignored issues
show
Bug introduced by
The type Orm\Zed\AfterPay\Persist...ntAfterPayAuthorization 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 SprykerEco\Zed\AfterPay\Persistence\AfterPayQueryContainerInterface;
12
13
class PaymentAuthorizeWriter implements PaymentAuthorizeWriterInterface
14
{
15
    /**
16
     * @var \SprykerEco\Zed\AfterPay\Persistence\AfterPayQueryContainerInterface
17
     */
18
    protected $afterPayQueryContainer;
19
20
    /**
21
     * @param \SprykerEco\Zed\AfterPay\Persistence\AfterPayQueryContainerInterface $afterPayQueryContainer
22
     */
23
    public function __construct(AfterPayQueryContainerInterface $afterPayQueryContainer)
24
    {
25
        $this->afterPayQueryContainer = $afterPayQueryContainer;
26
    }
27
28
    /**
29
     * @param string $orderReference
30
     * @param string|null $idReservation
31
     * @param string|null $idCheckout
32
     *
33
     * @return void
34
     */
35
    public function save(string $orderReference, ?string $idReservation = null, ?string $idCheckout = null): void
36
    {
37
        $authorizationEntity = $this->getPaymentAuthorizeEntity($orderReference);
38
        $authorizationEntity
39
            ->setOrderReference($orderReference)
40
            ->setIdReservation($idReservation)
41
            ->setIdCheckout($idCheckout)
42
            ->save();
43
    }
44
45
    /**
46
     * @param string $orderReference
47
     *
48
     * @return \Orm\Zed\AfterPay\Persistence\SpyPaymentAfterPayAuthorization
49
     */
50
    protected function getPaymentAuthorizeEntity(string $orderReference): SpyPaymentAfterPayAuthorization
51
    {
52
        $existingEntity = $this->afterPayQueryContainer
53
            ->queryAuthorizationByOrderReference($orderReference)
54
            ->findOne();
55
        if (!$existingEntity) {
56
            $existingEntity = new SpyPaymentAfterPayAuthorization();
57
        }
58
59
        return $existingEntity;
60
    }
61
}
62