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

TransactionLogger   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 12
dl 0
loc 47
rs 10
c 0
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A logTransaction() 0 14 1
A __construct() 0 3 1
A getRequestTransferEncoded() 0 3 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\Logger;
9
10
use Generated\Shared\Transfer\AfterpayApiResponseTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...rpayApiResponseTransfer 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 Spryker\Shared\Kernel\Transfer\AbstractTransfer;
13
use SprykerEco\Zed\Afterpay\Dependency\Service\AfterpayToUtilEncodingInterface;
14
15
class TransactionLogger implements TransactionLoggerInterface
16
{
17
    /**
18
     * @var \SprykerEco\Zed\Afterpay\Dependency\Service\AfterpayToUtilEncodingInterface
19
     */
20
    protected $utilEncoding;
21
22
    /**
23
     * @param \SprykerEco\Zed\Afterpay\Dependency\Service\AfterpayToUtilEncodingInterface $utilEncoding
24
     */
25
    public function __construct(AfterpayToUtilEncodingInterface $utilEncoding)
26
    {
27
        $this->utilEncoding = $utilEncoding;
28
    }
29
30
    /**
31
     * @param string $transactionType
32
     * @param string $orderReference
33
     * @param \Spryker\Shared\Kernel\Transfer\AbstractTransfer $transactionRequest
34
     * @param \Generated\Shared\Transfer\AfterpayApiResponseTransfer $transactionResponse
35
     *
36
     * @return void
37
     */
38
    public function logTransaction(
39
        string $transactionType,
40
        string $orderReference,
41
        AbstractTransfer $transactionRequest,
42
        AfterpayApiResponseTransfer $transactionResponse
43
    ): void {
44
        $transactionLog = new SpyPaymentAfterpayTransactionLog();
45
        $transactionLog
46
            ->setOrderReference($orderReference)
47
            ->setTransactionType($transactionType)
48
            ->setOutcome($transactionResponse->getOutcome())
49
            ->setRequestPayload($this->getRequestTransferEncoded($transactionRequest))
50
            ->setResponsePayload($transactionResponse->getResponsePayload())
51
            ->save();
52
    }
53
54
    /**
55
     * @param \Spryker\Shared\Kernel\Transfer\AbstractTransfer $requestTransfer
56
     *
57
     * @return string
58
     */
59
    protected function getRequestTransferEncoded(AbstractTransfer $requestTransfer): string
60
    {
61
        return $this->utilEncoding->encodeJson($requestTransfer->toArray());
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->utilEncodi...estTransfer->toArray()) could return the type null which is incompatible with the type-hinted return string. Consider adding an additional type-check to rule them out.
Loading history...
62
    }
63
}
64