| Conditions | 14 |
| Paths | 538 |
| Total Lines | 85 |
| Code Lines | 53 |
| Lines | 8 |
| Ratio | 9.41 % |
| Changes | 5 | ||
| Bugs | 0 | 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 |
||
| 48 | protected function execute(InputInterface $input, OutputInterface $output) |
||
| 49 | { |
||
| 50 | if(!empty($input->getOption('debug')) && $output->getVerbosity() < OutputInterface::VERBOSITY_VERBOSE) { |
||
| 51 | $output->setVerbosity(OutputInterface::VERBOSITY_VERBOSE); |
||
| 52 | } |
||
| 53 | |||
| 54 | $output->writeln($this->getApplication()->getLongVersion()."\n", Output::VERBOSITY_VERBOSE); |
||
| 55 | |||
| 56 | $debugFormatter = new DebugFormatter(); |
||
| 57 | foreach($input->getArgument('path') as $filename) { |
||
| 58 | $language = $input->getOption('language') |
||
| 59 | ? Language::byName($input->getOption('language')) |
||
| 60 | : Language::byFilename($filename); |
||
| 61 | |||
| 62 | $formatter = KeyLighter::get()->getFormatter($input->getOption('format')) ?: KeyLighter::get()->getDefaultFormatter(); |
||
| 63 | |||
| 64 | if(!($source = $this->content($filename))) { |
||
| 65 | throw new InvalidArgumentException(sprintf('Specified file %s doesn\'t exist, check if given path is correct.', $filename)); |
||
| 66 | } |
||
| 67 | |||
| 68 | if($output->isVerbose()) { |
||
| 69 | $counts = ['before' => null, 'after' => null]; |
||
| 70 | $times = ['tokenization' => null, 'parsing' => null, 'formatting' => null]; |
||
| 71 | |||
| 72 | $output->writeln(sprintf( |
||
| 73 | "Used file: <path>%s</path>, Language: <language>%s</language>, Formatter: <formatter>%s</formatter>", |
||
| 74 | $filename, $language->getFQN(), get_class($formatter) |
||
| 75 | )); |
||
| 76 | |||
| 77 | $tokens = $this->benchmark($output, function() use($language, $source) { return $language->tokenize($source); }, $times['tokenization']); |
||
| 78 | $counts['before'] = count($tokens); |
||
| 79 | View Code Duplication | if(in_array('tree-before', $input->getOption('debug'))) { |
|
| 80 | $output->writeln('<comment>Token tree before parsing: </comment>'); |
||
| 81 | $output->writeln($debugFormatter->format(clone $tokens, false)); |
||
| 82 | } |
||
| 83 | |||
| 84 | $tokens = $this->benchmark($output, function() use($language, $tokens) { return $language->parse($tokens); }, $times['parsing']); |
||
| 85 | $counts['after'] = count($tokens); |
||
| 86 | View Code Duplication | if(in_array('tree-after', $input->getOption('debug'))) { |
|
| 87 | $output->writeln('<comment>Token tree after parsing: </comment>'); |
||
| 88 | $output->writeln($debugFormatter->format(clone $tokens)); |
||
| 89 | } |
||
| 90 | |||
| 91 | $formatted = $this->benchmark($output, function() use($formatter, $tokens) { return $formatter->format($tokens); }, $times['formatting']); |
||
| 92 | |||
| 93 | if(in_array('count', $input->getOption('debug'))) { |
||
| 94 | $output->writeln(sprintf( |
||
| 95 | '<comment>Token count before parsing: </comment> %s (%s tokens/kB)', |
||
| 96 | $counts['before'], number_format($counts['before']/strlen($source) * 1024) |
||
| 97 | )); |
||
| 98 | $output->writeln(sprintf( |
||
| 99 | '<comment>Token count after parsing: </comment> %s (%s tokens/kB)', |
||
| 100 | $counts['after'], number_format($counts['after']/strlen($source) * 1024) |
||
| 101 | )); |
||
| 102 | } |
||
| 103 | |||
| 104 | if(in_array('detailed-time', $input->getOption('debug'))) { |
||
| 105 | $output->writeln(sprintf( |
||
| 106 | '<info>Time taken</info> [s] <comment>tokenization</comment>/<comment>parsing</comment>/<comment>formatting</comment>: %.4f / %.4f / %.4f', |
||
| 107 | $times['tokenization'], $times['parsing'], $times['formatting'] |
||
| 108 | )); |
||
| 109 | |||
| 110 | $output->writeln(sprintf( |
||
| 111 | '<info>Performance</info> [chars/s] <comment>tokenization</comment>/<comment>parsing</comment>/<comment>formatting</comment>: %s / %s / %s', |
||
| 112 | number_format(strlen($source) / $times['tokenization']), |
||
| 113 | number_format(strlen($source) / $times['parsing']), |
||
| 114 | number_format(strlen($source) / $times['formatting']) |
||
| 115 | )); |
||
| 116 | } |
||
| 117 | |||
| 118 | if(in_array('time', $input->getOption('debug'))) { |
||
| 119 | $output->writeln(sprintf( |
||
| 120 | '<info>Overall:</info> %.4fs, %s chars/s', |
||
| 121 | array_sum($times), number_format(strlen($source) / array_sum($times)) |
||
| 122 | )); |
||
| 123 | } |
||
| 124 | } else { |
||
| 125 | $formatted = KeyLighter::get()->highlight($source, $language, $formatter); |
||
| 126 | } |
||
| 127 | |||
| 128 | if(!$input->getOption('no-output')) { |
||
| 129 | $output->writeln($formatted); |
||
| 130 | } |
||
| 131 | } |
||
| 132 | } |
||
| 133 | |||
| 162 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.