| Conditions | 11 |
| Paths | 385 |
| Total Lines | 117 |
| 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 |
||
| 60 | public function generate(Metrics $metrics) |
||
| 61 | { |
||
| 62 | $logDir = $this->config->get('report-html'); |
||
|
|
|||
| 63 | if (!$logDir) { |
||
| 64 | return; |
||
| 65 | } |
||
| 66 | |||
| 67 | // consolidate |
||
| 68 | |||
| 69 | /** @var Group[] $groups */ |
||
| 70 | $groups = $this->config->get('groups'); |
||
| 71 | $this->groups = $this->config->get('groups'); |
||
| 72 | $consolidatedGroups = []; |
||
| 73 | foreach ($groups as $group) { |
||
| 74 | $reducedMetricsByGroup = $group->reduceMetrics($metrics); |
||
| 75 | $consolidatedGroups[$group->getName()] = new Consolidated($reducedMetricsByGroup); |
||
| 76 | } |
||
| 77 | |||
| 78 | $consolidated = new Consolidated($metrics); |
||
| 79 | |||
| 80 | // history of builds |
||
| 81 | $today = (object)[ |
||
| 82 | 'avg' => $consolidated->getAvg(), |
||
| 83 | 'sum' => $consolidated->getSum() |
||
| 84 | ]; |
||
| 85 | $files = glob($logDir . '/js/history-*.json'); |
||
| 86 | $next = count($files) + 1; |
||
| 87 | $history = []; |
||
| 88 | natsort($files); |
||
| 89 | foreach ($files as $filename) { |
||
| 90 | array_push($history, json_decode(file_get_contents($filename))); |
||
| 91 | } |
||
| 92 | |||
| 93 | // copy sources |
||
| 94 | if (!file_exists($logDir . '/js')) { |
||
| 95 | mkdir($logDir . '/js', 0755, true); |
||
| 96 | } |
||
| 97 | if (!file_exists($logDir . '/css')) { |
||
| 98 | mkdir($logDir . '/css', 0755, true); |
||
| 99 | } |
||
| 100 | if (!file_exists($logDir . '/images')) { |
||
| 101 | mkdir($logDir . '/images', 0755, true); |
||
| 102 | } |
||
| 103 | if (!file_exists($logDir . '/fonts')) { |
||
| 104 | mkdir($logDir . '/fonts', 0755, true); |
||
| 105 | } |
||
| 106 | recurse_copy($this->templateDir . '/html_report/js', $logDir . '/js'); |
||
| 107 | recurse_copy($this->templateDir . '/html_report/css', $logDir . '/css'); |
||
| 108 | recurse_copy($this->templateDir . '/html_report/images', $logDir . '/images'); |
||
| 109 | recurse_copy($this->templateDir . '/html_report/fonts', $logDir . '/fonts'); |
||
| 110 | |||
| 111 | // render dynamic pages |
||
| 112 | $this->renderPage($this->templateDir . '/html_report/index.php', $logDir . '/index.html', $consolidated, $history); |
||
| 113 | $this->renderPage($this->templateDir . '/html_report/loc.php', $logDir . '/loc.html', $consolidated, $history); |
||
| 114 | $this->renderPage($this->templateDir . '/html_report/relations.php', $logDir . '/relations.html', $consolidated, $history); |
||
| 115 | $this->renderPage($this->templateDir . '/html_report/coupling.php', $logDir . '/coupling.html', $consolidated, $history); |
||
| 116 | $this->renderPage($this->templateDir . '/html_report/all.php', $logDir . '/all.html', $consolidated, $history); |
||
| 117 | $this->renderPage($this->templateDir . '/html_report/oop.php', $logDir . '/oop.html', $consolidated, $history); |
||
| 118 | $this->renderPage($this->templateDir . '/html_report/complexity.php', $logDir . '/complexity.html', $consolidated, $history); |
||
| 119 | $this->renderPage($this->templateDir . '/html_report/panel.php', $logDir . '/panel.html', $consolidated, $history); |
||
| 120 | $this->renderPage($this->templateDir . '/html_report/violations.php', $logDir . '/violations.html', $consolidated, $history); |
||
| 121 | $this->renderPage($this->templateDir . '/html_report/packages.php', $logDir . '/packages.html', $consolidated, $history); |
||
| 122 | $this->renderPage($this->templateDir . '/html_report/package_relations.php', $logDir . '/package_relations.html', $consolidated, $history); |
||
| 123 | $this->renderPage($this->templateDir . '/html_report/composer.php', $logDir . '/composer.html', $consolidated, $history); |
||
| 124 | if ($this->config->has('git')) { |
||
| 125 | $this->renderPage($this->templateDir . '/html_report/git.php', $logDir . '/git.html', $consolidated, $consolidatedGroups, $history); |
||
| 126 | } |
||
| 127 | $this->renderPage($this->templateDir . '/html_report/junit.php', $logDir . '/junit.html', $consolidated, $consolidatedGroups, $history); |
||
| 128 | |||
| 129 | // js data |
||
| 130 | file_put_contents( |
||
| 131 | sprintf('%s/js/history-%d.json', $logDir, $next), |
||
| 132 | json_encode($today, JSON_PRETTY_PRINT) |
||
| 133 | ); |
||
| 134 | file_put_contents( |
||
| 135 | sprintf('%s/js/latest.json', $logDir), |
||
| 136 | json_encode($today, JSON_PRETTY_PRINT) |
||
| 137 | ); |
||
| 138 | |||
| 139 | // json data |
||
| 140 | file_put_contents( |
||
| 141 | $logDir . '/classes.js', |
||
| 142 | 'var classes = ' . json_encode($consolidated->getClasses(), JSON_PRETTY_PRINT) |
||
| 143 | ); |
||
| 144 | |||
| 145 | // consolidated by groups |
||
| 146 | foreach ($consolidatedGroups as $name => $consolidated) { |
||
| 147 | $outDir = $logDir . DIRECTORY_SEPARATOR . $name; |
||
| 148 | $this->currentGroup = $name; |
||
| 149 | $this->assetPath = '../'; |
||
| 150 | |||
| 151 | if (!file_exists($outDir)) { |
||
| 152 | mkdir($outDir, 0755, true); |
||
| 153 | } |
||
| 154 | |||
| 155 | $this->renderPage($this->templateDir . '/html_report/index.php', $outDir . '/index.html', $consolidated, $history); |
||
| 156 | $this->renderPage($this->templateDir . '/html_report/loc.php', $outDir . '/loc.html', $consolidated, $history); |
||
| 157 | $this->renderPage($this->templateDir . '/html_report/relations.php', $outDir . '/relations.html', $consolidated, $history); |
||
| 158 | $this->renderPage($this->templateDir . '/html_report/coupling.php', $outDir . '/coupling.html', $consolidated, $history); |
||
| 159 | $this->renderPage($this->templateDir . '/html_report/all.php', $outDir . '/all.html', $consolidated, $history); |
||
| 160 | $this->renderPage($this->templateDir . '/html_report/oop.php', $outDir . '/oop.html', $consolidated, $history); |
||
| 161 | $this->renderPage($this->templateDir . '/html_report/complexity.php', $outDir . '/complexity.html', $consolidated, $history); |
||
| 162 | $this->renderPage($this->templateDir . '/html_report/panel.php', $outDir . '/panel.html', $consolidated, $history); |
||
| 163 | $this->renderPage($this->templateDir . '/html_report/violations.php', $outDir . '/violations.html', $consolidated, $history); |
||
| 164 | $this->renderPage($this->templateDir . '/html_report/packages.php', $outDir . '/packages.html', $consolidated, $history); |
||
| 165 | $this->renderPage($this->templateDir . '/html_report/package_relations.php', $outDir . '/package_relations.html', $consolidated, $history); |
||
| 166 | $this->renderPage($this->templateDir . '/html_report/composer.php', $outDir . '/composer.html', $consolidated, $history); |
||
| 167 | |||
| 168 | // json data |
||
| 169 | file_put_contents( |
||
| 170 | $outDir . '/classes.js', |
||
| 171 | 'var classes = ' . json_encode($consolidated->getClasses(), JSON_PRETTY_PRINT) |
||
| 172 | ); |
||
| 173 | } |
||
| 174 | |||
| 175 | $this->output->writeln(sprintf('HTML report generated in "%s" directory', $logDir)); |
||
| 176 | } |
||
| 177 | |||
| 280 |
This check looks for function or method calls that always return null and whose return value is assigned to a variable.
The method
getObject()can return nothing but null, so it makes no sense to assign that value to a variable.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.