| Conditions | 13 |
| Paths | 528 |
| Total Lines | 116 |
| Code Lines | 87 |
| 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 |
||
| 35 | function drawParam($param, $form, $models, $objects, $parent = 0) { |
||
| 36 | $selectArrays = []; |
||
| 37 | $objectsCols = []; |
||
| 38 | |||
| 39 | if (!isset($selectArrays[$param->object->migration_id])) { |
||
| 40 | $selectArrays[$param->object->migration_id] = Migrations\Migration\Object::getList(['where' => ['migration_id', $param->object->migration_id], 'forSelect' => true]); |
||
| 41 | |||
| 42 | $selectArrays[$param->object->migration_id] = [ |
||
| 43 | '' => 'Выберите', |
||
| 44 | 'continue' => 'Пропустить', |
||
| 45 | 'container' => 'Контейнер' |
||
| 46 | ] + $selectArrays[$param->object->migration_id]; |
||
| 47 | } |
||
| 48 | |||
| 49 | if (empty($objectsCols[$param->object_id])) { |
||
| 50 | $modelName = $param->object->model; |
||
| 51 | foreach (array_keys($modelName::$cols) as $colName) { |
||
| 52 | $objectsCols[$param->object_id][$colName] = !empty($modelName::$labels[$colName]) ? $modelName::$labels[$colName] : $colName; |
||
| 53 | } |
||
| 54 | } |
||
| 55 | $modelName = $param->object->model; |
||
| 56 | $relations = []; |
||
| 57 | foreach ($modelName::relations() as $relName => $relation) { |
||
| 58 | $relations[$relName] = $relName; |
||
| 59 | } |
||
| 60 | if ($parent) { |
||
| 61 | $parserName = '\Migrations\Parser\Object\\' . ucfirst($parent->type); |
||
| 62 | $parser = new $parserName; |
||
| 63 | $parser->param = $parent; |
||
| 64 | $values = $parser->editor(); |
||
| 65 | } else { |
||
| 66 | $values = [ |
||
| 67 | '' => 'Выберите', |
||
| 68 | 'continue' => 'Пропустить', |
||
| 69 | 'item_key' => 'Ключ элемента', |
||
| 70 | 'paramsList' => 'Список параметров', |
||
| 71 | 'param' => 'Параметр', |
||
| 72 | 'value' => [ |
||
| 73 | 'text' => 'Значение', |
||
| 74 | 'input' => [ |
||
| 75 | 'name' => 'paramOptions[' . $param->id . ']', |
||
| 76 | 'type' => 'select', |
||
| 77 | 'source' => 'array', |
||
| 78 | 'sourceArray' => $objectsCols[$param->object_id], |
||
| 79 | 'options' => [ |
||
| 80 | 'value' => $param->type == 'value' ? $param->value : '' |
||
| 81 | ] |
||
| 82 | ] |
||
| 83 | ], |
||
| 84 | 'relation' => [ |
||
| 85 | 'text' => 'Зависимость', |
||
| 86 | 'input' => [ |
||
| 87 | 'name' => 'paramOptions[' . $param->id . ']', |
||
| 88 | 'type' => 'select', |
||
| 89 | 'source' => 'array', |
||
| 90 | 'sourceArray' => $relations, |
||
| 91 | 'options' => [ |
||
| 92 | 'value' => $param->type == 'relation' ? $param->value : '' |
||
| 93 | ] |
||
| 94 | ] |
||
| 95 | ], |
||
| 96 | 'object' => [ |
||
| 97 | 'text' => 'Объект', |
||
| 98 | 'input' => [ |
||
| 99 | 'name' => 'paramOptions[' . $param->id . ']', |
||
| 100 | 'type' => 'select', |
||
| 101 | 'source' => 'array', |
||
| 102 | 'sourceArray' => $selectArrays[$param->object->migration_id], |
||
| 103 | 'options' => [ |
||
| 104 | 'value' => $param->type == 'object' ? $param->value : '' |
||
| 105 | ] |
||
| 106 | ] |
||
| 107 | ], |
||
| 108 | 'objectLink' => [ |
||
| 109 | 'text' => 'Ссылка на объект', |
||
| 110 | 'input' => [ |
||
| 111 | 'name' => 'paramOptions[' . $param->id . ']', |
||
| 112 | 'type' => 'select', |
||
| 113 | 'source' => 'array', |
||
| 114 | 'sourceArray' => $selectArrays[$param->object->migration_id], |
||
| 115 | 'options' => [ |
||
| 116 | 'value' => $param->type == 'objectLink' ? $param->value : '' |
||
| 117 | ] |
||
| 118 | ] |
||
| 119 | ], |
||
| 120 | 'newObject' => [ |
||
| 121 | 'text' => 'Новый объект', |
||
| 122 | 'input' => [ |
||
| 123 | 'name' => 'paramOptions[' . $param->id . ']', |
||
| 124 | 'type' => 'select', |
||
| 125 | 'source' => 'array', |
||
| 126 | 'sourceArray' => $models, |
||
| 127 | 'options' => [ |
||
| 128 | 'value' => $param->type == 'newObject' ? $param->value : '' |
||
| 129 | ] |
||
| 130 | ] |
||
| 131 | ], |
||
| 132 | 'custom' => [ |
||
| 133 | 'text' => 'Свой класс обработки', |
||
| 134 | 'input' => [ |
||
| 135 | 'name' => 'paramOptions[' . $param->id . ']', |
||
| 136 | 'type' => 'text', |
||
| 137 | 'options' => [ |
||
| 138 | 'value' => $param->value |
||
| 139 | ] |
||
| 140 | ] |
||
| 141 | ] |
||
| 142 | ]; |
||
| 143 | } |
||
| 144 | $form->input('select', 'param[' . $param->id . ']', $param->code, ['values' => $values, |
||
| 145 | 'value' => $param->type |
||
| 146 | ]); |
||
| 147 | foreach ($param->childs as $child) { |
||
| 148 | echo '<div class="col-xs-offset-1">'; |
||
| 149 | drawParam($child, $form, $models, $objects, $param); |
||
| 150 | echo '</div>'; |
||
| 151 | } |
||
| 164 |