| Conditions | 4 |
| Paths | 4 |
| Total Lines | 57 |
| Code Lines | 38 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 93 | public function indexActionPost() : object |
||
| 94 | { |
||
| 95 | // Set variables |
||
| 96 | $response = $this->di->get("response"); |
||
| 97 | $request = $this->di->get("request"); |
||
| 98 | $service = $this->di->get("api-service"); |
||
| 99 | |||
| 100 | // Grab post variables |
||
| 101 | $input = $request->getPost("input"); |
||
| 102 | |||
| 103 | // If user didnt input anything, redirect back. |
||
| 104 | if ($input == "") { |
||
| 105 | $data = [ |
||
| 106 | "cod" => 404, |
||
| 107 | ]; |
||
| 108 | $_SESSION["weatherCurrentJSON"] = $data; |
||
| 109 | return $response->redirect("weather"); |
||
| 110 | } |
||
| 111 | |||
| 112 | // Setting up Weather |
||
| 113 | $weather = new Weather(); |
||
| 114 | $service->setServiceToLoad("openweathermap"); |
||
| 115 | $owmApiKey = $service->getKeyToService(); |
||
| 116 | $service->setServiceToLoad("ipstack"); |
||
| 117 | $ipsApiKey = $service->getKeyToService("ipstack"); |
||
| 118 | $weather->setKeyChain(array("openweathermap" => $owmApiKey, "ipstack" => $ipsApiKey)); |
||
| 119 | |||
| 120 | $filter = $weather->isIpAddress($input); |
||
| 121 | if ($filter) { |
||
| 122 | $loc = $weather->ipTrackWithGeolocation($input); |
||
| 123 | $location = $loc["city"] . ", " . $loc["country_code"]; |
||
| 124 | $weatherCurrentJSON = $weather->getWeatherCurrentFromAPI($location); |
||
| 125 | $weatherHistoryJSON = $weather->getWeatherHistoryFromAPI($loc["latitude"], $loc["longitude"]); |
||
| 126 | } else { |
||
| 127 | $weather->setApiKey($owmApiKey); |
||
| 128 | $isVerified = $weather->verifyLocation($input); |
||
| 129 | if ($isVerified != "404") { |
||
| 130 | $weatherCurrentJSON = $weather->getWeatherCurrentFromAPI($input); |
||
| 131 | $lon = $weatherCurrentJSON["coord"]["lon"]; |
||
| 132 | $lat = $weatherCurrentJSON["coord"]["lat"]; |
||
| 133 | $weatherHistoryJSON = $weather->getWeatherHistoryFromAPI($lat, $lon); |
||
| 134 | } else { |
||
| 135 | $data = [ |
||
| 136 | "cod" => 404, |
||
| 137 | ]; |
||
| 138 | $_SESSION["weatherCurrentJSON"] = $data; |
||
| 139 | $_SESSION["weatherHistoryJSON"] = null; |
||
| 140 | return $response->redirect("weather"); |
||
| 141 | } |
||
| 142 | } |
||
| 143 | |||
| 144 | // Set session variables |
||
| 145 | $_SESSION["weatherCurrentJSON"] = $weatherCurrentJSON; |
||
| 146 | $_SESSION["weatherHistoryJSON"] = $weatherHistoryJSON; |
||
| 147 | |||
| 148 | // Return di->response object to redirect to ip-geo-locator. |
||
| 149 | return $response->redirect("weather"); |
||
| 150 | } |
||
| 152 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths