biscolab /
google-maps-php-sdk
| 1 | <?php |
||
| 2 | /** |
||
| 3 | * Copyright (c) 2018 - present |
||
| 4 | * Google Maps PHP - GoogleMapsRequest.php |
||
| 5 | * author: Roberto Belotti - [email protected] |
||
| 6 | * web : robertobelotti.com, github.com/biscolab |
||
| 7 | * Initial version created on: 5/9/2018 |
||
| 8 | * MIT license: https://github.com/biscolab/google-maps-php/blob/master/LICENSE |
||
| 9 | */ |
||
| 10 | |||
| 11 | namespace Biscolab\GoogleMaps\Http; |
||
| 12 | |||
| 13 | /** |
||
| 14 | * Class GoogleMapsRequest |
||
| 15 | * @package Biscolab\GoogleMaps\Http |
||
| 16 | */ |
||
| 17 | class GoogleMapsRequest |
||
| 18 | { |
||
| 19 | |||
| 20 | /** |
||
| 21 | * @var string |
||
| 22 | * @since 0.5.0 |
||
| 23 | */ |
||
| 24 | protected $endpoint = null; |
||
| 25 | |||
| 26 | /** |
||
| 27 | * @var array |
||
| 28 | */ |
||
| 29 | private $params = []; |
||
| 30 | |||
| 31 | /** |
||
| 32 | * GoogleMapsRequest constructor. |
||
| 33 | * |
||
| 34 | * @param array $params |
||
| 35 | * @param null|string $endpoint |
||
| 36 | */ |
||
| 37 | public function __construct(array $params = [], ?string $endpoint = null) |
||
| 38 | { |
||
| 39 | |||
| 40 | if ($params) { |
||
|
0 ignored issues
–
show
|
|||
| 41 | foreach ($params as $param_name => $param_value) { |
||
| 42 | $this->setParam($param_name, $param_value); |
||
| 43 | } |
||
| 44 | } |
||
| 45 | |||
| 46 | $this->endpoint = $endpoint; |
||
| 47 | } |
||
| 48 | |||
| 49 | /** |
||
| 50 | * @param string $param_name |
||
| 51 | * @param mixed $param_value |
||
| 52 | * |
||
| 53 | * @return GoogleMapsRequest |
||
| 54 | */ |
||
| 55 | public function setParam(string $param_name, $param_value): GoogleMapsRequest |
||
| 56 | { |
||
| 57 | |||
| 58 | $this->params[$param_name] = $param_value; |
||
| 59 | |||
| 60 | return $this; |
||
| 61 | } |
||
| 62 | |||
| 63 | /** |
||
| 64 | * @return string |
||
| 65 | */ |
||
| 66 | public function getQuery(): string |
||
| 67 | { |
||
| 68 | |||
| 69 | $params = []; |
||
| 70 | |||
| 71 | foreach ($this->params as $param_name => $param_value) { |
||
| 72 | $params[$param_name] = (string)$param_value; |
||
| 73 | } |
||
| 74 | |||
| 75 | return http_build_query($params); |
||
| 76 | } |
||
| 77 | |||
| 78 | /** |
||
| 79 | * @return array |
||
| 80 | */ |
||
| 81 | public function getParams(): array |
||
| 82 | { |
||
| 83 | |||
| 84 | return $this->params; |
||
| 85 | } |
||
| 86 | |||
| 87 | /** |
||
| 88 | * @return null|string |
||
| 89 | */ |
||
| 90 | public function getEndpoint(): ?string |
||
| 91 | { |
||
| 92 | |||
| 93 | return $this->endpoint; |
||
| 94 | } |
||
| 95 | |||
| 96 | } |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)or! empty(...)instead.