Passed
Pull Request — feature/eco-2295/dev (#1)
by Aleksey
04:05 queued 02:14
created

AbstractRequest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 15
dl 0
loc 60
rs 10
c 0
b 0
f 0
wmc 4

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 DEFAULT_TIMEOUT = 45;
18
    protected const HEADER_CONTENT_TYPE_KEY = 'Content-Type';
19
    protected const HEADER_CONTENT_TYPE_VALUE = 'application/x-www-form-urlencoded';
20
21
    /**
22
     * @var \SprykerEco\Zed\CrefoPayApi\Business\Builder\Request\CrefoPayApiRequestBuilderInterface
23
     */
24
    protected $requestBuilder;
25
26
    /**
27
     * @var \SprykerEco\Zed\CrefoPayApi\CrefoPayApiConfig
28
     */
29
    protected $config;
30
31
    /**
32
     * @param \SprykerEco\Zed\CrefoPayApi\Business\Builder\Request\CrefoPayApiRequestBuilderInterface $requestBuilder
33
     * @param \SprykerEco\Zed\CrefoPayApi\CrefoPayApiConfig $config
34
     */
35
    public function __construct(
36
        CrefoPayApiRequestBuilderInterface $requestBuilder,
37
        CrefoPayApiConfig $config
38
    ) {
39
        $this->requestBuilder = $requestBuilder;
40
        $this->config = $config;
41
    }
42
43
    /**
44
     * @param \Generated\Shared\Transfer\CrefoPayApiRequestTransfer $requestTransfer
45
     *
46
     * @return array
47
     */
48
    public function getRequestOptions(CrefoPayApiRequestTransfer $requestTransfer): array
49
    {
50
        return [
51
            RequestOptions::TIMEOUT => static::DEFAULT_TIMEOUT,
52
            RequestOptions::HEADERS => $this->getHeaders(),
53
            RequestOptions::FORM_PARAMS => $this->getFormParams($requestTransfer),
54
        ];
55
    }
56
57
    /**
58
     * @return string[]
59
     */
60
    protected function getHeaders(): array
61
    {
62
        return [
63
            static::HEADER_CONTENT_TYPE_KEY => static::HEADER_CONTENT_TYPE_VALUE,
64
        ];
65
    }
66
67
    /**
68
     * @param \Generated\Shared\Transfer\CrefoPayApiRequestTransfer $requestTransfer
69
     *
70
     * @return array
71
     */
72
    protected function getFormParams(CrefoPayApiRequestTransfer $requestTransfer): array
73
    {
74
        return $this->requestBuilder->buildRequestPayload($requestTransfer);
75
    }
76
}
77