Conditions | 11 |
Paths | 28 |
Total Lines | 54 |
Code Lines | 32 |
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 |
||
12 | public function getRename() |
||
13 | { |
||
14 | $old_name = $this->helper->input('file'); |
||
15 | $new_name = $this->helper->input('new_name'); |
||
16 | |||
17 | $old_file = $this->lfm->pretty($old_name); |
||
18 | |||
19 | $is_directory = $old_file->isDirectory(); |
||
20 | |||
21 | if (empty($new_name)) { |
||
22 | if ($is_directory) { |
||
23 | return parent::error('folder-name'); |
||
24 | } else { |
||
25 | return parent::error('file-name'); |
||
26 | } |
||
27 | } |
||
28 | |||
29 | if (config('lfm.alphanumeric_directory') && preg_match('/[^\w-]/i', $new_name)) { |
||
30 | return parent::error('folder-alnum'); |
||
31 | // return parent::error('file-alnum'); |
||
32 | } elseif ($this->lfm->setName($new_name)->exists()) { |
||
33 | return parent::error('rename'); |
||
34 | } |
||
35 | |||
36 | if (! $is_directory) { |
||
37 | $extension = $old_file->extension(); |
||
38 | if ($extension) { |
||
39 | $new_name = str_replace('.' . $extension, '', $new_name) . '.' . $extension; |
||
40 | } |
||
41 | } |
||
42 | |||
43 | $new_file = $this->lfm->setName($new_name)->path('absolute'); |
||
44 | |||
45 | if ($is_directory) { |
||
46 | event(new FolderIsRenaming($old_file->path(), $new_file)); |
||
47 | } else { |
||
48 | event(new ImageIsRenaming($old_file->path(), $new_file)); |
||
49 | } |
||
50 | |||
51 | if ($old_file->hasThumb()) { |
||
52 | $this->lfm->setName($old_name)->thumb() |
||
53 | ->move($this->lfm->setName($new_name)->thumb()); |
||
54 | } |
||
55 | |||
56 | $this->lfm->setName($old_name) |
||
57 | ->move($this->lfm->setName($new_name)); |
||
58 | |||
59 | if ($is_directory) { |
||
60 | event(new FolderWasRenamed($old_file->path(), $new_file)); |
||
61 | } else { |
||
62 | event(new ImageWasRenamed($old_file->path(), $new_file)); |
||
63 | } |
||
64 | |||
65 | return parent::$success_response; |
||
66 | } |
||
68 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.