FirstDataResponseConverter   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A convertToResponseTransfer() 0 18 2
A __construct() 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\FirstData\Business\Api\Response\Converter;
9
10
use Generated\Shared\Transfer\FirstDataApiClientResponseTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...iClientResponseTransfer 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\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...
12
use SprykerEco\Zed\FirstData\Dependency\External\Guzzle\Response\FirstDataGuzzleResponseInterface;
13
use SprykerEco\Zed\FirstData\Dependency\Service\FirstDataToUtilEncodingServiceInterface;
14
15
class FirstDataResponseConverter implements FirstDataResponseConverterInterface
16
{
17
    /**
18
     * @var \SprykerEco\Zed\FirstData\Dependency\Service\FirstDataToUtilEncodingServiceInterface
19
     */
20
    protected $utilEncodingService;
21
22
    /**
23
     * @param \SprykerEco\Zed\FirstData\Dependency\Service\FirstDataToUtilEncodingServiceInterface $utilEncodingService
24
     */
25
    public function __construct(FirstDataToUtilEncodingServiceInterface $utilEncodingService)
26
    {
27
        $this->utilEncodingService = $utilEncodingService;
28
    }
29
30
    /**
31
     * @param \SprykerEco\Zed\FirstData\Dependency\External\Guzzle\Response\FirstDataGuzzleResponseInterface $guzzleResponse
32
     * @param bool $isSuccess
33
     *
34
     * @return \Generated\Shared\Transfer\FirstDataApiResponseTransfer
35
     */
36
    public function convertToResponseTransfer(
37
        FirstDataGuzzleResponseInterface $guzzleResponse,
38
        bool $isSuccess
39
    ): FirstDataApiResponseTransfer {
40
        $responseData = $this->utilEncodingService->decodeJson($guzzleResponse->getResponseBody(), true) ?? [];
41
42
        $firstDataApiResponseTransfer = (new FirstDataApiResponseTransfer());
43
        $firstDataApiResponseTransfer->setIsSuccess($isSuccess);
44
45
        if (!$isSuccess) {
46
            return $firstDataApiResponseTransfer->fromArray($responseData, true);
47
        }
48
49
        $firstDataApiClientResponseTransfer = new FirstDataApiClientResponseTransfer();
50
        $firstDataApiClientResponseTransfer->fromArray($responseData, true);
51
        $firstDataApiResponseTransfer->setClientResponse($firstDataApiClientResponseTransfer);
52
53
        return $firstDataApiResponseTransfer;
54
    }
55
}
56