Conditions | 9 |
Paths | 32 |
Total Lines | 56 |
Code Lines | 36 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 1 | 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 declare(strict_types=1); |
||
49 | public function handle() |
||
50 | { |
||
51 | $frameworkNames = $this->option('framework'); |
||
52 | if (is_string($frameworkNames)) { |
||
|
|||
53 | $frameworkNames = [$frameworkNames]; |
||
54 | } |
||
55 | /** |
||
56 | * @var array $frameworkNames |
||
57 | */ |
||
58 | if (in_array('*', $frameworkNames)) { |
||
59 | $frameworks = FrameworkFactory::factoryAll(); |
||
60 | } else { |
||
61 | $frameworks = array_map( |
||
62 | [FrameworkFactory::class, 'factory'], |
||
63 | $frameworkNames |
||
64 | ); |
||
65 | } |
||
66 | |||
67 | $name = $this->argument('name'); |
||
68 | if (!is_string($name)) { |
||
69 | $this->error('Name must be a string'); |
||
70 | return; |
||
71 | } |
||
72 | $datatype = DatatypeFactory::factory($name); |
||
73 | $datatypeLower = mb_strtolower($datatype->getName()); |
||
74 | $baseNamespace = $this->option('namespace'); |
||
75 | if (!is_string($baseNamespace)) { |
||
76 | $this->error('namespace must be a string'); |
||
77 | return; |
||
78 | } |
||
79 | |||
80 | $basePath = $this->option('path'); |
||
81 | if (!is_string($basePath)) { |
||
82 | $this->error('path must be a string'); |
||
83 | return; |
||
84 | } |
||
85 | |||
86 | $printer = new \Nette\PhpGenerator\PsrPrinter(); |
||
87 | |||
88 | foreach ($frameworks as $framework) { |
||
89 | /** |
||
90 | * @var Framework $framework |
||
91 | */ |
||
92 | $phpns = $framework->generateRenderable($datatype, $baseNamespace); |
||
93 | $code = "<?php declare(strict_types=1);\n" . $printer->printNamespace($phpns); |
||
94 | $basepath = $basePath . '/' . $framework->getName() . '/Renderable/'; |
||
95 | if (!is_dir($basepath)) { |
||
96 | \Safe\mkdir($basepath, 0777, true); |
||
97 | } |
||
98 | |||
99 | $filename = $basepath . 'Renderable_' . $datatypeLower . '.php'; |
||
100 | if (!file_exists($filename)) { |
||
101 | $this->info("Created renderable at {$filename}."); |
||
102 | file_put_contents($filename, $code); |
||
103 | } else { |
||
104 | $this->warn("Filename $filename already exists."); |
||
105 | } |
||
109 |