1 | <?php |
||
23 | class GuzzleClient extends BaseClient implements ClientInterface |
||
24 | { |
||
25 | /** |
||
26 | * @var string |
||
27 | */ |
||
28 | protected $bearerToken = ''; |
||
29 | |||
30 | /** |
||
31 | * @var ApiExceptionTransformerInterface |
||
32 | */ |
||
33 | protected $apiExceptionTransformer; |
||
34 | |||
35 | /** |
||
36 | * Client constructor. |
||
37 | * |
||
38 | * @param ApiExceptionTransformerInterface $apiExceptionTransformer |
||
39 | * @param array $config |
||
40 | */ |
||
41 | 4 | public function __construct(ApiExceptionTransformerInterface $apiExceptionTransformer, array $config = []) |
|
46 | |||
47 | /** |
||
48 | * @return string |
||
49 | */ |
||
50 | 2 | public function getBearerToken() |
|
54 | |||
55 | /** |
||
56 | * @param string $bearerToken |
||
57 | * |
||
58 | * @return $this |
||
59 | * @throws \InvalidArgumentException |
||
60 | */ |
||
61 | 2 | public function setBearerToken($bearerToken) |
|
62 | { |
||
63 | 2 | if (is_string($bearerToken) === false) { |
|
64 | 1 | throw new \InvalidArgumentException('Bearer Token should be a string!'); |
|
65 | 1 | } |
|
66 | 1 | $this->bearerToken = $bearerToken; |
|
67 | |||
68 | 1 | return $this; |
|
69 | } |
||
70 | |||
71 | /** |
||
72 | * @param string $requestMethod |
||
73 | * @param string $path |
||
74 | * @param array $params |
||
75 | * |
||
76 | * @return ResponseInterface |
||
77 | * @throws \InvalidArgumentException |
||
78 | * @throws \Exception|ApiException |
||
79 | */ |
||
80 | public function executeRequestForParams($requestMethod, $path, array $params) |
||
86 | |||
87 | /** |
||
88 | * @param string $requestMethod |
||
89 | * @param array $params |
||
90 | * |
||
91 | * @return array |
||
1 ignored issue
–
show
|
|||
92 | * @throws \InvalidArgumentException |
||
93 | */ |
||
94 | protected function calculateOptionsForParams($requestMethod, array $params) |
||
95 | { |
||
96 | $requestMethod = strtoupper($requestMethod); |
||
97 | $options = []; |
||
98 | |||
99 | switch ($requestMethod) { |
||
100 | case RequestMethodEnum::GET: |
||
101 | if (count($params) > 0) { |
||
102 | $options['query'] = $params; |
||
103 | } |
||
104 | break; |
||
105 | case RequestMethodEnum::PUT: |
||
106 | case RequestMethodEnum::POST: |
||
107 | if (count($params) > 0) { |
||
108 | $options['json'] = $params; |
||
109 | } |
||
110 | break; |
||
111 | case RequestMethodEnum::DELETE: |
||
112 | break; |
||
113 | default: |
||
114 | throw new \InvalidArgumentException(); |
||
115 | } |
||
116 | $options['headers'] = [ |
||
117 | 'Content-Type' => 'application/json', |
||
118 | 'Authorization' => sprintf('Bearer %s', $this->bearerToken), |
||
119 | ]; |
||
120 | |||
121 | return $options; |
||
122 | } |
||
123 | |||
124 | /** |
||
125 | * @param \Exception $exception |
||
126 | * |
||
127 | * @return \Exception|ApiException |
||
128 | */ |
||
129 | 1 | public function transformApiException(\Exception $exception) |
|
133 | } |
||
134 |
This check looks for the generic type
array
as a return type and suggests a more specific type. This type is inferred from the actual code.