| Conditions | 12 |
| Paths | 19 |
| Total Lines | 38 |
| Code Lines | 12 |
| Lines | 0 |
| Ratio | 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 |
||
| 115 | public function handle(bool $create = false) { |
||
| 116 | |||
| 117 | if (!($this->create = $create) && Request::isAjax()) return $this->handleAjax(); |
||
| 118 | |||
| 119 | # Create entity |
||
| 120 | |||
| 121 | if (static::$nesting) $this->parent = Entitizer::get(static::$type, Number::format(Request::get('id'))); |
||
| 122 | |||
| 123 | $this->entity = Entitizer::get(static::$type, (!$this->create ? Number::format(Request::get('id')) : 0)); |
||
| 124 | |||
| 125 | # Redirect if entity not found |
||
| 126 | |||
| 127 | if (!$this->create && (0 === $this->entity->id)) return Request::redirect(INSTALL_PATH . static::$link); |
||
| 128 | |||
| 129 | # Create form |
||
| 130 | |||
| 131 | $this->form = new static::$form_class($this->entity); |
||
| 132 | |||
| 133 | if (static::$nesting && $this->create) $this->form->get('parent_id')->set($this->parent->id); |
||
| 134 | |||
| 135 | # Handle form |
||
| 136 | |||
| 137 | if ($this->form->handle(new static::$controller($this->entity))) { |
||
| 138 | |||
| 139 | Request::redirect(INSTALL_PATH . static::$link . '/edit?id=' . $this->entity->id . '&submitted'); |
||
| 140 | } |
||
| 141 | |||
| 142 | # Display success message |
||
| 143 | |||
| 144 | if (!$this->create && (false !== Request::get('submitted'))) { |
||
| 145 | |||
| 146 | Messages::success(Language::get(static::$message_success_save)); |
||
| 147 | } |
||
| 148 | |||
| 149 | # ------------------------ |
||
| 150 | |||
| 151 | return $this->getContents(); |
||
| 152 | } |
||
| 153 | } |
||
| 155 |
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@propertyannotation 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.