Conditions | 16 |
Paths | 64 |
Total Lines | 65 |
Code Lines | 49 |
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 |
||
13 | public function searchAction() { |
||
14 | $result = new Server\Result(); |
||
15 | $searchString = filter_input(INPUT_GET, 'search', FILTER_SANITIZE_STRING); |
||
16 | $searchString = trim(preg_replace('![^A-zА-я0-9@-_\. ]!iSu', ' ', urldecode($searchString))); |
||
17 | if (!$searchString) { |
||
18 | $result->content = []; |
||
19 | $result->send(); |
||
20 | } |
||
21 | try { |
||
22 | $modelName = trim(filter_input(INPUT_GET, 'modelName', FILTER_SANITIZE_STRING)); |
||
23 | if (!$modelName) { |
||
24 | throw new Exception('Не указана модель'); |
||
25 | } |
||
26 | $model = new $modelName; |
||
27 | if (!$model || !is_subclass_of($model, 'Model')) { |
||
28 | throw new Exception('Модель не найдена'); |
||
29 | } |
||
30 | $formName = trim(filter_input(INPUT_GET, 'formName', FILTER_SANITIZE_STRING)); |
||
31 | if (!$formName) { |
||
32 | throw new Exception('Не указано название формы'); |
||
33 | } |
||
34 | if (empty($modelName::$forms[$formName])) { |
||
35 | throw new Exception('Не существует указанной формы'); |
||
36 | } |
||
37 | $activeForm = new Ui\ActiveForm($model, $formName); |
||
38 | $inputs = $activeForm->getInputs(); |
||
39 | $inputName = trim(filter_input(INPUT_GET, 'inputName', FILTER_SANITIZE_STRING)); |
||
40 | if (empty($inputs[$inputName])) { |
||
41 | throw new Exception('У формы нет такого поля'); |
||
42 | } |
||
43 | } catch (Exception $exc) { |
||
44 | $result->success = false; |
||
45 | $result->content = $exc->getMessage(); |
||
46 | return $result->send(); |
||
47 | } |
||
48 | $options = [ |
||
49 | 'where' => [ |
||
50 | ] |
||
51 | ]; |
||
52 | |||
53 | $searchArr = []; |
||
54 | foreach (explode(' ', $searchString) as $part) { |
||
55 | $colWhere = []; |
||
56 | $first = true; |
||
57 | foreach ($inputs[$inputName]['cols'] as $col) { |
||
58 | $part = trim($part); |
||
59 | if ($part && strlen($part) > 2) { |
||
60 | $colWhere[] = [$col, '%' . $part . '%', 'LIKE', $first ? 'AND' : 'OR']; |
||
61 | $first = false; |
||
62 | } |
||
63 | } |
||
64 | if ($colWhere) { |
||
65 | $searchArr[] = $colWhere; |
||
66 | } |
||
67 | } |
||
68 | if ($searchArr) { |
||
69 | $options['where'][] = $searchArr; |
||
70 | } else { |
||
71 | $result->content = []; |
||
72 | $result->send(); |
||
73 | } |
||
74 | $list = $activeForm->getOptionsList($inputs[$inputName], ['noEmptyValue' => true], $modelName, 'aditional', $options,$model); |
||
|
|||
75 | $result->content = $list; |
||
76 | $result->send(); |
||
77 | } |
||
78 | |||
80 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: