Conditions | 6 |
Paths | 8 |
Total Lines | 287 |
Code Lines | 159 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
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 |
||
279 | protected function viewConfiguration() |
||
280 | { |
||
281 | /* ----------------------------------------------- |
||
282 | * Populating fields array |
||
283 | * ----------------------------------------------- |
||
284 | */ |
||
285 | |||
286 | $fields = isset($_POST['fields']) ? $_POST['fields'] : $this->_params['default-config']; |
||
287 | |||
288 | /* ----------------------------------------------- |
||
289 | * Welcome |
||
290 | * ----------------------------------------------- |
||
291 | */ |
||
292 | |||
293 | $div = new XMLElement('div'); |
||
294 | $div->appendChild( |
||
295 | new XMLElement('h2', __('Find something sturdy to hold on to because things are about to get awesome.')) |
||
296 | ); |
||
297 | $div->appendChild( |
||
298 | new XMLElement( |
||
299 | 'p', |
||
300 | __('Think of this as a pre-game warm up. You know you’re going to kick-ass, so you’re savouring every moment before the show. Welcome to the Symphony install page.') |
||
301 | ) |
||
302 | ); |
||
303 | |||
304 | $this->Form->appendChild($div); |
||
305 | |||
306 | if (!empty($this->_params['errors'])) { |
||
307 | $this->Form->appendChild( |
||
308 | Widget::Error( |
||
309 | new XMLElement('p'), |
||
310 | __('Oops, a minor hurdle on your path to glory! There appears to be something wrong with the details entered below.') |
||
311 | ) |
||
312 | ); |
||
313 | } |
||
314 | |||
315 | /* ----------------------------------------------- |
||
316 | * Environment settings |
||
317 | * ----------------------------------------------- |
||
318 | */ |
||
319 | |||
320 | $fieldset = new XMLElement('fieldset'); |
||
321 | $div = new XMLElement('div'); |
||
322 | $this->__appendError(array('no-write-permission-root', 'no-write-permission-workspace'), $div); |
||
323 | if ($div->getNumberOfChildren() > 0) { |
||
324 | $fieldset->appendChild($div); |
||
325 | $this->Form->appendChild($fieldset); |
||
326 | } |
||
327 | |||
328 | /* ----------------------------------------------- |
||
329 | * Website & Locale settings |
||
330 | * ----------------------------------------------- |
||
331 | */ |
||
332 | |||
333 | $Environment = new XMLElement('fieldset'); |
||
334 | $Environment->appendChild(new XMLElement('legend', __('Website Preferences'))); |
||
335 | |||
336 | $label = Widget::Label( |
||
337 | __('Name'), |
||
338 | Widget::Input('fields[general][sitename]', $fields['general']['sitename']) |
||
339 | ); |
||
340 | |||
341 | $this->__appendError(array('general-no-sitename'), $label); |
||
342 | $Environment->appendChild($label); |
||
343 | |||
344 | $label = Widget::Label( |
||
345 | __('Admin Path'), |
||
346 | Widget::Input('fields[symphony][admin-path]', $fields['symphony']['admin-path']) |
||
347 | ); |
||
348 | |||
349 | $this->__appendError(array('no-symphony-path'), $label); |
||
350 | $Environment->appendChild($label); |
||
351 | |||
352 | $Fieldset = new XMLElement('fieldset', null, array('class' => 'frame')); |
||
353 | $Fieldset->appendChild(new XMLElement('legend', __('Date and Time'))); |
||
354 | $Fieldset->appendChild(new XMLElement( |
||
355 | 'p', |
||
356 | __('Customise how Date and Time values are displayed throughout the Administration interface.') |
||
357 | )); |
||
358 | |||
359 | // Timezones |
||
360 | $options = DateTimeObj::getTimezonesSelectOptions(( |
||
361 | isset($fields['region']['timezone']) && !empty($fields['region']['timezone']) |
||
362 | ? $fields['region']['timezone'] |
||
363 | : date_default_timezone_get() |
||
364 | )); |
||
365 | $Fieldset->appendChild(Widget::Label(__('Region'), Widget::Select('fields[region][timezone]', $options))); |
||
366 | |||
367 | // Date formats |
||
368 | $options = DateTimeObj::getDateFormatsSelectOptions($fields['region']['date_format']); |
||
369 | $Fieldset->appendChild(Widget::Label( |
||
370 | __('Date Format'), |
||
371 | Widget::Select('fields[region][date_format]', $options) |
||
372 | )); |
||
373 | |||
374 | // Time formats |
||
375 | $options = DateTimeObj::getTimeFormatsSelectOptions($fields['region']['time_format']); |
||
376 | $Fieldset->appendChild(Widget::Label( |
||
377 | __('Time Format'), |
||
378 | Widget::Select('fields[region][time_format]', $options) |
||
379 | )); |
||
380 | |||
381 | $Environment->appendChild($Fieldset); |
||
382 | $this->Form->appendChild($Environment); |
||
383 | |||
384 | /* ----------------------------------------------- |
||
385 | * Database settings |
||
386 | * ----------------------------------------------- |
||
387 | */ |
||
388 | |||
389 | $Database = new XMLElement('fieldset'); |
||
390 | $Database->appendChild(new XMLElement('legend', __('Database Connection'))); |
||
391 | $Database->appendChild(new XMLElement('p', __('Please provide Symphony with access to a database.'))); |
||
392 | |||
393 | // Database name |
||
394 | $label = Widget::Label(__('Database'), Widget::Input('fields[database][db]', $fields['database']['db'])); |
||
395 | |||
396 | $this->__appendError(array('database-incorrect-version', 'unknown-database'), $label); |
||
397 | $Database->appendChild($label); |
||
398 | |||
399 | // Database credentials |
||
400 | $Div = new XMLElement('div', null, array('class' => 'two columns')); |
||
401 | $Div->appendChild(Widget::Label( |
||
402 | __('Username'), |
||
403 | Widget::Input('fields[database][user]', $fields['database']['user']), |
||
404 | 'column' |
||
405 | )); |
||
406 | $Div->appendChild(Widget::Label( |
||
407 | __('Password'), |
||
408 | Widget::Input('fields[database][password]', $fields['database']['password'], 'password'), |
||
409 | 'column' |
||
410 | )); |
||
411 | |||
412 | $this->__appendError(array('database-invalid-credentials'), $Div); |
||
413 | $Database->appendChild($Div); |
||
414 | |||
415 | // Advanced configuration |
||
416 | $Fieldset = new XMLElement('fieldset', null, array('class' => 'frame')); |
||
417 | $Fieldset->appendChild(new XMLElement('legend', __('Advanced Configuration'))); |
||
418 | $Fieldset->appendChild(new XMLElement( |
||
419 | 'p', |
||
420 | __('Leave these fields unless you are sure they need to be changed.') |
||
421 | )); |
||
422 | |||
423 | // Advanced configuration: Host, Port |
||
424 | $Div = new XMLElement('div', null, array('class' => 'two columns')); |
||
425 | $Div->appendChild(Widget::Label( |
||
426 | __('Host'), |
||
427 | Widget::Input('fields[database][host]', $fields['database']['host']), |
||
428 | 'column' |
||
429 | )); |
||
430 | $Div->appendChild(Widget::Label( |
||
431 | __('Port'), |
||
432 | Widget::Input('fields[database][port]', $fields['database']['port']), |
||
433 | 'column' |
||
434 | )); |
||
435 | |||
436 | $this->__appendError(array('no-database-connection'), $Div); |
||
437 | $Fieldset->appendChild($Div); |
||
438 | |||
439 | // Advanced configuration: Table Prefix |
||
440 | $label = Widget::Label( |
||
441 | __('Table Prefix'), |
||
442 | Widget::Input('fields[database][tbl_prefix]', $fields['database']['tbl_prefix']) |
||
443 | ); |
||
444 | |||
445 | $this->__appendError(array('database-table-prefix'), $label); |
||
446 | $Fieldset->appendChild($label); |
||
447 | |||
448 | $Database->appendChild($Fieldset); |
||
449 | $this->Form->appendChild($Database); |
||
450 | |||
451 | /* ----------------------------------------------- |
||
452 | * Permission settings |
||
453 | * ----------------------------------------------- |
||
454 | */ |
||
455 | |||
456 | $Permissions = new XMLElement('fieldset'); |
||
457 | $Permissions->appendChild(new XMLElement('legend', __('Permission Settings'))); |
||
458 | $Permissions->appendChild(new XMLElement( |
||
459 | 'p', |
||
460 | __('Set the permissions Symphony uses when saving files/directories.') |
||
461 | )); |
||
462 | |||
463 | $Div = new XMLElement('div', null, array('class' => 'two columns')); |
||
464 | $Div->appendChild(Widget::Label( |
||
465 | __('Files'), |
||
466 | Widget::Input('fields[file][write_mode]', $fields['file']['write_mode']), |
||
467 | 'column' |
||
468 | )); |
||
469 | $Div->appendChild(Widget::Label( |
||
470 | __('Directories'), |
||
471 | Widget::Input('fields[directory][write_mode]', $fields['directory']['write_mode']), |
||
472 | 'column' |
||
473 | )); |
||
474 | |||
475 | $Permissions->appendChild($Div); |
||
476 | $this->Form->appendChild($Permissions); |
||
477 | |||
478 | /* ----------------------------------------------- |
||
479 | * User settings |
||
480 | * ----------------------------------------------- |
||
481 | */ |
||
482 | |||
483 | $User = new XMLElement('fieldset'); |
||
484 | $User->appendChild(new XMLElement('legend', __('User Information'))); |
||
485 | $User->appendChild(new XMLElement( |
||
486 | 'p', |
||
487 | __('Once installation is complete, you will be able to log in to the Symphony admin area with these user details.') |
||
488 | )); |
||
489 | |||
490 | // Username |
||
491 | $label = Widget::Label( |
||
492 | __('Username'), |
||
493 | Widget::Input('fields[user][username]', $fields['user']['username']) |
||
494 | ); |
||
495 | |||
496 | $this->__appendError(array('user-no-username'), $label); |
||
497 | $User->appendChild($label); |
||
498 | |||
499 | // Password |
||
500 | $Div = new XMLElement('div', null, array('class' => 'two columns')); |
||
501 | $Div->appendChild(Widget::Label( |
||
502 | __('Password'), |
||
503 | Widget::Input('fields[user][password]', $fields['user']['password'], 'password'), |
||
504 | 'column' |
||
505 | )); |
||
506 | $Div->appendChild(Widget::Label( |
||
507 | __('Confirm Password'), |
||
508 | Widget::Input('fields[user][confirm-password]', $fields['user']['confirm-password'], 'password'), |
||
509 | 'column' |
||
510 | )); |
||
511 | |||
512 | $this->__appendError(array('user-no-password', 'user-password-mismatch'), $Div); |
||
513 | $User->appendChild($Div); |
||
514 | |||
515 | // Personal information |
||
516 | $Fieldset = new XMLElement('fieldset', null, array('class' => 'frame')); |
||
517 | $Fieldset->appendChild(new XMLElement('legend', __('Personal Information'))); |
||
518 | $Fieldset->appendChild(new XMLElement('p', __('Please add the following personal details for this user.'))); |
||
519 | |||
520 | // Personal information: First Name, Last Name |
||
521 | $Div = new XMLElement('div', null, array('class' => 'two columns')); |
||
522 | $Div->appendChild(Widget::Label( |
||
523 | __('First Name'), |
||
524 | Widget::Input('fields[user][firstname]', $fields['user']['firstname']), |
||
525 | 'column' |
||
526 | )); |
||
527 | $Div->appendChild(Widget::Label( |
||
528 | __('Last Name'), |
||
529 | Widget::Input('fields[user][lastname]', $fields['user']['lastname']), |
||
530 | 'column' |
||
531 | )); |
||
532 | |||
533 | $this->__appendError(array('user-no-name'), $Div); |
||
534 | $Fieldset->appendChild($Div); |
||
535 | |||
536 | // Personal information: Email Address |
||
537 | $label = Widget::Label(__('Email Address'), Widget::Input('fields[user][email]', $fields['user']['email'])); |
||
538 | |||
539 | $this->__appendError(array('user-invalid-email'), $label); |
||
540 | $Fieldset->appendChild($label); |
||
541 | |||
542 | $User->appendChild($Fieldset); |
||
543 | $this->Form->appendChild($User); |
||
544 | |||
545 | /* ----------------------------------------------- |
||
546 | * Submit area |
||
547 | * ----------------------------------------------- |
||
548 | */ |
||
549 | |||
550 | $this->Form->appendChild(new XMLElement('h2', __('Install Symphony'))); |
||
551 | $this->Form->appendChild(new XMLElement( |
||
552 | 'p', |
||
553 | __( |
||
554 | 'The installation process goes by really quickly. Make sure to take a deep breath before you press that sweet button.', |
||
555 | array('<code>' . basename(INSTALL_URL) . '</code>') |
||
556 | ) |
||
557 | )); |
||
558 | |||
559 | $Submit = new XMLElement('div', null, array('class' => 'submit')); |
||
560 | $Submit->appendChild(Widget::Input('lang', Lang::get(), 'hidden')); |
||
561 | |||
562 | $Submit->appendChild(Widget::Input('action[install]', __('Install Symphony'), 'submit')); |
||
563 | |||
564 | $this->Form->appendChild($Submit); |
||
565 | } |
||
566 | } |
||
567 |
If you define a variable conditionally, it can happen that it is not defined for all execution paths.
Let’s take a look at an example:
In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.
Available Fixes
Check for existence of the variable explicitly:
Define a default value for the variable:
Add a value for the missing path: