1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @author Fabian Hanisch |
4
|
|
|
* @since 14.07.2017 23:08 |
5
|
|
|
* @version 1.0 |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace HanischIt\KrakenApi\Service\RequestService; |
9
|
|
|
|
10
|
|
|
use HanischIt\KrakenApi\Enum\RequestMethodEnum; |
11
|
|
|
use HanischIt\KrakenApi\Enum\VisibilityEnum; |
12
|
|
|
use HanischIt\KrakenApi\Exception\ApiException; |
13
|
|
|
use HanischIt\KrakenApi\Model\AbstractRequest; |
14
|
|
|
use HanischIt\KrakenApi\Model\Header; |
15
|
|
|
use HanischIt\KrakenApi\Model\RequestInterface; |
|
|
|
|
16
|
|
|
use HanischIt\KrakenApi\Model\RequestOptions; |
17
|
|
|
use HanischIt\KrakenApi\Model\Response; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Class AbstractRequest |
21
|
|
|
* |
22
|
|
|
* @package HanischIt\KrakenApi\Service\RequestService |
23
|
|
|
*/ |
24
|
|
|
class Request implements RequestServiceInterface |
25
|
|
|
{ |
26
|
|
|
/** |
27
|
|
|
* @var PostRequest |
28
|
|
|
*/ |
29
|
|
|
private $postRequest; |
30
|
|
|
/** |
31
|
|
|
* @var GetRequest |
32
|
|
|
*/ |
33
|
|
|
private $getRequest; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* AbstractRequest constructor. |
37
|
|
|
* |
38
|
|
|
* @param PostRequest $postRequest |
39
|
|
|
* @param GetRequest $getRequest |
40
|
|
|
*/ |
41
|
19 |
|
public function __construct(PostRequest $postRequest, GetRequest $getRequest) |
42
|
|
|
{ |
43
|
19 |
|
$this->postRequest = $postRequest; |
44
|
19 |
|
$this->getRequest = $getRequest; |
45
|
19 |
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @param AbstractRequest $request |
49
|
|
|
* @param RequestOptions $requestOptions |
50
|
|
|
* @param Header $header |
51
|
|
|
* |
52
|
|
|
* @return Response |
53
|
|
|
*/ |
54
|
5 |
|
public function execute(AbstractRequest $request, RequestOptions $requestOptions, Header $header) |
55
|
|
|
{ |
56
|
5 |
|
$method = $request->getVisibility() == VisibilityEnum::VISIBILITY_PRIVATE ? RequestMethodEnum::REQUEST_METHOD_POST : RequestMethodEnum::REQUEST_METHOD_GET; |
57
|
|
|
|
58
|
5 |
|
if ($method === RequestMethodEnum::REQUEST_METHOD_POST) { |
59
|
2 |
|
$response = $this->postRequest->execute($request, $requestOptions, $header); |
60
|
2 |
|
} else { |
61
|
3 |
|
$response = $this->getRequest->execute($request, $requestOptions); |
62
|
|
|
} |
63
|
|
|
|
64
|
5 |
|
$responseClass = $request->getResponseClassName(); |
65
|
5 |
|
$result = json_decode($response->getBody(), true); |
|
|
|
|
66
|
5 |
|
$this->handleError($result); |
67
|
4 |
|
$responseObject = new $responseClass(); |
68
|
4 |
|
if (isset($result["result"])) { |
69
|
4 |
|
if (method_exists($responseObject, "manualMapping")) { |
70
|
4 |
|
$responseObject->manualMapping($result["result"]); |
71
|
4 |
|
} else { |
72
|
|
|
foreach ($result["result"] as $key => $val) { |
73
|
|
|
$methodName = "set" . ucfirst($key); |
74
|
|
|
$responseObject->$methodName($val); |
75
|
|
|
} |
76
|
|
|
} |
77
|
4 |
|
} |
78
|
|
|
|
79
|
4 |
|
return $responseObject; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @param array $result |
84
|
|
|
* @throws ApiException |
85
|
|
|
*/ |
86
|
5 |
|
private function handleError($result) |
87
|
|
|
{ |
88
|
5 |
|
if (isset($result["error"]) && !empty($result["error"])) { |
89
|
1 |
|
throw new ApiException($result["error"]); |
90
|
|
|
} |
91
|
4 |
|
} |
92
|
|
|
} |
93
|
|
|
|
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