AdyenApiRequest   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 10 1
A request() 0 13 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\Request;
9
10
use Generated\Shared\Transfer\AdyenApiRequestTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\AdyenApiRequestTransfer 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 GuzzleHttp\Exception\RequestException;
13
use SprykerEco\Zed\AdyenApi\AdyenApiConfig;
14
use SprykerEco\Zed\AdyenApi\Business\Adapter\AdyenApiAdapterInterface;
15
use SprykerEco\Zed\AdyenApi\Business\Converter\AdyenApiConverterInterface;
16
use SprykerEco\Zed\AdyenApi\Business\Mapper\AdyenApiMapperInterface;
17
18
class AdyenApiRequest implements AdyenApiRequestInterface
19
{
20
    /**
21
     * @var \SprykerEco\Zed\AdyenApi\Business\Adapter\AdyenApiAdapterInterface
22
     */
23
    protected $adapter;
24
25
    /**
26
     * @var \SprykerEco\Zed\AdyenApi\Business\Converter\AdyenApiConverterInterface
27
     */
28
    protected $converter;
29
30
    /**
31
     * @var \SprykerEco\Zed\AdyenApi\Business\Mapper\AdyenApiMapperInterface
32
     */
33
    protected $mapper;
34
35
    /**
36
     * @var \SprykerEco\Zed\AdyenApi\AdyenApiConfig
37
     */
38
    protected $config;
39
40
    /**
41
     * @var string
42
     */
43
    protected $method;
44
45
    /**
46
     * @param \SprykerEco\Zed\AdyenApi\Business\Adapter\AdyenApiAdapterInterface $adapter
47
     * @param \SprykerEco\Zed\AdyenApi\Business\Converter\AdyenApiConverterInterface $converter
48
     * @param \SprykerEco\Zed\AdyenApi\Business\Mapper\AdyenApiMapperInterface $mapper
49
     * @param \SprykerEco\Zed\AdyenApi\AdyenApiConfig $config
50
     */
51
    public function __construct(
52
        AdyenApiAdapterInterface $adapter,
53
        AdyenApiConverterInterface $converter,
54
        AdyenApiMapperInterface $mapper,
55
        AdyenApiConfig $config
56
    ) {
57
        $this->adapter = $adapter;
58
        $this->converter = $converter;
59
        $this->mapper = $mapper;
60
        $this->config = $config;
61
    }
62
63
    /**
64
     * @param \Generated\Shared\Transfer\AdyenApiRequestTransfer $requestTransfer
65
     *
66
     * @return \Generated\Shared\Transfer\AdyenApiResponseTransfer
67
     */
68
    public function request(AdyenApiRequestTransfer $requestTransfer): AdyenApiResponseTransfer
69
    {
70
        $requestData = $this->mapper->buildRequestArray($requestTransfer);
71
        $isSuccess = true;
72
73
        try {
74
            $response = $this->adapter->sendRequest($requestData);
75
        } catch (RequestException $requestException) {
76
            $response = $requestException->getResponse();
77
            $isSuccess = false;
78
        }
79
80
        return $this->converter->convertToResponseTransfer($response, $isSuccess);
81
    }
82
}
83