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\Builder\Request; |
9
|
|
|
|
10
|
|
|
use ArrayObject; |
11
|
|
|
use Generated\Shared\Transfer\CrefoPayApiRequestTransfer; |
|
|
|
|
12
|
|
|
use SprykerEco\Service\CrefoPayApi\CrefoPayApiServiceInterface; |
13
|
|
|
use SprykerEco\Zed\CrefoPayApi\Business\Validator\Request\CrefoPayApiRequestValidatorInterface; |
14
|
|
|
use SprykerEco\Zed\CrefoPayApi\Dependency\Service\CrefoPayApiToUtilEncodingServiceInterface; |
15
|
|
|
|
16
|
|
|
abstract class AbstractRequestBuilder implements CrefoPayApiRequestBuilderInterface |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* @var \SprykerEco\Zed\CrefoPayApi\Business\Validator\Request\CrefoPayApiRequestValidatorInterface |
20
|
|
|
*/ |
21
|
|
|
protected $validator; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @var \SprykerEco\Zed\CrefoPayApi\Dependency\Service\CrefoPayApiToUtilEncodingServiceInterface |
25
|
|
|
*/ |
26
|
|
|
protected $encodingService; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @var \SprykerEco\Service\CrefoPayApi\CrefoPayApiServiceInterface |
30
|
|
|
*/ |
31
|
|
|
protected $service; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @param \Generated\Shared\Transfer\CrefoPayApiRequestTransfer $requestTransfer |
35
|
|
|
* |
36
|
|
|
* @return array |
37
|
|
|
*/ |
38
|
|
|
abstract protected function convertRequestTransferToArray(CrefoPayApiRequestTransfer $requestTransfer): array; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @param \SprykerEco\Zed\CrefoPayApi\Business\Validator\Request\CrefoPayApiRequestValidatorInterface $validator |
42
|
|
|
* @param \SprykerEco\Zed\CrefoPayApi\Dependency\Service\CrefoPayApiToUtilEncodingServiceInterface $encodingService |
43
|
|
|
* @param \SprykerEco\Service\CrefoPayApi\CrefoPayApiServiceInterface $service |
44
|
|
|
*/ |
45
|
|
|
public function __construct( |
46
|
|
|
CrefoPayApiRequestValidatorInterface $validator, |
47
|
|
|
CrefoPayApiToUtilEncodingServiceInterface $encodingService, |
48
|
|
|
CrefoPayApiServiceInterface $service |
49
|
|
|
) { |
50
|
|
|
$this->validator = $validator; |
51
|
|
|
$this->encodingService = $encodingService; |
52
|
|
|
$this->service = $service; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @param \Generated\Shared\Transfer\CrefoPayApiRequestTransfer $requestTransfer |
57
|
|
|
* |
58
|
|
|
* @return array |
59
|
|
|
*/ |
60
|
|
|
public function buildRequestPayload(CrefoPayApiRequestTransfer $requestTransfer): array |
61
|
|
|
{ |
62
|
|
|
$this->validator->validate($requestTransfer); |
63
|
|
|
$requestPayload = $this->convertRequestTransferToArray($requestTransfer); |
64
|
|
|
$requestPayload = $this->removeRedundantParams($requestPayload); |
65
|
|
|
$requestPayload = $this->convertNestedArrayToJson($requestPayload); |
66
|
|
|
$requestPayload['mac'] = $this->service->calculateMac($requestPayload); |
67
|
|
|
|
68
|
|
|
return $requestPayload; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @param array $data |
73
|
|
|
* |
74
|
|
|
* @return array |
75
|
|
|
*/ |
76
|
|
|
protected function removeRedundantParams(array $data): array |
77
|
|
|
{ |
78
|
|
|
$data = array_filter($data, function ($item) { |
79
|
|
|
if ($item instanceof ArrayObject) { |
80
|
|
|
return $item->count() !== 0; |
81
|
|
|
} |
82
|
|
|
return $item !== null; |
83
|
|
|
}); |
84
|
|
|
|
85
|
|
|
foreach ($data as $key => $value) { |
86
|
|
|
if (is_array($value) || $value instanceof ArrayObject) { |
87
|
|
|
$data[$key] = $this->removeRedundantParams($value); |
|
|
|
|
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
return $data; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* @param array $data |
96
|
|
|
* |
97
|
|
|
* @return array |
98
|
|
|
*/ |
99
|
|
|
protected function convertNestedArrayToJson(array $data): array |
100
|
|
|
{ |
101
|
|
|
foreach ($data as $key => $value) { |
102
|
|
|
if (is_array($value) || $value instanceof ArrayObject) { |
103
|
|
|
$data[$key] = $this->encodingService->encodeJson($value); |
104
|
|
|
} |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
return $data; |
108
|
|
|
} |
109
|
|
|
} |
110
|
|
|
|
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:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths