Passed
Push — feature/eco-574/eco-2266-check... ( efd21d )
by Aleksey
08:13
created

TransactionLogReader   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 18
dl 0
loc 62
rs 10
c 0
b 0
f 0
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A findOrderAuthorizeTransactionLogByIdSalesOrder() 0 9 2
A findOrderAuthorizeTransactionEntity() 0 11 1
A __construct() 0 3 1
A buildTransactionTransfer() 0 6 1
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;
9
10
use Generated\Shared\Transfer\AfterpayTransactionLogTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...yTransactionLogTransfer 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\Afterpay\Persistence\SpyPaymentAfterpayTransactionLog;
0 ignored issues
show
Bug introduced by
The type Orm\Zed\Afterpay\Persist...tAfterpayTransactionLog 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 SprykerEco\Shared\Afterpay\AfterpayConfig;
13
use SprykerEco\Shared\Afterpay\AfterpayConstants;
14
use SprykerEco\Zed\Afterpay\Persistence\AfterpayQueryContainerInterface;
15
16
class TransactionLogReader implements TransactionLogReaderInterface
17
{
18
    public const TRANSACTION_TYPE_AUTHORIZE = AfterpayConfig::TRANSACTION_TYPE_AUTHORIZE;
19
20
    /**
21
     * @var \SprykerEco\Zed\Afterpay\Persistence\AfterpayQueryContainerInterface
22
     */
23
    protected $queryContainer;
24
25
    /**
26
     * @param \SprykerEco\Zed\Afterpay\Persistence\AfterpayQueryContainerInterface $queryContainer
27
     */
28
    public function __construct(AfterpayQueryContainerInterface $queryContainer)
29
    {
30
        $this->queryContainer = $queryContainer;
31
    }
32
33
    /**
34
     * @param int $idSalesOrder
35
     *
36
     * @return \Generated\Shared\Transfer\AfterpayTransactionLogTransfer|null
37
     */
38
    public function findOrderAuthorizeTransactionLogByIdSalesOrder(int $idSalesOrder): ?AfterpayTransactionLogTransfer
39
    {
40
        $spyTransactionLog = $this->findOrderAuthorizeTransactionEntity($idSalesOrder);
41
42
        if ($spyTransactionLog === null) {
43
            return null;
44
        }
45
46
        return $this->buildTransactionTransfer($spyTransactionLog);
47
    }
48
49
    /**
50
     * @param int $idSalesOrder
51
     *
52
     * @return \Orm\Zed\Afterpay\Persistence\SpyPaymentAfterpayTransactionLog|null
53
     */
54
    protected function findOrderAuthorizeTransactionEntity(int $idSalesOrder): ?SpyPaymentAfterpayTransactionLog
55
    {
56
        $transactionLogEntity = $this
57
            ->queryContainer
58
            ->queryTransactionByIdSalesOrderAndType(
59
                $idSalesOrder,
60
                static::TRANSACTION_TYPE_AUTHORIZE
61
            )
62
            ->findOne();
63
64
        return $transactionLogEntity;
65
    }
66
67
    /**
68
     * @param \Orm\Zed\Afterpay\Persistence\SpyPaymentAfterpayTransactionLog $transactionLogEntry
69
     *
70
     * @return \Generated\Shared\Transfer\AfterpayTransactionLogTransfer
71
     */
72
    protected function buildTransactionTransfer(SpyPaymentAfterpayTransactionLog $transactionLogEntry): AfterpayTransactionLogTransfer
73
    {
74
        $transactionLogTransfer = new AfterpayTransactionLogTransfer();
75
        $transactionLogTransfer->fromArray($transactionLogEntry->toArray(), true);
76
77
        return $transactionLogTransfer;
78
    }
79
}
80