Conditions | 9 |
Paths | 20 |
Total Lines | 83 |
Code Lines | 59 |
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 |
||
75 | public function indexActionPost() |
||
76 | { |
||
77 | // Set variables |
||
78 | $response = $this->di->get("response"); |
||
79 | $request = $this->di->get("request"); |
||
80 | $service = $this->di->get("api-service"); |
||
81 | |||
82 | // Grab post variables |
||
83 | $external = false; |
||
84 | $input = $request->getPost("input"); |
||
85 | if (!$input) { |
||
86 | $external = true; |
||
87 | try { |
||
88 | $body = $this->di->get("request")->getBodyAsJson(); |
||
89 | } catch (\Exception $e) { |
||
90 | $data = [ |
||
91 | "status_code" => 404, |
||
92 | "message" => "Something went wrong, read the API-documentation", |
||
93 | "details" => "Looks like your input was empty" |
||
94 | ]; |
||
95 | return [$data]; |
||
96 | } |
||
97 | if (is_array($body)) { |
||
98 | if (!array_key_exists("input", $body)) { |
||
99 | $data = [ |
||
100 | "status_code" => 404, |
||
101 | "message" => "Something went wrong, read the API-documentation", |
||
102 | "details" => "Make sure to use the key 'input', read documentation for examples", |
||
103 | ]; |
||
104 | return [$data]; |
||
105 | } |
||
106 | } |
||
107 | $input = $body["input"]; |
||
108 | } |
||
109 | |||
110 | // If user didnt input anything |
||
111 | if ($input == "") { |
||
112 | $data = [ |
||
113 | "status_code" => 404, |
||
114 | "message" => "Something went wrong, read the API-documentation", |
||
115 | "details" => "Looks like your input was empty" |
||
116 | ]; |
||
117 | return [$data]; |
||
118 | } |
||
119 | |||
120 | // Setting up Weather |
||
121 | $weather = new Weather(); |
||
122 | $service->setServiceToLoad("openweathermap"); |
||
123 | $owmApiKey = $service->getKeyToService(); |
||
124 | $service->setServiceToLoad("ipstack"); |
||
125 | $ipsApiKey = $service->getKeyToService("ipstack"); |
||
126 | $weather->setKeyChain(array("openweathermap" => $owmApiKey, "ipstack" => $ipsApiKey)); |
||
127 | |||
128 | $filter = $weather->isIpAddress($input); |
||
129 | if ($filter) { |
||
130 | $loc = $weather->ipTrackWithGeolocation($input); |
||
131 | $location = $loc["city"] . ", " . $loc["country_code"]; |
||
132 | $weatherCurrentJSON = $weather->getWeatherCurrentFromAPI($location); |
||
133 | $weatherHistoryJSON = $weather->getWeatherHistoryFromAPI($loc["latitude"], $loc["longitude"]); |
||
134 | } else { |
||
135 | $weather->setApiKey($owmApiKey); |
||
136 | $isVerified = $weather->verifyLocation($input); |
||
137 | if ($isVerified != "404") { |
||
138 | $weatherCurrentJSON = $weather->getWeatherCurrentFromAPI($input); |
||
139 | $lon = $weatherCurrentJSON["coord"]["lon"]; |
||
140 | $lat = $weatherCurrentJSON["coord"]["lat"]; |
||
141 | $weatherHistoryJSON = $weather->getWeatherHistoryFromAPI($lat, $lon); |
||
142 | } else { |
||
143 | $data = [ |
||
144 | "status_code" => 404, |
||
145 | "message" => "Something went wrong, read the API-documentation", |
||
146 | "details" => "Looks like your search for '$input' didnt match anything" |
||
147 | ]; |
||
148 | return [$data]; |
||
149 | } |
||
150 | } |
||
151 | |||
152 | if ($weatherHistoryJSON) { |
||
153 | $dataJSON = $weather->convertToJSON($weatherCurrentJSON, $weatherHistoryJSON); |
||
154 | $_SESSION["statusCode"] = null; |
||
155 | } |
||
156 | |||
157 | return [$dataJSON]; |
||
158 | } |
||
160 |
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