@@ -107,14 +107,15 @@ public function __construct(array $config, CacheManager $cache)
107107 * @param string $ip
108108 *
109109 * @return \Torann\GeoIP\Location
110+ * @throws \Exception
110111 */
111112 public function getLocation ($ ip = null )
112113 {
113114 // Get location data
114115 $ this ->location = $ this ->find ($ ip );
115116
116117 // Should cache location
117- if ($ this ->shouldCache ($ ip , $ this ->location )) {
118+ if ($ this ->shouldCache ($ this ->location , $ ip )) {
118119 $ this ->getCache ()->set ($ ip , $ this ->location );
119120 }
120121
@@ -148,16 +149,15 @@ private function find($ip = null)
148149 $ location = $ this ->getService ()->locate ($ ip );
149150
150151 // Set currency if not already set by the service
151- if (!$ location ->currency ) {
152+ if (! $ location ->currency ) {
152153 $ location ->currency = $ this ->getCurrency ($ location ->iso_code );
153154 }
154155
155156 // Set default
156157 $ location ->default = false ;
157158
158159 return $ location ;
159- }
160- catch (\Exception $ e ) {
160+ } catch (\Exception $ e ) {
161161 if ($ this ->config ('log_failures ' , true ) === true ) {
162162 $ log = new Logger ('geoip ' );
163163 $ log ->pushHandler (new StreamHandler (storage_path ('logs/geoip.log ' ), Logger::ERROR ));
@@ -262,8 +262,8 @@ public function getClientIP()
262262 */
263263 private function isValid ($ ip )
264264 {
265- if (!filter_var ($ ip , FILTER_VALIDATE_IP , FILTER_FLAG_IPV4 | FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE )
266- && !filter_var ($ ip , FILTER_VALIDATE_IP , FILTER_FLAG_IPV6 | FILTER_FLAG_NO_PRIV_RANGE )
265+ if (! filter_var ($ ip , FILTER_VALIDATE_IP , FILTER_FLAG_IPV4 | FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE )
266+ && ! filter_var ($ ip , FILTER_VALIDATE_IP , FILTER_FLAG_IPV6 | FILTER_FLAG_NO_PRIV_RANGE )
267267 ) {
268268 return false ;
269269 }
@@ -274,20 +274,19 @@ private function isValid($ip)
274274 /**
275275 * Determine if the location should be cached.
276276 *
277- * @param string $ip
278- * @param Location $location
277+ * @param Location $location
278+ * @param string|null $ip
279279 *
280280 * @return bool
281281 */
282- private function shouldCache ($ ip = null , Location $ location )
282+ private function shouldCache (Location $ location , $ ip = null )
283283 {
284284 if ($ location ->default === true || $ location ->cached === true ) {
285285 return false ;
286286 }
287287
288288 switch ($ this ->config ('cache ' , 'none ' )) {
289289 case 'all ' :
290- return true ;
291290 case 'some ' && $ ip === null :
292291 return true ;
293292 }
0 commit comments