| Conditions | 9 |
| Paths | 1 |
| Total Lines | 114 |
| Code Lines | 62 |
| Lines | 0 |
| Ratio | 0 % |
| 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 |
||
| 45 | public function behaviors() |
||
| 46 | { |
||
| 47 | return [ |
||
| 48 | 'fields' => [ |
||
| 49 | 'class' => Behavior::class, |
||
| 50 | 'module' => 'import', |
||
| 51 | 'fields' => [ |
||
| 52 | 'import_settings_set_id' => [ |
||
| 53 | 'class' => Hidden::class, |
||
| 54 | 'attribute' => 'import_settings_set_id', |
||
| 55 | ], |
||
| 56 | 'type' => [ |
||
| 57 | 'class' => DropDown::class, |
||
| 58 | 'attribute' => 'type', |
||
| 59 | 'field' => [ |
||
| 60 | 'options' => [ |
||
| 61 | 'style' => 'width: 100px', |
||
| 62 | ] |
||
| 63 | ], |
||
| 64 | 'data' => function () { |
||
| 65 | return self::getAttributesValuesTypesList(); |
||
| 66 | }, |
||
| 67 | ], |
||
| 68 | 'column_nbr' => [ |
||
| 69 | 'class' => NumberField::class, |
||
| 70 | 'attribute' => 'column_nbr', |
||
| 71 | ], |
||
| 72 | 'number_delimiter' => [ |
||
| 73 | 'attribute' => 'number_delimiter', |
||
| 74 | 'required' => true, |
||
| 75 | 'defaultValue' => ',', |
||
| 76 | ], |
||
| 77 | 'value_string' => [ |
||
| 78 | 'attribute' => 'value_string', |
||
| 79 | ], |
||
| 80 | 'value_option' => [ |
||
| 81 | 'class' => HasOneSelect2::class, |
||
| 82 | 'attribute' => 'value_option', |
||
| 83 | 'nameParam' => 'name', |
||
| 84 | // 'relation' => 'dictionariesData', |
||
| 85 | 'data' => function () { |
||
| 86 | if (!$this->settingsSet || !$this->settingsSet->settingsSheet || !$this->settingsSet->settingsSheet->settingsSets) { |
||
|
|
|||
| 87 | return []; |
||
| 88 | } |
||
| 89 | $dictionaryOptions = ['' => '']; |
||
| 90 | $types = SettingsSheet::getDictionaries(); |
||
| 91 | // return []; |
||
| 92 | foreach ($this->settingsSet->settingsSheet->settingsSets as $settingsSet) { |
||
| 93 | foreach ($settingsSet->settingsValues as $value) { |
||
| 94 | $type = explode('.', $value->type)[0]; |
||
| 95 | if (!empty($types[$type]) && !empty($value->value_option)) { |
||
| 96 | if ($model = $types[$type]->byId($value->value_option)->one()) { |
||
| 97 | $dictionaryOptions[$model->id] = $model->name; |
||
| 98 | } |
||
| 99 | } |
||
| 100 | } |
||
| 101 | } |
||
| 102 | |||
| 103 | return $dictionaryOptions; |
||
| 104 | }, |
||
| 105 | 'isNoRenderRelationLink' => true, |
||
| 106 | 'widgetOptions' => [ |
||
| 107 | 'url' => ['get-dictionaries'], |
||
| 108 | 'pluginOptions' => [ |
||
| 109 | 'width' => 'auto', |
||
| 110 | 'ajax' => [ |
||
| 111 | 'data' => new JsExpression(<<<JS |
||
| 112 | function(params) { |
||
| 113 | var currentType = $(this).parents('.multiple-input-list__item:first').find('.list-cell__type select').val(); |
||
| 114 | return { |
||
| 115 | name: params.term, |
||
| 116 | type: currentType, |
||
| 117 | page: params.page |
||
| 118 | }; |
||
| 119 | } |
||
| 120 | JS |
||
| 121 | ), |
||
| 122 | ], |
||
| 123 | ], |
||
| 124 | ], |
||
| 125 | // 'data' => [], |
||
| 126 | // 'options' => [ |
||
| 127 | // 'initValueText' => $dictionaryOptions, |
||
| 128 | // 'options' => [ |
||
| 129 | // 'placeholder' => 'Dictionary' |
||
| 130 | // ], |
||
| 131 | // 'pluginOptions' => [ |
||
| 132 | // 'allowClear' => true, |
||
| 133 | // 'ajax' => [ |
||
| 134 | // 'url' => $getDictionariesUrl, |
||
| 135 | // 'dataType' => 'json', |
||
| 136 | // 'data' => new JsExpression(<<<JS |
||
| 137 | //function(params) { |
||
| 138 | // var currentType = $(this).parents('.multiple-input-list__item:first').find('.list-cell__type select').val(); |
||
| 139 | // return { |
||
| 140 | // name: params.term, |
||
| 141 | // type: currentType |
||
| 142 | // }; |
||
| 143 | //} |
||
| 144 | //JS |
||
| 145 | // ) |
||
| 146 | // ], |
||
| 147 | // ], |
||
| 148 | // ], |
||
| 149 | // 'enableError' => true, |
||
| 150 | ], |
||
| 151 | ], |
||
| 152 | // 'plugins' => \yii::$app->getModule('import')->getSettingsSetsCrudFieldsPlugins(), |
||
| 153 | ], |
||
| 154 | 'date' => [ |
||
| 155 | 'class' => TimestampBehavior::class, |
||
| 156 | 'createdAtAttribute' => 'created', |
||
| 157 | 'updatedAtAttribute' => 'updated', |
||
| 158 | 'value' => new Expression('NOW()'), |
||
| 159 | ], |
||
| 203 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)or! empty(...)instead.