| Conditions | 16 |
| Paths | 384 |
| Total Lines | 42 |
| Code Lines | 34 |
| Lines | 3 |
| Ratio | 7.14 % |
| Changes | 1 | ||
| 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 |
||
| 13 | public function formPopUpAction() |
||
|
2 ignored issues
–
show
|
|||
| 14 | { |
||
| 15 | if (strpos($_GET['item'], ':')) { |
||
| 16 | $raw = explode(':', $_GET['item']); |
||
| 17 | $modelName = $raw[0]; |
||
| 18 | $id = $raw[1]; |
||
| 19 | $model = $modelName::get($id, $modelName::index(), !empty($_GET['params']['dataManagerParams']) ? $_GET['params']['dataManagerParams'] : []); |
||
| 20 | } else { |
||
| 21 | $modelName = $_GET['item']; |
||
| 22 | $model = new $modelName(); |
||
| 23 | } |
||
| 24 | $params = []; |
||
| 25 | if (!empty($_GET['params'])) { |
||
| 26 | $params = $_GET['params']; |
||
| 27 | if (!empty($params['preset'])) { |
||
| 28 | $model->setParams($params['preset']); |
||
| 29 | } |
||
| 30 | } |
||
| 31 | View Code Duplication | if (!empty($_GET['params']['dataManagerParams']['appType'])) { |
|
| 32 | $params['appType'] = $_GET['params']['dataManagerParams']['appType']; |
||
| 33 | } |
||
| 34 | |||
| 35 | $formName = !empty($_GET['formName']) ? $_GET['formName'] : (!empty($_GET['params']['formName']) ? $_GET['params']['formName'] : 'manager'); |
||
| 36 | $form = new Ui\ActiveForm($model, $formName); |
||
| 37 | if (!empty($_GET['_']) || !empty($_POST['_'])) { |
||
| 38 | $return = new Server\Result(); |
||
| 39 | ob_start(); |
||
| 40 | $form->checkRequest($params, true); |
||
| 41 | $_GET['item'] = get_class($form->model) . ($model->pk() ? ':' . $model->pk() : ''); |
||
| 42 | $form->action = (App::$cur->system ? '/' . App::$cur->name : '') . '/ui/formPopUp/?' . http_build_query($_GET); |
||
| 43 | $form->draw($params, true); |
||
| 44 | $return->content = ob_get_contents(); |
||
| 45 | ob_end_clean(); |
||
| 46 | $return->send(); |
||
| 47 | } else { |
||
| 48 | $form->checkRequest($params); |
||
| 49 | $_GET['item'] = get_class($form->model) . ($model->pk() ? ':' . $model->pk() : ''); |
||
| 50 | $form->action = (App::$cur->system ? '/' . App::$cur->name : '') . '/ui/formPopUp/?' . http_build_query($_GET); |
||
| 51 | $this->view->setTitle(($model && $model->pk() ? 'Изменить ' : 'Создать ') . $form->header); |
||
| 52 | $this->view->page(['content' => 'form', 'data' => compact('form', 'params')]); |
||
| 53 | } |
||
| 54 | } |
||
| 55 | |||
| 66 |
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: