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