Passed
Push — feature/eco-2295/eco-2344-crea... ( 1e5ae0...217e63 )
by Aleksey
01:02
created

AbstractRequest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 17
dl 0
loc 62
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getRequestOptions() 0 6 1
A getFormParams() 0 3 1
A getHeaders() 0 4 1
A __construct() 0 6 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\CrefoPayApi\Business\Request;
9
10
use Generated\Shared\Transfer\CrefoPayApiRequestTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...foPayApiRequestTransfer 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 GuzzleHttp\RequestOptions;
0 ignored issues
show
Bug introduced by
The type GuzzleHttp\RequestOptions 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\CrefoPayApi\Business\Builder\Request\CrefoPayApiRequestBuilderInterface;
13
use SprykerEco\Zed\CrefoPayApi\CrefoPayApiConfig;
14
15
abstract class AbstractRequest implements CrefoPayApiRequestInterface
16
{
17
    protected const METHOD_POST = 'POST';
18
    protected const METHOD_GET = 'GET';
19
    protected const DEFAULT_TIMEOUT = 45;
20
    protected const HEADER_CONTENT_TYPE_KEY = 'Content-Type';
21
    protected const HEADER_CONTENT_TYPE_VALUE = 'application/x-www-form-urlencoded';
22
23
    /**
24
     * @var \SprykerEco\Zed\CrefoPayApi\Business\Builder\Request\CrefoPayApiRequestBuilderInterface
25
     */
26
    protected $requestBuilder;
27
28
    /**
29
     * @var \SprykerEco\Zed\CrefoPayApi\CrefoPayApiConfig
30
     */
31
    protected $config;
32
33
    /**
34
     * @param \SprykerEco\Zed\CrefoPayApi\Business\Builder\Request\CrefoPayApiRequestBuilderInterface $requestBuilder
35
     * @param \SprykerEco\Zed\CrefoPayApi\CrefoPayApiConfig $config
36
     */
37
    public function __construct(
38
        CrefoPayApiRequestBuilderInterface $requestBuilder,
39
        CrefoPayApiConfig $config
40
    ) {
41
        $this->requestBuilder = $requestBuilder;
42
        $this->config = $config;
43
    }
44
45
    /**
46
     * @param \Generated\Shared\Transfer\CrefoPayApiRequestTransfer $requestTransfer
47
     *
48
     * @return array
49
     */
50
    public function getRequestOptions(CrefoPayApiRequestTransfer $requestTransfer): array
51
    {
52
        return [
53
            RequestOptions::TIMEOUT => static::DEFAULT_TIMEOUT,
54
            RequestOptions::HEADERS => $this->getHeaders(),
55
            RequestOptions::FORM_PARAMS => $this->getFormParams($requestTransfer),
56
        ];
57
    }
58
59
    /**
60
     * @return string[]
61
     */
62
    protected function getHeaders(): array
63
    {
64
        return [
65
            static::HEADER_CONTENT_TYPE_KEY => static::HEADER_CONTENT_TYPE_VALUE,
66
        ];
67
    }
68
69
    /**
70
     * @param \Generated\Shared\Transfer\CrefoPayApiRequestTransfer $requestTransfer
71
     *
72
     * @return array
73
     */
74
    protected function getFormParams(CrefoPayApiRequestTransfer $requestTransfer): array
75
    {
76
        return $this->requestBuilder->buildRequestPayload($requestTransfer);
77
    }
78
}
79