| 1 | <?php |
||||||
| 2 | |||||||
| 3 | namespace Anax\Controller; |
||||||
| 4 | |||||||
| 5 | use Anax\Commons\ContainerInjectableInterface; |
||||||
| 6 | use Anax\Commons\ContainerInjectableTrait; |
||||||
| 7 | use Anax\Controller\IpModel; |
||||||
| 8 | |||||||
| 9 | // Turn off all error reporting |
||||||
| 10 | error_reporting(0); |
||||||
| 11 | // use Anax\Route\Exception\ForbiddenException; |
||||||
| 12 | // use Anax\Route\Exception\NotFoundException; |
||||||
| 13 | // use Anax\Route\Exception\InternalErrorException; |
||||||
| 14 | |||||||
| 15 | /** |
||||||
| 16 | * A sample controller to show how a controller class can be implemented. |
||||||
| 17 | * The controller will be injected with $di if implementing the interface |
||||||
| 18 | * ContainerInjectableInterface, like this sample class does. |
||||||
| 19 | * The controller is mounted on a particular route and can then handle all |
||||||
| 20 | * requests for that mount point. |
||||||
| 21 | * |
||||||
| 22 | *@SuppressWarnings(PHPMD.TooManyPublicMethods) |
||||||
| 23 | */ |
||||||
| 24 | class WeatherController implements ContainerInjectableInterface |
||||||
| 25 | { |
||||||
| 26 | use ContainerInjectableTrait; |
||||||
| 27 | |||||||
| 28 | |||||||
| 29 | |||||||
| 30 | /** |
||||||
| 31 | * @var string $db a sample member variable that gets initialised |
||||||
| 32 | */ |
||||||
| 33 | private $model; |
||||||
| 34 | |||||||
| 35 | |||||||
| 36 | |||||||
| 37 | /** |
||||||
| 38 | * The initialize method is optional and will always be called before the |
||||||
| 39 | * target method/action. This is a convienient method where you could |
||||||
| 40 | * setup internal properties that are commonly used by several methods. |
||||||
| 41 | * |
||||||
| 42 | * @return void |
||||||
| 43 | */ |
||||||
| 44 | 1 | public function initialize() : void |
|||||
| 45 | { |
||||||
| 46 | // Use to initialise member variables. |
||||||
| 47 | 1 | $this->model = new IpModel(); |
|||||
|
0 ignored issues
–
show
|
|||||||
| 48 | 1 | } |
|||||
| 49 | |||||||
| 50 | /** |
||||||
| 51 | * This is the index method action, it handles: |
||||||
| 52 | * ANY METHOD mountpoint |
||||||
| 53 | * ANY METHOD mountpoint/ |
||||||
| 54 | * ANY METHOD mountpoint/index |
||||||
| 55 | * |
||||||
| 56 | * @return string |
||||||
| 57 | */ |
||||||
| 58 | 1 | public function indexAction() : object |
|||||
| 59 | { |
||||||
| 60 | 1 | $page = $this->di->get("page"); |
|||||
| 61 | 1 | $weather = $this->di->get("weather"); |
|||||
| 62 | 1 | $title = "ip validator with map"; |
|||||
| 63 | 1 | $request = $this->di->get("request"); |
|||||
| 64 | 1 | $ipAddress = $request->getGet("ipMap") ?? null; |
|||||
| 65 | 1 | $version = null; |
|||||
| 66 | 1 | $localIP = $this->model->local(); |
|||||
| 67 | 1 | $res = null; |
|||||
| 68 | 1 | $lat = $res["latitude"]; |
|||||
| 69 | 1 | $long = $res["longitude"]; |
|||||
| 70 | // $t = $weather->histWeather($lat, $long); |
||||||
| 71 | 1 | $country = $res["country_name"]; |
|||||
| 72 | 1 | $region = $res["region_name"]; |
|||||
| 73 | 1 | $hostname = null; |
|||||
| 74 | 1 | $check = null; |
|||||
| 75 | 1 | $answer = null; |
|||||
| 76 | 1 | $summaries = []; |
|||||
| 77 | 1 | $dates = null; |
|||||
| 78 | 1 | if ($ipAddress !== null) { |
|||||
| 79 | $type = $request->getGet("type") ?? null; |
||||||
| 80 | if (strpos($ipAddress, ":") || strpos($ipAddress, ",") == false) { |
||||||
|
0 ignored issues
–
show
|
|||||||
| 81 | $response = $this->model->ipValidate($ipAddress); |
||||||
| 82 | $check = $response[0]; |
||||||
| 83 | $hostname = $response[1]; |
||||||
| 84 | $version = $response[2]; |
||||||
| 85 | $res = $this->model->ipStack($ipAddress); |
||||||
| 86 | $lat = $res["latitude"]; |
||||||
| 87 | $long = $res["longitude"]; |
||||||
| 88 | } elseif (strpos($ipAddress, ",")) { |
||||||
| 89 | $latlong = explode(",", $ipAddress); |
||||||
| 90 | $lat = $latlong[0]; |
||||||
| 91 | $long = $latlong[1]; |
||||||
| 92 | } |
||||||
| 93 | |||||||
| 94 | $this->checkhist($answer, $type, $weather, $lat, $long, $dates, $summaries); |
||||||
| 95 | |||||||
| 96 | $country = $res["country_name"]; |
||||||
| 97 | $region = $res["region_name"]; |
||||||
| 98 | } |
||||||
| 99 | $data = [ |
||||||
| 100 | 1 | "check" => $check, |
|||||
| 101 | 1 | "hostname" => $hostname, |
|||||
| 102 | 1 | "localIP" => $localIP, |
|||||
| 103 | 1 | "type" => $version, |
|||||
| 104 | 1 | "lat" => $lat, |
|||||
| 105 | 1 | "long" => $long, |
|||||
| 106 | 1 | "country" => $country, |
|||||
| 107 | 1 | "region" => $region, |
|||||
| 108 | 1 | "tja" => $summaries, |
|||||
| 109 | 1 | "dates" => $dates, |
|||||
| 110 | 1 | "hist" => $answer |
|||||
| 111 | |||||||
| 112 | ]; |
||||||
| 113 | 1 | $page->add("weather/forms_weather", $data); |
|||||
| 114 | 1 | return $page->render([ |
|||||
| 115 | 1 | "title" => $title, |
|||||
| 116 | ]); |
||||||
| 117 | } |
||||||
| 118 | |||||||
| 119 | /** |
||||||
| 120 | * Check historik and kommande |
||||||
| 121 | */ |
||||||
| 122 | private function checkhist($answer, $type, $weather, $lat, $long, $dates, $summaries) |
||||||
|
0 ignored issues
–
show
The parameter
$answer is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. Loading history...
The parameter
$dates is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. Loading history...
|
|||||||
| 123 | { |
||||||
| 124 | if ($type == "Historik") { |
||||||
| 125 | $answer = $weather->histWeather($lat, $long); |
||||||
| 126 | if (!is_string($answer)) { |
||||||
| 127 | foreach ($answer as $day) { |
||||||
| 128 | $summaries[] = $day[0]["summary"]; |
||||||
| 129 | } |
||||||
| 130 | $dates = $weather->dates('-31 day', 30); |
||||||
|
0 ignored issues
–
show
|
|||||||
| 131 | } |
||||||
| 132 | } elseif ($type == "Kommande") { |
||||||
| 133 | $answer = $weather->newWeather($lat, $long); |
||||||
| 134 | if (!is_string($answer)) { |
||||||
| 135 | foreach ($answer as $day) { |
||||||
| 136 | $summaries[] = $day["summary"]; |
||||||
| 137 | } |
||||||
| 138 | $dates = $weather->dates(' +1 day', 7); |
||||||
| 139 | } |
||||||
| 140 | } |
||||||
| 141 | } |
||||||
| 142 | } |
||||||
| 143 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..