| Conditions | 7 |
| Paths | 14 |
| Total Lines | 77 |
| Code Lines | 50 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| 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 |
||
| 39 | #[Override] |
||
| 40 | protected function execute(InputInterface $input, OutputInterface $output): int |
||
| 41 | { |
||
| 42 | $output->writeln(''); |
||
| 43 | $output->writeln('<info>Warming Gacela cache...</info>'); |
||
| 44 | $output->writeln('<info>' . str_repeat('=', 60) . '</info>'); |
||
| 45 | $output->writeln(''); |
||
| 46 | |||
| 47 | $clearCache = (bool) $input->getOption('clear'); |
||
| 48 | |||
| 49 | if ($clearCache) { |
||
| 50 | $this->clearCache($output); |
||
| 51 | } |
||
| 52 | |||
| 53 | $startTime = microtime(true); |
||
| 54 | $startMemory = memory_get_usage(true); |
||
| 55 | |||
| 56 | // Find all modules |
||
| 57 | $modules = $this->getFacade()->findAllAppModules(); |
||
| 58 | $output->writeln(sprintf('<fg=cyan>Found %d modules</>', count($modules))); |
||
| 59 | $output->writeln(''); |
||
| 60 | |||
| 61 | $resolvedCount = 0; |
||
| 62 | $skippedCount = 0; |
||
| 63 | |||
| 64 | // Pre-resolve all module classes |
||
| 65 | foreach ($modules as $module) { |
||
| 66 | $moduleClasses = [ |
||
| 67 | 'Facade' => $module->facadeClass(), |
||
| 68 | 'Factory' => $module->factoryClass(), |
||
| 69 | 'Config' => $module->configClass(), |
||
| 70 | 'Provider' => $module->providerClass(), |
||
| 71 | ]; |
||
| 72 | |||
| 73 | $output->writeln(sprintf('<comment>Processing:</> %s', $module->moduleName())); |
||
| 74 | |||
| 75 | foreach ($moduleClasses as $type => $className) { |
||
| 76 | if ($className === null) { |
||
| 77 | continue; |
||
| 78 | } |
||
| 79 | |||
| 80 | if (!class_exists($className)) { |
||
| 81 | $output->writeln(sprintf(' <fg=yellow>⚠ Skipped %s:</> %s (class not found)', $type, $className)); |
||
| 82 | ++$skippedCount; |
||
| 83 | continue; |
||
| 84 | } |
||
| 85 | |||
| 86 | // Trigger class resolution to populate cache |
||
| 87 | try { |
||
| 88 | class_exists($className, true); |
||
| 89 | $output->writeln(sprintf(' <fg=green>✓ Resolved %s:</> %s', $type, $className)); |
||
| 90 | ++$resolvedCount; |
||
| 91 | } catch (Throwable $e) { |
||
| 92 | $output->writeln(sprintf(' <fg=red>✗ Failed %s:</> %s (%s)', $type, $className, $e->getMessage())); |
||
| 93 | ++$skippedCount; |
||
| 94 | } |
||
| 95 | } |
||
| 96 | |||
| 97 | $output->writeln(''); |
||
| 98 | } |
||
| 99 | |||
| 100 | $endTime = microtime(true); |
||
| 101 | $endMemory = memory_get_usage(true); |
||
| 102 | |||
| 103 | $output->writeln('<info>' . str_repeat('=', 60) . '</info>'); |
||
| 104 | $output->writeln('<info>Cache warming complete!</info>'); |
||
| 105 | $output->writeln(''); |
||
| 106 | $output->writeln(sprintf('<fg=cyan>Modules processed:</> %d', count($modules))); |
||
| 107 | $output->writeln(sprintf('<fg=cyan>Classes resolved:</> %d', $resolvedCount)); |
||
| 108 | $output->writeln(sprintf('<fg=cyan>Classes skipped:</> %d', $skippedCount)); |
||
| 109 | $output->writeln(sprintf('<fg=cyan>Time taken:</> %.3f seconds', $endTime - $startTime)); |
||
| 110 | $output->writeln(sprintf('<fg=cyan>Memory used:</> %s', $this->formatBytes($endMemory - $startMemory))); |
||
| 111 | $output->writeln(''); |
||
| 112 | |||
| 113 | $this->displayCacheInfo($output); |
||
| 114 | |||
| 115 | return Command::SUCCESS; |
||
| 116 | } |
||
| 193 |