Conditions | 37 |
Paths | > 20000 |
Total Lines | 156 |
Lines | 112 |
Ratio | 71.79 % |
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 |
||
154 | public function update(Request $request, $id) |
||
155 | { |
||
156 | $directory = Directory::find($id); |
||
157 | if (!$directory) { |
||
158 | throw new \UnexpectedValueException('the directory does not exist.', -10314); |
||
159 | } |
||
160 | |||
161 | $updValues = []; |
||
162 | |||
163 | $name = $request->input('name'); |
||
164 | View Code Duplication | if (isset($name)) { |
|
165 | if (!$name) { |
||
166 | throw new \UnexpectedValueException('the name can not be empty.', -10300); |
||
167 | } |
||
168 | $updValues['name'] = $name; |
||
169 | } |
||
170 | |||
171 | $configs = []; |
||
172 | |||
173 | $host = $request->input('host'); |
||
174 | View Code Duplication | if (isset($host)) { |
|
175 | if (!$host) { |
||
176 | throw new \UnexpectedValueException('the host can not be empty.', -10301); |
||
177 | } |
||
178 | $configs['host'] = $host; |
||
179 | } |
||
180 | |||
181 | $port = $request->input('port'); |
||
182 | View Code Duplication | if (isset($port)) { |
|
183 | if (!$port) { |
||
184 | throw new \UnexpectedValueException('the port can not be empty.', -10302); |
||
185 | } |
||
186 | $configs['port'] = intval($port); |
||
187 | } |
||
188 | |||
189 | $encryption = $request->input('encryption'); |
||
190 | if (isset($encryption)) { |
||
191 | $configs['encryption'] = $encryption; |
||
192 | } |
||
193 | |||
194 | $admin_username = $request->input('admin_username'); |
||
195 | View Code Duplication | if (isset($admin_username)) { |
|
196 | if (!$admin_username) { |
||
197 | throw new \UnexpectedValueException('the username can not be empty.', -10303); |
||
198 | } |
||
199 | $configs['admin_username'] = $admin_username; |
||
200 | } |
||
201 | |||
202 | $admin_password = $request->input('admin_password'); |
||
203 | View Code Duplication | if (isset($admin_password)) { |
|
204 | if (!$admin_password) { |
||
205 | throw new \UnexpectedValueException('the user password can not be empty.', -10304); |
||
206 | } |
||
207 | $configs['admin_password'] = $admin_password; |
||
208 | } |
||
209 | |||
210 | $base_dn = $request->input('base_dn'); |
||
211 | View Code Duplication | if (isset($base_dn)) { |
|
212 | if (!$base_dn) { |
||
213 | throw new \UnexpectedValueException('the base_dn can not be empty.', -10305); |
||
214 | } |
||
215 | $configs['base_dn'] = $base_dn; |
||
216 | } |
||
217 | |||
218 | $additional_user_dn = $request->input('additional_user_dn'); |
||
219 | if (isset($additional_user_dn)) { |
||
220 | $configs['additional_user_dn'] = $additional_user_dn; |
||
221 | } |
||
222 | |||
223 | $additional_group_dn = $request->input('additional_group_dn'); |
||
224 | if (isset($additional_group_dn)) { |
||
225 | $configs['additional_group_dn'] = $additional_group_dn; |
||
226 | } |
||
227 | |||
228 | $user_object_class = $request->input('user_object_class'); |
||
229 | View Code Duplication | if (isset($user_object_class)) { |
|
230 | if (!$user_object_class) { |
||
231 | throw new \UnexpectedValueException('the user object class can not be empty.', -10306); |
||
232 | } |
||
233 | $configs['user_object_class'] = $user_object_class; |
||
234 | } |
||
235 | |||
236 | $user_object_filter = $request->input('user_object_filter'); |
||
237 | View Code Duplication | if (isset($user_object_filter)) { |
|
238 | if (!$user_object_filter) { |
||
239 | throw new \UnexpectedValueException('the user object filter can not be empty.', -10307); |
||
240 | } |
||
241 | $configs['user_object_filter'] = $user_object_filter; |
||
242 | } |
||
243 | |||
244 | $user_name_attr = $request->input('user_name_attr'); |
||
245 | View Code Duplication | if (isset($user_name_attr)) { |
|
246 | if (!$user_name_attr) { |
||
247 | throw new \UnexpectedValueException('the user name attributte can not be empty.', -10308); |
||
248 | } |
||
249 | $configs['user_name_attr'] = $user_name_attr; |
||
250 | } |
||
251 | |||
252 | $user_email_attr = $request->input('user_email_attr'); |
||
253 | View Code Duplication | if (isset($user_email_attr)) { |
|
254 | if (!$user_email_attr) { |
||
255 | throw new \UnexpectedValueException('the user email attributte can not be empty.', -10309); |
||
256 | } |
||
257 | $configs['user_email_attr'] = $user_email_attr; |
||
258 | } |
||
259 | |||
260 | $group_object_class = $request->input('group_object_class'); |
||
261 | View Code Duplication | if (isset($group_object_class)) { |
|
262 | if (!$group_object_class) { |
||
263 | throw new \UnexpectedValueException('the group object class can not be empty.', -10310); |
||
264 | } |
||
265 | $configs['group_object_class'] = $group_object_class; |
||
266 | } |
||
267 | |||
268 | $group_object_filter = $request->input('group_object_filter'); |
||
269 | View Code Duplication | if (isset($group_object_filter)) { |
|
270 | if (!$group_object_filter) { |
||
271 | throw new \UnexpectedValueException('the group object filter can not be empty.', -10311); |
||
272 | } |
||
273 | $configs['group_object_filter'] = $group_object_filter; |
||
274 | } |
||
275 | |||
276 | $group_name_attr = $request->input('group_name_attr'); |
||
277 | View Code Duplication | if (isset($group_name_attr)) { |
|
278 | if (!$group_name_attr) { |
||
279 | throw new \UnexpectedValueException('the group name attributte can not be empty.', -10312); |
||
280 | } |
||
281 | $configs['group_name_attr'] = $group_name_attr; |
||
282 | } |
||
283 | |||
284 | $group_membership_attr = $request->input('group_membership_attr'); |
||
285 | View Code Duplication | if (isset($group_membership_attr)) { |
|
286 | if (!$group_membership_attr) { |
||
287 | throw new \UnexpectedValueException('the group membership attributte can not be empty.', -10313); |
||
288 | } |
||
289 | $configs['group_membership_attr'] = $group_membership_attr; |
||
290 | } |
||
291 | |||
292 | if ($configs) { |
||
293 | $updValues['configs'] = isset($directory->configs) ? array_merge($directory->configs ?: [], $configs) : $configs; |
||
294 | } |
||
295 | |||
296 | $invalid_flag = $request->input('invalid_flag'); |
||
297 | if (isset($invalid_flag)) { |
||
298 | $updValues['invalid_flag'] = intval($invalid_flag); |
||
299 | } |
||
300 | |||
301 | $directory->fill($updValues)->save(); |
||
302 | |||
303 | //if (isset($invalid_flag)) |
||
304 | //{ |
||
305 | // EloquentUser::where('directory', $id)->update([ 'invalid_flag' => intval($invalid_flag) ]); |
||
306 | //} |
||
307 | |||
308 | return $this->show($id); |
||
309 | } |
||
310 | |||
405 |
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: