1 | <?php |
||
16 | class HttpClientLocationCreator |
||
17 | { |
||
18 | use LoggerAwareTrait; |
||
19 | 1 | ||
20 | /** |
||
21 | * @var ClientInterface |
||
22 | */ |
||
23 | protected $client; |
||
24 | |||
25 | |||
26 | /** |
||
27 | * @var RequestFactoryInterface |
||
28 | */ |
||
29 | public $request_factory; |
||
30 | |||
31 | |||
32 | /** |
||
33 | * Geocoder API endpoint. |
||
34 | * |
||
35 | * @var string |
||
36 | */ |
||
37 | public $api; |
||
38 | |||
39 | |||
40 | /** |
||
41 | * IP adress query parameter |
||
42 | * |
||
43 | * @var string |
||
44 | */ |
||
45 | public $ip_var_name = "ip"; |
||
46 | |||
47 | |||
48 | /** |
||
49 | * @var callable |
||
50 | */ |
||
51 | public $response_decoder; |
||
52 | |||
53 | |||
54 | /** |
||
55 | * @var mixed |
||
56 | */ |
||
57 | public $default_location; |
||
58 | |||
59 | |||
60 | /** |
||
61 | * @var string |
||
62 | */ |
||
63 | protected $error_loglevel = LogLevel::ERROR; |
||
64 | |||
65 | |||
66 | /** |
||
67 | * @var string |
||
68 | */ |
||
69 | protected $client_exception_loglevel = LogLevel::NOTICE; |
||
70 | |||
71 | |||
72 | /** |
||
73 | 2 | * @param string $api Geocoder API endpoint |
|
74 | * @param ClientInterface $client PSR-18 HTTP Client |
||
75 | 2 | * @param RequestFactoryInterface $request_factory PSR-17 Request factory |
|
76 | 2 | * @param callable|null $response_decoder Optional: PSR-7 Response decoder callable |
|
77 | 2 | */ |
|
78 | 2 | public function __construct( string $api, ClientInterface $client, RequestFactoryInterface $request_factory, callable $response_decoder = null, LoggerInterface $logger = null) |
|
86 | |||
87 | 2 | ||
88 | |||
89 | 2 | /** |
|
90 | * @param string $client_ip Client IP address |
||
91 | */ |
||
92 | 2 | public function __invoke( string $client_ip ) |
|
145 | 2 | ||
146 | |||
147 | 2 | ||
148 | 2 | /** |
|
149 | * @param string $client_ip Client IP address |
||
150 | * @return RequestInterface |
||
151 | */ |
||
152 | public function createRequest( string $client_ip ) : RequestInterface |
||
161 | 4 | ||
162 | |||
163 | |||
164 | /** |
||
165 | * @param ResponseInterface $response |
||
166 | * @return mixed |
||
167 | */ |
||
168 | public function decodeResponse(ResponseInterface $response) |
||
174 | 6 | ||
175 | |||
176 | |||
177 | /** |
||
178 | * Sets the default location to return on error |
||
179 | * |
||
180 | * @param mixed $location |
||
181 | */ |
||
182 | public function setDefaultLocation( $location ) : self |
||
187 | |||
188 | |||
189 | /** |
||
190 | * @param string $error_loglevel PSR-3 Loglevel name |
||
191 | */ |
||
192 | public function setErrorLoglevel( string $error_loglevel ) { |
||
196 | |||
197 | 4 | ||
198 | 4 | ||
199 | /** |
||
200 | * @param string $client_exception_loglevel PSR-3 Loglevel name |
||
201 | */ |
||
202 | public function setClientExceptionLoglevel( string $client_exception_loglevel ) { |
||
206 | |||
207 | |||
208 | /** |
||
209 | * Sets the API endpoint |
||
210 | * |
||
211 | * @param string $api |
||
212 | */ |
||
213 | public function setApiEndpoint( string $api ) : self |
||
218 | |||
219 | |||
220 | |||
221 | /** |
||
222 | * Sets the HTTP Client to use. |
||
223 | * |
||
224 | * @param ClientInterface $client |
||
225 | */ |
||
226 | public function setClient( ClientInterface $client ) : self |
||
231 | |||
232 | |||
233 | /** |
||
234 | * Sets the PSR-17 Request factory |
||
235 | * |
||
236 | * @param RequestFactoryInterface $request_factory |
||
237 | */ |
||
238 | public function setRequestFactory( RequestFactoryInterface $request_factory ) : self |
||
243 | |||
244 | |||
245 | /** |
||
246 | * Sets the PSR-7 Response decoder callable. |
||
247 | * |
||
248 | * @param callable $response_decoder |
||
249 | */ |
||
250 | public function setResponseDecoder( callable $response_decoder = null ) : self |
||
255 | |||
256 | } |
||
257 |
The break statement is not necessary if it is preceded for example by a return statement:
If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.