FirstDataApiLogger   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 70
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 21
c 1
b 0
f 0
dl 0
loc 70
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A logApiCall() 0 14 1
A executeSavePaymentFirstDataApiLogTransaction() 0 12 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\FirstData\Business\Api\Logger;
9
10
use Generated\Shared\Transfer\FirstDataApiResponseTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...DataApiResponseTransfer 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 Generated\Shared\Transfer\FirstDataHttpRequestTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...DataHttpRequestTransfer 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 Generated\Shared\Transfer\PaymentFirstDataApiLogTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...FirstDataApiLogTransfer 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...
13
use Spryker\Zed\Kernel\Persistence\EntityManager\TransactionTrait;
14
use SprykerEco\Zed\FirstData\Dependency\Service\FirstDataToUtilEncodingServiceInterface;
15
use SprykerEco\Zed\FirstData\Persistence\FirstDataEntityManagerInterface;
16
17
class FirstDataApiLogger implements FirstDataApiLoggerInterface
18
{
19
    use TransactionTrait;
20
21
    /**
22
     * @var \SprykerEco\Zed\FirstData\Persistence\FirstDataEntityManagerInterface
23
     */
24
    protected $firstDataEntityManager;
25
26
    /**
27
     * @var \SprykerEco\Zed\FirstData\Dependency\Service\FirstDataToUtilEncodingServiceInterface
28
     */
29
    protected $utilEncodingService;
30
31
    /**
32
     * @param \SprykerEco\Zed\FirstData\Persistence\FirstDataEntityManagerInterface $firstDataEntityManager
33
     * @param \SprykerEco\Zed\FirstData\Dependency\Service\FirstDataToUtilEncodingServiceInterface $utilEncodingService
34
     */
35
    public function __construct(
36
        FirstDataEntityManagerInterface $firstDataEntityManager,
37
        FirstDataToUtilEncodingServiceInterface $utilEncodingService
38
    ) {
39
        $this->firstDataEntityManager = $firstDataEntityManager;
40
        $this->utilEncodingService = $utilEncodingService;
41
    }
42
43
    /**
44
     * @param \Generated\Shared\Transfer\FirstDataHttpRequestTransfer $firstDataHttpRequestTransfer
45
     * @param \Generated\Shared\Transfer\FirstDataApiResponseTransfer $firstDataApiResponseTransfer
46
     * @param string|null $requestType
47
     *
48
     * @return void
49
     */
50
    public function logApiCall(
51
        FirstDataHttpRequestTransfer $firstDataHttpRequestTransfer,
52
        FirstDataApiResponseTransfer $firstDataApiResponseTransfer,
53
        ?string $requestType
54
    ): void {
55
        $this->getTransactionHandler()->handleTransaction(function () use (
56
            $firstDataHttpRequestTransfer,
57
            $firstDataApiResponseTransfer,
58
            $requestType
59
        ): void {
60
            $this->executeSavePaymentFirstDataApiLogTransaction(
61
                $firstDataHttpRequestTransfer,
62
                $firstDataApiResponseTransfer,
63
                $requestType
64
            );
65
        });
66
    }
67
68
    /**
69
     * @param \Generated\Shared\Transfer\FirstDataHttpRequestTransfer $firstDataHttpRequestTransfer
70
     * @param \Generated\Shared\Transfer\FirstDataApiResponseTransfer $firstDataApiResponseTransfer
71
     * @param string|null $requestType
72
     *
73
     * @return void
74
     */
75
    protected function executeSavePaymentFirstDataApiLogTransaction(
76
        FirstDataHttpRequestTransfer $firstDataHttpRequestTransfer,
77
        FirstDataApiResponseTransfer $firstDataApiResponseTransfer,
78
        ?string $requestType
79
    ): void {
80
        $paymentFirstDataApiLogTransfer = new PaymentFirstDataApiLogTransfer();
81
        $paymentFirstDataApiLogTransfer->setRequest($this->utilEncodingService->encodeJson($firstDataHttpRequestTransfer->toArray()));
82
        $paymentFirstDataApiLogTransfer->setResponse($this->utilEncodingService->encodeJson($firstDataApiResponseTransfer->toArray()));
83
        $paymentFirstDataApiLogTransfer->setType($requestType);
84
        $paymentFirstDataApiLogTransfer->setIsSuccess($firstDataApiResponseTransfer->getIsSuccess());
85
86
        $this->firstDataEntityManager->savePaymentFirstDataApiLog($paymentFirstDataApiLogTransfer);
87
    }
88
}
89