| Conditions | 2 |
| Paths | 2 |
| Total Lines | 35 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 58 | public function search(string $query): int |
||
| 59 | { |
||
| 60 | $queryParameters = |
||
| 61 | [ |
||
| 62 | 'q' => $query, |
||
| 63 | 'start' => 0, |
||
| 64 | 'limit' => 1, |
||
| 65 | ]; |
||
| 66 | |||
| 67 | $queryParameters += $this->queryParameters; |
||
| 68 | |||
| 69 | $queryParameters = http_build_query($queryParameters); |
||
| 70 | |||
| 71 | $headers = []; |
||
| 72 | |||
| 73 | if ($this->apiKey) { |
||
|
|
|||
| 74 | $headers['X-Api-Key'] = $this->apiKey; |
||
| 75 | } |
||
| 76 | |||
| 77 | $url = $this->searchLocation->withQuery($queryParameters); |
||
| 78 | |||
| 79 | $request = new Request( |
||
| 80 | 'GET', |
||
| 81 | (string) $url, |
||
| 82 | $headers |
||
| 83 | ); |
||
| 84 | |||
| 85 | $response = $this->httpClient->sendRequest($request); |
||
| 86 | |||
| 87 | $decodedResponse = json_decode( |
||
| 88 | $response->getBody()->getContents() |
||
| 89 | ); |
||
| 90 | |||
| 91 | return (int) $decodedResponse->{'totalItems'}; |
||
| 92 | } |
||
| 93 | } |
||
| 94 |
In PHP, under loose comparison (like
==, or!=, orswitchconditions), values of different types might be equal.For
stringvalues, the empty string''is a special case, in particular the following results might be unexpected: