| Conditions | 7 |
| Paths | 8 |
| Total Lines | 77 |
| Code Lines | 46 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| 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 |
||
| 89 | public function execute(ResultCollection $collection, ResultCollection $aggregatedResults) { |
||
| 90 | |||
| 91 | $files = $this->finder->find($this->path); |
||
| 92 | |||
| 93 | if(0 == sizeof($files, COUNT_NORMAL)) { |
||
| 94 | throw new \LogicException('No file found'); |
||
| 95 | } |
||
| 96 | |||
| 97 | $progress = new ProgressBar($this->output); |
||
| 98 | $progress->start(sizeof($files, COUNT_NORMAL)); |
||
| 99 | |||
| 100 | // tools |
||
| 101 | $classMap = new ClassMap(); |
||
| 102 | $tokenizer = new Tokenizer(); |
||
| 103 | $syntaxChecker = new SyntaxChecker(); |
||
| 104 | |||
| 105 | $fileAnalyzer = new FileAnalyzer( |
||
| 106 | $this->output |
||
| 107 | , $this->withOOP |
||
| 108 | , new Extractor($tokenizer) |
||
| 109 | , new \Hal\Metrics\Complexity\Text\Halstead\Halstead($tokenizer, new \Hal\Component\Token\TokenType()) |
||
| 110 | , new \Hal\Metrics\Complexity\Text\Length\Loc($tokenizer) |
||
| 111 | , new \Hal\Metrics\Design\Component\MaintainabilityIndex\MaintainabilityIndex() |
||
| 112 | , new \Hal\Metrics\Complexity\Component\McCabe\McCabe($tokenizer) |
||
| 113 | , new \Hal\Metrics\Complexity\Component\Myer\Myer($tokenizer) |
||
| 114 | , $classMap |
||
| 115 | ); |
||
| 116 | |||
| 117 | foreach($files as $k => $filename) { |
||
| 118 | |||
| 119 | $progress->advance(); |
||
| 120 | |||
| 121 | // Integrity |
||
| 122 | if(!$this->ignoreErrors && !$syntaxChecker->isCorrect($filename)) { |
||
| 123 | $this->output->writeln(sprintf('<error>file %s is not valid and has been skipped</error>', $filename)); |
||
| 124 | unset($files[$k]); |
||
| 125 | continue; |
||
| 126 | } |
||
| 127 | |||
| 128 | // Analyze |
||
| 129 | try { |
||
| 130 | $resultSet = $fileAnalyzer->execute($filename); |
||
| 131 | } catch(\Exception $e) { |
||
| 132 | throw new \Exception( |
||
| 133 | ( |
||
| 134 | sprintf("a '%s' exception occured analyzing file %s\nMessage: %s", get_class($e), $filename, $e->getMessage()) |
||
| 135 | . sprintf("\n------------\nStack:\n%s", $e->getTraceAsString()) |
||
| 136 | . sprintf("\n------------\nDo not hesitate to report a bug: https://github.com/Halleck45/PhpMetrics/issues") |
||
| 137 | ) |
||
| 138 | , 0, $e->getPrevious()); |
||
| 139 | } |
||
| 140 | |||
| 141 | $collection->push($resultSet); |
||
| 142 | } |
||
| 143 | |||
| 144 | $progress->clear(); |
||
| 145 | $progress->finish(); |
||
| 146 | |||
| 147 | |||
| 148 | if($this->withOOP) { |
||
| 149 | // COUPLING (should be done after parsing files) |
||
| 150 | $this->output->write(str_pad("\x0DAnalyzing coupling. This will take few minutes...", 80, "\x20")); |
||
| 151 | $couplingAnalyzer = new CouplingAnalyzer($classMap, $collection); |
||
| 152 | $couplingAnalyzer->execute($files); |
||
| 153 | |||
| 154 | // LCOM (should be done after parsing files) |
||
| 155 | $this->output->write(str_pad("\x0DLack of cohesion of method (lcom). This will take few minutes...", 80, "\x20")); |
||
| 156 | $lcomAnalyzer = new LcomAnalyzer($classMap, $collection); |
||
| 157 | $lcomAnalyzer->execute($files); |
||
| 158 | |||
| 159 | // Card and Agresti (should be done after parsing files) |
||
| 160 | $this->output->write(str_pad("\x0DAnalyzing System complexity. This will take few minutes...", 80, "\x20")); |
||
| 161 | $lcomAnalyzer = new CardAndAgrestiAnalyzer($classMap, $collection); |
||
| 162 | $lcomAnalyzer->execute($files); |
||
| 163 | } |
||
| 164 | |||
| 165 | } |
||
| 166 | |||
| 168 |