1 | <?php |
||
15 | class NominatimClient |
||
16 | { |
||
17 | |||
18 | /** |
||
19 | * Base URL |
||
20 | */ |
||
21 | const BASE_URI = 'http://nominatim.openstreetmap.org'; |
||
22 | |||
23 | /** |
||
24 | * @var GuzzleClient |
||
25 | */ |
||
26 | private $guzzleClient; |
||
27 | |||
28 | /** |
||
29 | * NominatimClient constructor. |
||
30 | * @param array $config |
||
31 | */ |
||
32 | 4 | public function __construct(array $config = []) |
|
49 | |||
50 | /** |
||
51 | * Reverse action |
||
52 | * |
||
53 | * @param $latitude |
||
54 | * @param $longitude |
||
55 | * |
||
56 | * @return \Psr\Http\Message\ResponseInterface |
||
57 | */ |
||
58 | 3 | public function reverse($latitude, $longitude) |
|
86 | |||
87 | /** |
||
88 | * Validate is latitude |
||
89 | * |
||
90 | * @param $value |
||
91 | * |
||
92 | * @return int |
||
93 | */ |
||
94 | 3 | private function isLatitude($value) |
|
98 | |||
99 | /** |
||
100 | * Validate is longitude |
||
101 | * |
||
102 | * @param $value |
||
103 | * |
||
104 | * @return int |
||
105 | */ |
||
106 | 1 | private function isLongitude($value) |
|
113 | |||
114 | /** |
||
115 | * Get Guzzle Client |
||
116 | * |
||
117 | * @return GuzzleClient |
||
118 | */ |
||
119 | 2 | public function getGuzzleClient() |
|
123 | |||
124 | } |
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.