| Conditions | 10 |
| Paths | 19 |
| Total Lines | 73 |
| Code Lines | 42 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 4 | ||
| Bugs | 3 | 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 |
||
| 105 | protected function execute(InputInterface $input, OutputInterface $output) |
||
| 106 | { |
||
| 107 | |||
| 108 | $output->writeln('PHPMetrics by Jean-François Lépine <https://twitter.com/Halleck45>'); |
||
| 109 | $output->writeln(''); |
||
| 110 | |||
| 111 | // config |
||
| 112 | $configFactory = new ConfigFactory(); |
||
| 113 | $config = $configFactory->factory($input); |
||
| 114 | |||
| 115 | // files |
||
| 116 | if(null === $config->getPath()->getBasePath()) { |
||
| 117 | throw new \LogicException('Please provide a path to analyze'); |
||
| 118 | } |
||
| 119 | |||
| 120 | // files to analyze |
||
| 121 | $finder = new Finder( |
||
| 122 | $config->getPath()->getExtensions() |
||
| 123 | , $config->getPath()->getExcludedDirs() |
||
| 124 | , $config->getPath()->isFollowSymlinks() ? Finder::FOLLOW_SYMLINKS : null |
||
| 125 | ); |
||
| 126 | |||
| 127 | // prepare plugins |
||
| 128 | $repository = new Repository(); |
||
| 129 | foreach($config->getExtensions()->getExtensions() as $filename) { |
||
| 130 | if(!file_exists($filename) ||!is_readable($filename)) { |
||
| 131 | $output->writeln(sprintf('<error>Plugin %s skipped: not found</error>', $filename)); |
||
| 132 | continue; |
||
| 133 | } |
||
| 134 | $plugin = require_once($filename); |
||
| 135 | $repository->attach($plugin); |
||
| 136 | } |
||
| 137 | $extensionService = new ExtensionService($repository); |
||
| 138 | |||
| 139 | // prepare structures |
||
| 140 | $bounds = new Bounds(); |
||
| 141 | $collection = new ResultCollection(); |
||
| 142 | $aggregatedResults = new ResultCollection(); |
||
| 143 | |||
| 144 | // execute analyze |
||
| 145 | $queueFactory = new QueueAnalyzeFactory($input, $output, $config, $extensionService); |
||
| 146 | $queue = $queueFactory->factory($finder, $bounds); |
||
| 147 | gc_disable(); |
||
| 148 | $queue->execute($collection, $aggregatedResults); |
||
| 149 | gc_enable(); |
||
| 150 | |||
| 151 | $output->writeln(''); |
||
| 152 | |||
| 153 | // provide data to extensions |
||
| 154 | if(($n = sizeof($repository->all())) > 0) { |
||
| 155 | $output->writeln(sprintf('%d %s. Executing analyzis', $n, ($n > 1 ? 'plugins are enabled' : 'plugin is enabled') )); |
||
| 156 | $extensionService->receive($config, $collection, $aggregatedResults, $bounds); |
||
| 157 | } |
||
| 158 | |||
| 159 | // generating reports |
||
| 160 | $output->writeln("Generating reports..."); |
||
| 161 | $queueFactory = new QueueReportFactory($input, $output, $config, $extensionService); |
||
| 162 | $queue = $queueFactory->factory($finder, $bounds); |
||
| 163 | $queue->execute($collection, $aggregatedResults); |
||
| 164 | |||
| 165 | $output->writeln('<info>Done</info>'); |
||
| 166 | |||
| 167 | // evaluation of success |
||
| 168 | $rule = $config->getFailureCondition(); |
||
| 169 | if(null !== $rule) { |
||
| 170 | $evaluator = new Evaluator($collection, $aggregatedResults, $bounds); |
||
| 171 | $result = $evaluator->evaluate($rule); |
||
| 172 | // fail if failure-condition is realized |
||
| 173 | return $result->isValid() ? 1 : 0; |
||
| 174 | } |
||
| 175 | |||
| 176 | return 0; |
||
| 177 | } |
||
| 178 | |||
| 180 |