Conditions | 16 |
Paths | 36 |
Total Lines | 68 |
Code Lines | 44 |
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 |
||
111 | public function getOptions() |
||
112 | { |
||
113 | // get model, model configuration interface, model logic |
||
114 | $model = $this->getModel(); |
||
115 | $section = \AdminSection::getModel($this->getModel()); |
||
116 | $payload = $section->getPayload(); |
||
117 | $form_element_controller = new FormElementController(); |
||
118 | $form = $form_element_controller->getModelLogicPayload($section, $model->id, $payload); |
||
119 | |||
120 | if ($form instanceof FormInterface) { |
||
121 | // if defined: get values of the depends form fields |
||
122 | $depends = json_decode($this->getDataDepends(), true); |
||
123 | if (is_array($depends) && count($depends)) { |
||
124 | $data_depends = []; |
||
125 | foreach ($depends as $depend) { |
||
126 | $temp_element = $form->getElement($depend); |
||
127 | $depend_value = null; |
||
128 | if (mb_strpos($depend, '.')) { |
||
129 | $parts = explode('.', $depend); |
||
130 | $fieldName = array_pop($parts); |
||
131 | $relationName = implode('.', $parts); |
||
132 | if (! $model->relationLoaded($relationName)) { |
||
133 | $model->load($relationName); |
||
134 | } |
||
135 | $temp = $model; |
||
136 | $temp_fail = false; |
||
137 | foreach ($parts as $part) { |
||
138 | $temp = $temp->{$part}; |
||
139 | if (! $temp) { |
||
140 | $temp_fail = true; |
||
141 | break; |
||
142 | } |
||
143 | } |
||
144 | if (! $temp_fail) { |
||
145 | $depend_value = $temp->{$fieldName}; |
||
146 | } |
||
147 | } else { |
||
148 | $depend_value = $model->{$depend}; |
||
149 | } |
||
150 | if (! $depend_value) { |
||
151 | $depend_value = $temp_element->getDefaultValue(); |
||
152 | } |
||
153 | $data_depends[$depend] = $depend_value; |
||
154 | } |
||
155 | $this->setAjaxParameters($data_depends); |
||
156 | } |
||
157 | } |
||
158 | |||
159 | // if defined: get model for options via callback |
||
160 | if (is_callable($callback = $callback = $this->getModelForOptionsCallback())) { |
||
161 | $result = $callback($this); |
||
162 | if ($result) { |
||
163 | $this->setModelForOptions($result); |
||
164 | } |
||
165 | } |
||
166 | |||
167 | if (! is_null($this->getModelForOptions()) && ! is_null($this->getDisplay())) { |
||
168 | $this->setOptions( |
||
169 | $this->loadOptions() |
||
170 | ); |
||
171 | } |
||
172 | |||
173 | $options = Arr::except($this->options, $this->exclude); |
||
174 | if ($this->isSortable()) { |
||
175 | asort($options, $this->getSortableFlags()); |
||
176 | } |
||
177 | |||
178 | return $options; |
||
179 | } |
||
266 |