Issues (33)

src/Weather/Ipvalidate.php (1 issue)

1
<?php
2
3
namespace Osln\Weather;
4
5
use Anax\Commons\ContainerInjectableInterface;
6
use Anax\Commons\ContainerInjectableTrait;
7
8
class Ipvalidate
9
{
10 6
    public function __construct()
11
    {
12 6
        $this->config = new LoadConfig();
0 ignored issues
show
Bug Best Practice introduced by
The property config does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
13 6
    }
14 4
    public function getUrl($search)
15
    {
16 4
        $url = null;
17 4
        $key = null;
18 4
        if (filter_var($search, FILTER_VALIDATE_IP)) {
19 4
            $key = $this->config->getKey("ipstack");
20 4
            $url = "http://api.ipstack.com/%2\$s?access_key=%1\$s";
21
        } else {
22 4
            $url = "http://open.mapquestapi.com/nominatim/v1/search.php?q=%2\$s&limit=1&format=json&key=%1\$s";
23 4
            $key = $this->config->getKey("mapquest");
24
        }
25 4
        $urlFinal = sprintf($url, $key, $search);
26 4
        return $urlFinal;
27
    }
28
}
29