Conditions | 13 |
Paths | 300 |
Total Lines | 55 |
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 |
||
85 | public function handle(): void |
||
86 | { |
||
87 | $path = $this->argument('path'); |
||
88 | $name = $this->option('name'); |
||
89 | $type = $this->option('type'); |
||
90 | $maxDepth = $this->option('maxdepth'); |
||
91 | $delete = filter_var($this->option('delete'), FILTER_VALIDATE_BOOLEAN); |
||
92 | |||
93 | $root = function_exists('base_path') === true ? base_path() : getcwd(); |
||
94 | $path = rtrim($root, '/').'/'.$path; |
||
95 | |||
96 | $this->finder->in($path); |
||
97 | |||
98 | if ($name !== null) { |
||
99 | $this->finder->name($name); |
||
100 | } |
||
101 | |||
102 | switch ($type) { |
||
103 | case 'd': |
||
104 | $this->finder->directories(); |
||
105 | break; |
||
106 | case 'f': |
||
107 | $this->finder->files(); |
||
108 | break; |
||
109 | } |
||
110 | |||
111 | if (is_null($maxDepth) === false) { |
||
112 | if ($maxDepth === '0') { |
||
113 | $this->line($path); |
||
114 | |||
115 | return; |
||
116 | } |
||
117 | $this->finder->depth('<'.$maxDepth); |
||
118 | } |
||
119 | |||
120 | foreach ($this->finder->getIterator() as $file) { |
||
121 | $realPath = $file->getRealpath(); |
||
122 | if ($delete === true && $this->files->exists($realPath) === true) { |
||
123 | $removed = false; |
||
124 | |||
125 | try { |
||
126 | if ($this->files->isDirectory($realPath) === true) { |
||
127 | $removed = $this->files->deleteDirectory($realPath); |
||
128 | } else { |
||
129 | $removed = $this->files->delete($realPath); |
||
130 | } |
||
131 | } catch (Exception $e) { |
||
132 | $removed = false; |
||
133 | } |
||
134 | $removed === true ? $this->info('removed '.$realPath) : $this->error('removed '.$realPath.' fail'); |
||
135 | } else { |
||
136 | $this->line($realPath); |
||
137 | } |
||
138 | } |
||
139 | } |
||
140 | |||
168 |