Conditions | 6 |
Paths | 6 |
Total Lines | 62 |
Code Lines | 37 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 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 |
||
21 | public function perform(ScaffolderConfig $config, DirectoriesInterface $dirs, Console $console): int |
||
22 | { |
||
23 | $this->output->title('Scaffolder commands'); |
||
24 | $this->writeln( |
||
25 | 'Scaffolder enables developers to quickly and easily generate application code for various classes, using a set of console commands', |
||
26 | ); |
||
27 | |||
28 | $this->newLine(); |
||
29 | |||
30 | $table = $this->table(['Command', 'Target']); |
||
31 | $rootDir = $dirs->get('root'); |
||
32 | $available = $config->getDeclarations(); |
||
33 | |||
34 | $i = 0; |
||
35 | foreach ($available as $name) { |
||
36 | $command = 'create:' . $name; |
||
37 | |||
38 | if (!$console->getApplication()->has($command)) { |
||
39 | continue; |
||
40 | } |
||
41 | |||
42 | $command = $console->getApplication()->get($command); |
||
43 | |||
44 | if ($i > 0) { |
||
45 | $table->addRow(new TableSeparator()); |
||
46 | } |
||
47 | $declaration = $config->getDeclaration($name); |
||
48 | |||
49 | $options = []; |
||
50 | foreach ($declaration['options'] ?? [] as $key => $value) { |
||
51 | $options[] = $key . ': <fg=yellow>' . \json_encode(\str_replace($rootDir, '', $value)) . '</>'; |
||
52 | } |
||
53 | |||
54 | $file = \str_replace($rootDir, '', $config->classFilename($name, $this->name)); |
||
55 | $namespace = $config->classNamespace($name, $this->name); |
||
56 | $table->addRow([ |
||
57 | $command->getName() . "\n<fg=gray>{$command->getDescription()}</>", |
||
58 | <<<TARGET |
||
59 | path: <fg=green>/$file</> |
||
60 | namespace: <fg=yellow>$namespace</> |
||
61 | TARGET |
||
62 | . |
||
63 | ($options !== [] ? "\n" . \implode("\n", $options) : ''), |
||
64 | ]); |
||
65 | |||
66 | $i++; |
||
67 | } |
||
68 | |||
69 | $randomName = $available[\array_rand($available)]; |
||
70 | $this->writeln( |
||
71 | "<info>Use `<fg=yellow>php app.php create:{$randomName} {$this->name}</>` command to generate desired class. Below is a list of available commands:</info>", |
||
72 | ); |
||
73 | |||
74 | $table->render(); |
||
75 | |||
76 | $this->writeln( |
||
77 | '<info>Use `<fg=yellow>php app.php create:*** --help</>` command to see available options.</info>', |
||
78 | ); |
||
79 | |||
80 | $this->writeln('Read more about scaffolder in <fg=yellow>https://spiral.dev/docs/basics-scaffolding</> documentation section.'); |
||
81 | |||
82 | return self::SUCCESS; |
||
83 | } |
||
85 |