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