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 | 15 | 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 | 12 | public function setBearerToken($bearerToken) |
|
70 | |||
71 | /** |
||
72 | * @param \Exception $exception |
||
73 | * |
||
74 | * @return \Exception|ApiException |
||
75 | */ |
||
76 | 1 | public function transformApiException(\Exception $exception) |
|
80 | |||
81 | /** |
||
82 | * @param string $requestMethod |
||
83 | * @param string $path |
||
84 | * @param array $params |
||
85 | * |
||
86 | * @return ResponseInterface |
||
87 | * @throws \InvalidArgumentException |
||
88 | * @throws \Exception|ApiException |
||
89 | */ |
||
90 | 11 | public function executeRequestForParams($requestMethod, $path, array $params) |
|
96 | |||
97 | /** |
||
98 | * @param string $requestMethod |
||
99 | * @param array $params |
||
100 | * |
||
101 | * @return array |
||
102 | * @throws \InvalidArgumentException |
||
103 | */ |
||
104 | 11 | protected function calculateOptionsForParams($requestMethod, array $params) |
|
129 | |||
130 | /** |
||
131 | * @return array |
||
132 | */ |
||
133 | 11 | protected function prepareBaseOptions() |
|
144 | } |
||
145 |
Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.
Let’s take a look at an example:
As you can see in this example, the array
$myArray
is initialized the first time when the foreach loop is entered. You can also see that the value of thebar
key is only written conditionally; thus, its value might result from a previous iteration.This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.