Conditions | 23 |
Paths | 297 |
Total Lines | 122 |
Code Lines | 91 |
Lines | 0 |
Ratio | 0 % |
Changes | 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 |
||
176 | public function main() |
||
177 | { |
||
178 | if (!isset($this->file) && count($this->filesets) === 0) { |
||
179 | throw new BuildException("Missing either a nested fileset or attribute 'file' set"); |
||
180 | } |
||
181 | |||
182 | if (!isset($this->file)) { |
||
183 | $fileList = []; |
||
184 | $project = $this->getProject(); |
||
185 | foreach ($this->filesets as $fs) { |
||
186 | $ds = $fs->getDirectoryScanner($project); |
||
187 | $files = $ds->getIncludedFiles(); |
||
188 | $dir = $fs->getDir($this->project)->getAbsolutePath(); |
||
189 | foreach ($files as $file) { |
||
190 | $fileList[] = $dir . DIRECTORY_SEPARATOR . $file; |
||
191 | } |
||
192 | } |
||
193 | } else { |
||
194 | $fileList = [$this->file]; |
||
195 | } |
||
196 | |||
197 | $this->checkJsHintIsInstalled(); |
||
198 | |||
199 | $fileList = array_map('escapeshellarg', $fileList); |
||
200 | if ($this->config) { |
||
201 | $command = sprintf( |
||
202 | '%s --config=%s --reporter=%s %s', |
||
203 | $this->executable, |
||
204 | $this->config, |
||
205 | $this->reporter, |
||
206 | implode(' ', $fileList) |
||
207 | ); |
||
208 | } else { |
||
209 | $command = sprintf( |
||
210 | '%s --reporter=%s %s', |
||
211 | $this->executable, |
||
212 | $this->reporter, |
||
213 | implode(' ', $fileList) |
||
214 | ); |
||
215 | } |
||
216 | $this->log('Execute: ' . PHP_EOL . $command, Project::MSG_VERBOSE); |
||
217 | $output = []; |
||
218 | exec($command, $output); |
||
219 | $output = implode(PHP_EOL, $output); |
||
220 | |||
221 | if ($this->checkstyleReportPath) { |
||
222 | file_put_contents($this->checkstyleReportPath, $output); |
||
223 | $this->log(''); |
||
224 | $this->log('Checkstyle report saved to ' . $this->checkstyleReportPath); |
||
225 | } |
||
226 | |||
227 | libxml_clear_errors(); |
||
228 | libxml_use_internal_errors(true); |
||
229 | $xml = simplexml_load_string($output, 'SimpleXMLElement', LIBXML_PARSEHUGE); |
||
230 | if (false === $xml) { |
||
231 | $errors = libxml_get_errors(); |
||
232 | if (!empty($errors)) { |
||
233 | foreach ($errors as $error) { |
||
234 | $msg = $xml[$error->line - 1] . "\n"; |
||
235 | $msg .= str_repeat('-', $error->column) . "^\n"; |
||
236 | |||
237 | switch ($error->level) { |
||
238 | case LIBXML_ERR_WARNING: |
||
239 | $msg .= 'Warning ' . $error->code . ': '; |
||
240 | break; |
||
241 | case LIBXML_ERR_ERROR: |
||
242 | $msg .= 'Error ' . $error->code . ': '; |
||
243 | break; |
||
244 | case LIBXML_ERR_FATAL: |
||
245 | $msg .= 'Fatal error ' . $error->code . ': '; |
||
246 | break; |
||
247 | } |
||
248 | $msg .= trim($error->message) . PHP_EOL . ' Line: ' . $error->line . PHP_EOL . ' Column: ' . $error->column; |
||
249 | $this->log($msg, Project::MSG_VERBOSE); |
||
250 | } |
||
251 | throw new BuildException('Unable to parse output of JSHint, use checkstyleReportPath="/path/to/report.xml" to debug'); |
||
252 | } |
||
253 | } |
||
254 | $projectBasedir = $this->getProjectBasedir(); |
||
255 | $errorsCount = 0; |
||
256 | $warningsCount = 0; |
||
257 | $fileError = $this->xmlAttributes['fileError']; |
||
258 | foreach ($xml->file as $file) { |
||
259 | $fileAttributes = $file->attributes(); |
||
|
|||
260 | $fileName = (string) $fileAttributes['name']; |
||
261 | foreach ($file->$fileError as $error) { |
||
262 | $errAttr = (array) $error->attributes(); |
||
263 | $attrs = current($errAttr); |
||
264 | |||
265 | if ($attrs['severity'] === $this->xmlAttributes['severity']['error']) { |
||
266 | $errorsCount++; |
||
267 | } elseif ($attrs['severity'] === $this->xmlAttributes['severity']['warning']) { |
||
268 | $warningsCount++; |
||
269 | } elseif ($attrs['severity'] !== $this->xmlAttributes['severity']['info']) { |
||
270 | throw new BuildException(sprintf('Unknown severity "%s"', $attrs['severity'])); |
||
271 | } |
||
272 | $e = sprintf( |
||
273 | '%s: line %d, col %d, %s', |
||
274 | str_replace($projectBasedir, '', $fileName), |
||
275 | $attrs[$this->xmlAttributes['line']], |
||
276 | $attrs[$this->xmlAttributes['column']], |
||
277 | $attrs[$this->xmlAttributes['message']] |
||
278 | ); |
||
279 | $this->log($e); |
||
280 | } |
||
281 | } |
||
282 | |||
283 | $message = sprintf( |
||
284 | 'JSHint detected %d errors and %d warnings.', |
||
285 | $errorsCount, |
||
286 | $warningsCount |
||
287 | ); |
||
288 | if ($this->haltOnError && $errorsCount) { |
||
289 | throw new BuildException($message); |
||
290 | } |
||
291 | |||
292 | if ($this->haltOnWarning && $warningsCount) { |
||
293 | throw new BuildException($message); |
||
294 | } |
||
295 | |||
296 | $this->log(''); |
||
297 | $this->log($message); |
||
298 | } |
||
323 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.