Conditions | 10 |
Paths | 55 |
Total Lines | 57 |
Code Lines | 18 |
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 |
||
103 | protected function handle(bool $ajax = false) { |
||
104 | |||
105 | # Handle ajax request |
||
106 | |||
107 | if ($ajax) return $this->handleAjax(); |
||
108 | |||
109 | # Create parent |
||
110 | |||
111 | $this->parent = new static::$container_class(Request::get('parent')); |
||
112 | |||
113 | # Create entity |
||
114 | |||
115 | $this->entity = Filemanager::get($this->parent, Request::get('name')); |
||
116 | |||
117 | # Redirect if entity not found |
||
118 | |||
119 | if (!$this->entity->isInited()) { |
||
120 | |||
121 | $query = (('' !== $this->parent->getPath()) ? ('?parent=' . $this->parent->getPath()) : ''); |
||
122 | |||
123 | Request::redirect(INSTALL_PATH . '/admin/content/filemanager/' . static::$origin . '/' . $query); |
||
124 | } |
||
125 | |||
126 | # Create rename form |
||
127 | |||
128 | $this->forms['rename'] = new Filemanager\Form\Rename($this->entity, static::$permissions['manage']); |
||
129 | |||
130 | $this->controllers['rename'] = new Filemanager\Controller\Rename($this->entity); |
||
131 | |||
132 | # Create edit form |
||
133 | |||
134 | if ($this->entity->isFile() && static::$permissions['edit']) { |
||
135 | |||
136 | $this->forms['edit'] = new Filemanager\Form\Edit($this->entity); |
||
137 | |||
138 | $this->controllers['edit'] = new Filemanager\Controller\Edit($this->entity); |
||
139 | } |
||
140 | |||
141 | # Handle form |
||
142 | |||
143 | foreach ($this->forms as $name => $form) if ($form->handle($this->controllers[$name], true)) { |
||
144 | |||
145 | Request::redirect(INSTALL_PATH . '/admin/content/filemanager/' . static::$origin . '/' . static::$type . |
||
146 | |||
147 | '?parent=' . $this->parent->getPath() . '&name=' . $this->entity->getName() . '&submitted=' . $name); |
||
148 | } |
||
149 | |||
150 | # Display success message |
||
151 | |||
152 | if (Request::get('submitted') === 'rename') Popup::set('positive', Language::get(static::$message_success_rename)); |
||
153 | |||
154 | else if (Request::get('submitted') === 'edit') Popup::set('positive', Language::get(static::$message_success_edit)); |
||
155 | |||
156 | # ------------------------ |
||
157 | |||
158 | return $this->getContents(); |
||
159 | } |
||
160 | } |
||
162 |
Since your code implements the magic setter
_set
, this function will be called for any write access on an undefined variable. You can add the@property
annotation to your class or interface to document the existence of this variable.Since the property has write access only, you can use the @property-write annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.