AbstractConverter   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Importance

Changes 2
Bugs 1 Features 0
Metric Value
eloc 13
c 2
b 1
f 0
dl 0
loc 52
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A convertToResponseTransfer() 0 14 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\AdyenApi\Business\Converter;
9
10
use Generated\Shared\Transfer\AdyenApiErrorResponseTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...piErrorResponseTransfer 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\AdyenApiResponseTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\AdyenApiResponseTransfer 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 Psr\Http\Message\ResponseInterface;
13
use SprykerEco\Zed\AdyenApi\AdyenApiConfig;
14
use SprykerEco\Zed\AdyenApi\Dependency\Service\AdyenApiToUtilEncodingServiceInterface;
15
16
abstract class AbstractConverter implements AdyenApiConverterInterface
17
{
18
    /**
19
     * @var \SprykerEco\Zed\AdyenApi\AdyenApiConfig
20
     */
21
    protected $config;
22
23
    /**
24
     * @var \SprykerEco\Zed\AdyenApi\Dependency\Service\AdyenApiToUtilEncodingServiceInterface
25
     */
26
    protected $encodingService;
27
28
    /**
29
     * @param \Generated\Shared\Transfer\AdyenApiResponseTransfer $responseTransfer
30
     * @param array $response
31
     *
32
     * @return \Generated\Shared\Transfer\AdyenApiResponseTransfer
33
     */
34
    abstract protected function updateResponseTransfer(AdyenApiResponseTransfer $responseTransfer, array $response): AdyenApiResponseTransfer;
35
36
    /**
37
     * @param \SprykerEco\Zed\AdyenApi\AdyenApiConfig $config
38
     * @param \SprykerEco\Zed\AdyenApi\Dependency\Service\AdyenApiToUtilEncodingServiceInterface $encodingService
39
     */
40
    public function __construct(
41
        AdyenApiConfig $config,
42
        AdyenApiToUtilEncodingServiceInterface $encodingService
43
    ) {
44
        $this->config = $config;
45
        $this->encodingService = $encodingService;
46
    }
47
48
    /**
49
     * @param \Psr\Http\Message\ResponseInterface $response
50
     * @param bool $isSuccess
51
     *
52
     * @return \Generated\Shared\Transfer\AdyenApiResponseTransfer
53
     */
54
    public function convertToResponseTransfer(ResponseInterface $response, $isSuccess = true): AdyenApiResponseTransfer
55
    {
56
        $responseBody = $this->encodingService->decodeJson($response->getBody(), true);
57
        $responseTransfer = new AdyenApiResponseTransfer();
58
        $responseTransfer->setIsSuccess($isSuccess);
59
60
        if ($isSuccess) {
61
            return $this->updateResponseTransfer($responseTransfer, $responseBody);
0 ignored issues
show
Bug introduced by
It seems like $responseBody can also be of type null; however, parameter $response of SprykerEco\Zed\AdyenApi\...pdateResponseTransfer() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

61
            return $this->updateResponseTransfer($responseTransfer, /** @scrutinizer ignore-type */ $responseBody);
Loading history...
62
        }
63
64
        $error = (new AdyenApiErrorResponseTransfer())->fromArray($responseBody, true);
65
        $responseTransfer->setError($error);
66
67
        return $responseTransfer;
68
    }
69
}
70