| Conditions | 14 |
| Paths | 61 |
| Total Lines | 54 |
| Code Lines | 35 |
| Lines | 3 |
| Ratio | 5.56 % |
| 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 |
||
| 77 | public function renderElements($fieldset, $buttonsFieldset, $colMap = null, $buttonsSpan = null) |
||
| 78 | { |
||
| 79 | View Code Duplication | if ($fieldset instanceOf ViewPartialProviderInterface) { |
|
| 80 | return $this->getView()->partial($fieldset->getViewPartial(), [ 'element' => $fieldset, 'colMap' => $colMap, 'buttonsSpan' => $buttonsSpan ]); |
||
| 81 | } |
||
| 82 | |||
| 83 | if (true !== $buttonsFieldset && null === $colMap) { |
||
| 84 | $colMap = $fieldset->getColumnMap(); |
||
| 85 | } |
||
| 86 | |||
| 87 | $formElement = $this->getView()->plugin('formElement'); |
||
| 88 | $content = ''; $buttonsRendered = false; $i=0; |
||
| 89 | foreach ($fieldset as $element) { |
||
| 90 | if (true === $buttonsFieldset) { |
||
| 91 | $content .= $formElement($element); |
||
| 92 | continue; |
||
| 93 | } |
||
| 94 | |||
| 95 | if (isset($colMap[$element->getName()])) { |
||
| 96 | $cols = $colMap[$element->getName()]; |
||
| 97 | |||
| 98 | } else if (isset($colMap[$i])) { |
||
| 99 | $cols = $colMap[$i]; |
||
| 100 | |||
| 101 | } else { |
||
| 102 | $cols = $element->getOption('span') ?: 12; |
||
| 103 | } |
||
| 104 | |||
| 105 | if ($fieldset instanceOf TextSearchFormFieldset && $element->getName() == $fieldset->getButtonElement()) { |
||
| 106 | $content.='<div class="input-group col-md-' . $cols . '">' |
||
| 107 | . $formElement($element) |
||
| 108 | . '<div class="input-group-btn search-form-buttons" style="width: 0px;">' |
||
| 109 | . $this->renderElements($buttonsFieldset, true) . '</div>' |
||
| 110 | . '</div>'; |
||
| 111 | $buttonsRendered = true; |
||
| 112 | } else { |
||
| 113 | $content .= '<div class="input-group col-md-' . $cols . '">' |
||
| 114 | . $formElement($element) |
||
| 115 | . '</div>'; |
||
| 116 | } |
||
| 117 | |||
| 118 | $i += 1; |
||
| 119 | } |
||
| 120 | |||
| 121 | if (true !== $buttonsFieldset && !$buttonsRendered) { |
||
| 122 | if (null === $buttonsSpan) { |
||
| 123 | $buttonsSpan = $buttonsFieldset->getSpan(); |
||
| 124 | } |
||
| 125 | $content .= '<div class="input-group search-form-buttons col-md-' . $buttonsSpan . ' text-right">' |
||
| 126 | . '<div class="btn-group">' . $this->renderElements($buttonsFieldset, true) .'</div></div>'; |
||
| 127 | } |
||
| 128 | |||
| 129 | return $content; |
||
| 130 | } |
||
| 131 | } |
Let’s assume that you have a directory layout like this:
. |-- OtherDir | |-- Bar.php | `-- Foo.php `-- SomeDir `-- Foo.phpand let’s assume the following content of
Bar.php:If both files
OtherDir/Foo.phpandSomeDir/Foo.phpare loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.phpHowever, as
OtherDir/Foo.phpdoes not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: