| Conditions | 10 |
| Paths | 8 |
| Total Lines | 39 |
| Code Lines | 22 |
| Lines | 3 |
| Ratio | 7.69 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 1 |
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 |
||
| 35 | public function generate(Metrics $metrics) |
||
| 36 | { |
||
| 37 | if ($this->config->has('quiet')) { |
||
| 38 | return; |
||
| 39 | } |
||
| 40 | |||
| 41 | |||
| 42 | $logFile = $this->config->get('report-csv'); |
||
| 43 | if (!$logFile) { |
||
| 44 | return; |
||
| 45 | } |
||
| 46 | View Code Duplication | if (!file_exists(dirname($logFile)) || !is_writable(dirname($logFile))) { |
|
| 47 | throw new \RuntimeException('You don\'t have permissions to write CSV report in ' . $logFile); |
||
| 48 | } |
||
| 49 | |||
| 50 | $availables = (new Registry())->allForStructures(); |
||
| 51 | $hwnd = fopen($logFile, 'w'); |
||
| 52 | fputcsv($hwnd, $availables); |
||
| 53 | |||
| 54 | foreach ($metrics->all() as $metric) { |
||
| 55 | |||
| 56 | if (!$metric instanceof ClassMetric) { |
||
| 57 | continue; |
||
| 58 | } |
||
| 59 | $row = []; |
||
| 60 | foreach ($availables as $key) { |
||
| 61 | $data = $metric->get($key); |
||
| 62 | if (is_array($data) || !is_scalar($data)) { |
||
| 63 | $data = 'N/A'; |
||
| 64 | } |
||
| 65 | |||
| 66 | array_push($row, $data); |
||
| 67 | } |
||
| 68 | fputcsv($hwnd, $row); |
||
| 69 | } |
||
| 70 | |||
| 71 | fclose($hwnd); |
||
| 72 | |||
| 73 | } |
||
| 74 | } |
||
| 75 |
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..