| Conditions | 20 |
| Paths | 3072 |
| Total Lines | 55 |
| Code Lines | 43 |
| 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 |
||
| 20 | public function formPopUpAction() { |
||
| 21 | $id = false; |
||
| 22 | if (strpos($_GET['item'], ':')) { |
||
| 23 | $raw = explode(':', $_GET['item']); |
||
| 24 | $modelName = $raw[0]; |
||
| 25 | $id = $raw[1]; |
||
| 26 | } else { |
||
| 27 | $modelName = $_GET['item']; |
||
| 28 | } |
||
| 29 | $formName = !empty($_GET['formName']) ? $_GET['formName'] : (!empty($_GET['params']['formName']) ? $_GET['params']['formName'] : 'manager'); |
||
| 30 | $form = ActiveForm::forModel($modelName, $formName); |
||
| 31 | if ($id) { |
||
| 32 | $form->loadModelById($id, empty($_GET['params']['dataManagerParams']) ? $_GET['params']['dataManagerParams'] : []); |
||
| 33 | } |
||
| 34 | if (!$form->model) { |
||
| 35 | $form->emptyModel(); |
||
| 36 | } |
||
| 37 | |||
| 38 | $params = []; |
||
| 39 | if (!empty($_GET['params'])) { |
||
| 40 | $params = $_GET['params']; |
||
| 41 | if (!empty($params['preset'])) { |
||
| 42 | $model->setParams($params['preset']); |
||
|
|
|||
| 43 | } |
||
| 44 | } |
||
| 45 | if (!empty($_GET['params']['dataManagerParams']['appType'])) { |
||
| 46 | $params['appType'] = $_GET['params']['dataManagerParams']['appType']; |
||
| 47 | } |
||
| 48 | |||
| 49 | |||
| 50 | if (!empty($_GET['_']) || !empty($_POST['_'])) { |
||
| 51 | $return = new Result(); |
||
| 52 | ob_start(); |
||
| 53 | $form->checkRequest($params, true); |
||
| 54 | $_GET['item'] = $form->modelName . ($form->model->pk() ? ':' . $form->model->pk() : ''); |
||
| 55 | $get = $_GET; |
||
| 56 | if (isset($get['notSave'])) { |
||
| 57 | unset($get['notSave']); |
||
| 58 | } |
||
| 59 | $this->view->widget('msgList'); |
||
| 60 | $form->action = (App::$cur->system ? '/' . App::$cur->name : '') . '/ui/formPopUp/?' . http_build_query($get); |
||
| 61 | $form->draw($params, true); |
||
| 62 | $return->content = ob_get_contents(); |
||
| 63 | ob_end_clean(); |
||
| 64 | $return->send(); |
||
| 65 | } else { |
||
| 66 | $form->checkRequest($params); |
||
| 67 | $_GET['item'] = $form->modelName . ($form->model->pk() ? ':' . $form->model->pk() : ''); |
||
| 68 | $get = $_GET; |
||
| 69 | if (isset($get['notSave'])) { |
||
| 70 | unset($get['notSave']); |
||
| 71 | } |
||
| 72 | $form->action = (App::$cur->system ? '/' . App::$cur->name : '') . '/ui/formPopUp/?' . http_build_query($get); |
||
| 73 | $this->view->setTitle(($form->model && $form->model->pk() ? 'Изменить ' : 'Создать ') . $form->label); |
||
| 74 | $this->view->page(['content' => 'form', 'data' => compact('form', 'params')]); |
||
| 75 | } |
||
| 97 |