| Conditions | 12 |
| Paths | 29 |
| Total Lines | 75 |
| Code Lines | 46 |
| 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 |
||
| 41 | protected function execute(InputInterface $input, OutputInterface $output) |
||
| 42 | { |
||
| 43 | $output->writeln('Start up application with supplied config...'); |
||
| 44 | $config = $input->getArgument('applicationConfig'); |
||
| 45 | $path = stream_resolve_include_path($config); |
||
| 46 | if (!is_readable($path)) { |
||
| 47 | throw new \InvalidArgumentException("Invalid loader path: {$config}"); |
||
| 48 | } |
||
| 49 | |||
| 50 | // Init the application once using given config |
||
| 51 | // This way the late static binding on the AspectKernel |
||
| 52 | // will be on the goaop-zf2-module kernel |
||
| 53 | \Zend\Mvc\Application::init(include $path); |
||
| 54 | |||
| 55 | if (!class_exists(AspectKernel::class, false)) { |
||
| 56 | $message = "Kernel was not initialized yet. Maybe missing module Go\ZF2\GoAopModule in config {$path}"; |
||
| 57 | throw new \InvalidArgumentException($message); |
||
| 58 | } |
||
| 59 | |||
| 60 | $kernel = AspectKernel::getInstance(); |
||
| 61 | $options = $kernel->getOptions(); |
||
| 62 | |||
| 63 | if (empty($options['cacheDir'])) { |
||
| 64 | throw new \InvalidArgumentException('Cache warmer require the `cacheDir` options to be configured'); |
||
| 65 | } |
||
| 66 | |||
| 67 | $enumerator = new Enumerator($options['appDir'], $options['includePaths'], $options['excludePaths']); |
||
| 68 | $iterator = $enumerator->enumerate(); |
||
| 69 | |||
| 70 | $totalFiles = iterator_count($iterator); |
||
| 71 | $output->writeln("Total <info>{$totalFiles}</info> files to process."); |
||
| 72 | $iterator->rewind(); |
||
| 73 | |||
| 74 | set_error_handler(function($errno, $errstr, $errfile, $errline) { |
||
| 75 | throw new \ErrorException($errstr, $errno, 0, $errfile, $errline); |
||
| 76 | }); |
||
| 77 | |||
| 78 | $index = 0; |
||
| 79 | $errors = []; |
||
| 80 | foreach ($iterator as $file) { |
||
| 81 | if ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE) { |
||
| 82 | $output->writeln("Processing file <info>{$file->getRealPath()}</info>"); |
||
| 83 | } |
||
| 84 | $isSuccess = null; |
||
|
|
|||
| 85 | try { |
||
| 86 | // This will trigger creation of cache |
||
| 87 | file_get_contents( |
||
| 88 | FilterInjectorTransformer::PHP_FILTER_READ . |
||
| 89 | SourceTransformingLoader::FILTER_IDENTIFIER . |
||
| 90 | '/resource=' . $file->getRealPath() |
||
| 91 | ); |
||
| 92 | $isSuccess = true; |
||
| 93 | } catch (\Exception $e) { |
||
| 94 | $isSuccess = false; |
||
| 95 | $errors[$file->getRealPath()] = $e; |
||
| 96 | } |
||
| 97 | if ($output->getVerbosity() == OutputInterface::VERBOSITY_NORMAL) { |
||
| 98 | $output->write($isSuccess ? '.' : '<error>E</error>'); |
||
| 99 | if (++$index % 50 == 0) { |
||
| 100 | $output->writeln("($index/$totalFiles)"); |
||
| 101 | } |
||
| 102 | } |
||
| 103 | } |
||
| 104 | |||
| 105 | restore_error_handler(); |
||
| 106 | |||
| 107 | if ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERY_VERBOSE) { |
||
| 108 | foreach ($errors as $file=>$error) { |
||
| 109 | $message = "File {$file} is not processed correctly due to exception: {$error->getMessage()}"; |
||
| 110 | $output->writeln($message); |
||
| 111 | } |
||
| 112 | } |
||
| 113 | |||
| 114 | $output->writeln('<info>Done</info>'); |
||
| 115 | } |
||
| 116 | |||
| 118 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.