Conditions | 7 |
Paths | 16 |
Total Lines | 51 |
Code Lines | 34 |
Lines | 0 |
Ratio | 0 % |
Changes | 5 | ||
Bugs | 1 | 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 |
||
23 | public function handle(): int |
||
24 | { |
||
25 | $backends = $this->prepareBackends(); |
||
26 | $codeclimate = $this->getCodeClimateOutput(); |
||
27 | $allErrors = []; |
||
28 | $nScanned = 0; |
||
29 | |||
30 | if ($this->getOutput()->isVerbose()) { |
||
31 | $this->info('blade-lint: Using backends: ' . join(', ', array_map(fn (Backend $backend) => $backend->name(), $backends))); |
||
32 | } |
||
33 | |||
34 | foreach ($this->getBladeFiles() as $file) { |
||
35 | $errors = $this->checkFile($file, ...$backends); |
||
|
|||
36 | if (count($errors) > 0) { |
||
37 | $status = self::FAILURE; |
||
38 | foreach ($errors as $error) { |
||
39 | $this->error($error->toString()); |
||
40 | } |
||
41 | } elseif ($this->getOutput()->isVerbose()) { |
||
42 | $this->line("No syntax errors detected in {$file->getPathname()}"); |
||
43 | } |
||
44 | |||
45 | $allErrors = array_merge($allErrors, $errors); |
||
46 | $nScanned++; |
||
47 | } |
||
48 | |||
49 | if ($codeclimate !== null) { |
||
50 | fwrite($codeclimate, json_encode( |
||
51 | array_map(function (ErrorRecord $error) { |
||
52 | return [ |
||
53 | 'type' => 'issue', |
||
54 | 'check_name' => 'Laravel Blade Lint', |
||
55 | 'description' => $error->message, |
||
56 | 'fingerprint' => md5(join("|", [$error->message, $error->path, $error->line])), |
||
57 | 'categories' => ['Bug Risk'], |
||
58 | 'location' => [ |
||
59 | 'path' => $error->path, |
||
60 | 'lines' => [ |
||
61 | 'begin' => $error->line, |
||
62 | ], |
||
63 | ], |
||
64 | 'severity' => 'blocker' |
||
65 | ]; |
||
66 | }, $allErrors), |
||
67 | JSON_PRETTY_PRINT | JSON_THROW_ON_ERROR |
||
68 | )); |
||
69 | } |
||
70 | |||
71 | $this->info('blade-lint: scanned: ' . $nScanned . ' files'); |
||
72 | |||
73 | return $status ?? self::SUCCESS; |
||
74 | } |
||
179 |