| Conditions | 10 |
| Paths | 12 |
| Total Lines | 82 |
| Code Lines | 42 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 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 |
||
| 40 | protected function execute(InputInterface $input, OutputInterface $output) |
||
| 41 | { |
||
| 42 | $output->writeln(''); |
||
| 43 | |||
| 44 | if (extension_loaded('xdebug')) { |
||
| 45 | /** |
||
| 46 | * This will disable only showing stack traces on error conditions. |
||
| 47 | */ |
||
| 48 | if (function_exists('xdebug_disable')) { |
||
| 49 | xdebug_disable(); |
||
| 50 | } |
||
| 51 | |||
| 52 | $output->writeln('<error>It is highly recommended to disable the XDebug extension before invoking this command.</error>'); |
||
| 53 | } |
||
| 54 | |||
| 55 | $parser = (new ParserFactory())->create(ParserFactory::PREFER_PHP7, new \PhpParser\Lexer\Emulative([ |
||
| 56 | 'usedAttributes' => [ |
||
| 57 | 'comments', |
||
| 58 | 'startLine', |
||
| 59 | 'endLine', |
||
| 60 | 'startTokenPos', |
||
| 61 | 'endTokenPos' |
||
| 62 | ] |
||
| 63 | ])); |
||
| 64 | |||
| 65 | /** @var Application $application */ |
||
| 66 | $application = $this->getApplication(); |
||
| 67 | $application->compiler = new Compiler(); |
||
| 68 | |||
| 69 | $em = EventManager::getInstance(); |
||
|
|
|||
| 70 | $context = new Context($output, $application, $em); |
||
| 71 | |||
| 72 | $fileParser = new FileParser( |
||
| 73 | $parser, |
||
| 74 | $this->getCompiler() |
||
| 75 | ); |
||
| 76 | |||
| 77 | $path = $input->getArgument('path'); |
||
| 78 | if (is_dir($path)) { |
||
| 79 | $directoryIterator = new RecursiveIteratorIterator( |
||
| 80 | new RecursiveDirectoryIterator($path, FilesystemIterator::SKIP_DOTS) |
||
| 81 | ); |
||
| 82 | $output->writeln('Scanning directory <info>' . $path . '</info>'); |
||
| 83 | |||
| 84 | $count = 0; |
||
| 85 | |||
| 86 | /** @var SplFileInfo $file */ |
||
| 87 | foreach ($directoryIterator as $file) { |
||
| 88 | if ($file->getExtension() !== 'php') { |
||
| 89 | continue; |
||
| 90 | } |
||
| 91 | |||
| 92 | $context->debug($file->getPathname()); |
||
| 93 | $count++; |
||
| 94 | } |
||
| 95 | |||
| 96 | $output->writeln("Found <info>{$count} files</info>"); |
||
| 97 | |||
| 98 | if ($count > 100) { |
||
| 99 | $output->writeln('<comment>Caution: You are trying to scan a lot of files; this might be slow. For bigger libraries, consider setting up a dedicated platform or using ci.lowl.io.</comment>'); |
||
| 100 | } |
||
| 101 | |||
| 102 | $output->writeln(''); |
||
| 103 | |||
| 104 | /** @var SplFileInfo $file */ |
||
| 105 | foreach ($directoryIterator as $file) { |
||
| 106 | if ($file->getExtension() !== 'php') { |
||
| 107 | continue; |
||
| 108 | } |
||
| 109 | |||
| 110 | $fileParser->parserFile($file->getPathname(), $context); |
||
| 111 | } |
||
| 112 | } elseif (is_file($path)) { |
||
| 113 | $fileParser->parserFile($path, $context); |
||
| 114 | } |
||
| 115 | |||
| 116 | |||
| 117 | /** |
||
| 118 | * Step 2 Recursive check ... |
||
| 119 | */ |
||
| 120 | $application->compiler->compile($context); |
||
| 121 | } |
||
| 122 | |||
| 131 |
Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.