| Conditions | 38 |
| Paths | 218 |
| Total Lines | 114 |
| Code Lines | 85 |
| 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 |
||
| 96 | public function checkRequest($params = [], $ajax = false) { |
||
| 97 | if (!$this->checkAccess()) { |
||
| 98 | $this->drawError('you not have access to "' . $this->modelName . '" manager with name: "' . $this->formName . '"'); |
||
| 99 | return []; |
||
| 100 | } |
||
| 101 | $successId = 0; |
||
| 102 | $modelName = $this->model; |
||
| 103 | if (!empty($_POST[$this->requestFormName][$this->modelName]) || !empty($_FILES[$this->requestFormName]['tmp_name'][$this->modelName])) { |
||
| 104 | $request = !empty($_POST[$this->requestFormName][$this->modelName]) ? $_POST[$this->requestFormName][$this->modelName] : []; |
||
| 105 | if ($this->model) { |
||
| 106 | if (!empty($this->form['handler']) && empty($_GET['notSave'])) { |
||
| 107 | |||
| 108 | $modelName::{$this->form['handler']}($request); |
||
| 109 | $text = 'Новый элемент был успешно добавлен'; |
||
| 110 | \Msg::add($text, 'success'); |
||
| 111 | \Msg::show(); |
||
| 112 | } else { |
||
| 113 | $presets = !empty($this->form['preset']) ? $this->form['preset'] : []; |
||
| 114 | if (!empty($this->form['userGroupPreset'][\Users\User::$cur->group_id])) { |
||
| 115 | $presets = array_merge($presets, $this->form['userGroupPreset'][\Users\User::$cur->group_id]); |
||
| 116 | } |
||
| 117 | $afterSave = []; |
||
| 118 | $error = false; |
||
| 119 | foreach ($this->inputs as $col => $param) { |
||
| 120 | if (!empty($presets[$col])) { |
||
| 121 | continue; |
||
| 122 | } |
||
| 123 | if (is_object($param)) { |
||
| 124 | $afterSave[$col] = $param; |
||
| 125 | continue; |
||
| 126 | } |
||
| 127 | if (!empty($this->form['userGroupReadonly'][\Users\User::$cur->group_id]) && in_array($col, $this->form['userGroupReadonly'][\Users\User::$cur->group_id])) { |
||
| 128 | continue; |
||
| 129 | } |
||
| 130 | $type = ucfirst($param['type']); |
||
| 131 | if ($type == 'DynamicType') { |
||
| 132 | switch ($param['typeSource']) { |
||
| 133 | case 'selfMethod': |
||
| 134 | $type = $this->model->{$param['selfMethod']}(); |
||
| 135 | if (is_array($type)) { |
||
| 136 | $param = $type; |
||
| 137 | $type = $type['type']; |
||
| 138 | } |
||
| 139 | break; |
||
| 140 | } |
||
| 141 | } |
||
| 142 | $inputClassName = '\Ui\ActiveForm\Input\\' . ucfirst($type); |
||
| 143 | /** @var \Ui\ActiveForm\Input $input */ |
||
| 144 | $input = new $inputClassName(); |
||
| 145 | $input->activeForm = $this; |
||
| 146 | $input->activeFormParams = $params; |
||
| 147 | $input->modelName = $this->modelName; |
||
| 148 | $input->colName = $col; |
||
| 149 | $input->colParams = $param; |
||
| 150 | try { |
||
| 151 | $input->validate($request); |
||
| 152 | $input->parseRequest($request); |
||
| 153 | } catch (\Exception $exc) { |
||
| 154 | \Msg::add($exc->getMessage(), 'danger'); |
||
| 155 | $error = true; |
||
| 156 | } |
||
| 157 | } |
||
| 158 | if (!$error && empty($_GET['notSave'])) { |
||
| 159 | foreach ($presets as $col => $preset) { |
||
| 160 | if (!empty($preset['value'])) { |
||
| 161 | $this->model->$col = $preset['value']; |
||
| 162 | } elseif (!empty($preset['userCol'])) { |
||
| 163 | if (strpos($preset['userCol'], ':')) { |
||
| 164 | $rel = substr($preset['userCol'], 0, strpos($preset['userCol'], ':')); |
||
| 165 | $param = substr($preset['userCol'], strpos($preset['userCol'], ':') + 1); |
||
| 166 | $this->model->$col = \Users\User::$cur->$rel->$param; |
||
| 167 | } else { |
||
| 168 | $this->model->$col = \Users\User::$cur->{$preset['userCol']}; |
||
| 169 | } |
||
| 170 | } |
||
| 171 | } |
||
| 172 | if (!$this->parent) { |
||
| 173 | if (!empty($this->form['successText'])) { |
||
| 174 | $text = $this->form['successText']; |
||
| 175 | } else { |
||
| 176 | $text = $this->model->pk() ? 'Изменения были успешно сохранены' : 'Новый элемент был успешно добавлен'; |
||
| 177 | } |
||
| 178 | \Msg::add($text, 'success'); |
||
| 179 | } |
||
| 180 | |||
| 181 | $this->model->save(!empty($params['dataManagerParams']) ? $params['dataManagerParams'] : []); |
||
| 182 | foreach ($afterSave as $col => $form) { |
||
| 183 | if (strpos($col, 'form:') === 0) { |
||
| 184 | $colPath = explode(':', $col); |
||
| 185 | if (!$this->model->{$colPath[1]}) { |
||
| 186 | $relOptions = $modelName::getRelation($colPath[1]); |
||
| 187 | if (!isset($this->model->_params[$modelName::index()])) { |
||
| 188 | $this->model->_params[$modelName::index()] = 0; |
||
| 189 | } |
||
| 190 | $relOptions['model']::fixPrefix($relOptions['col']); |
||
| 191 | $form->model->{$relOptions['col']} = $this->model->_params[$modelName::index()]; |
||
| 192 | } |
||
| 193 | } |
||
| 194 | $form->checkRequest(); |
||
| 195 | } |
||
| 196 | if ($ajax) { |
||
| 197 | \Msg::show(); |
||
| 198 | } elseif (!empty($_GET['redirectUrl'])) { |
||
| 199 | \Tools::redirect($_GET['redirectUrl'] . (!empty($_GET['dataManagerHash']) ? '#' . $_GET['dataManagerHash'] : '')); |
||
| 200 | } |
||
| 201 | $successId = $this->model->pk(); |
||
| 202 | } |
||
| 203 | } |
||
| 204 | } |
||
| 205 | if (!is_array($params) && is_callable($params)) { |
||
| 206 | $params($request); |
||
| 207 | } |
||
| 208 | } |
||
| 209 | return $successId; |
||
| 210 | } |
||
| 359 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths