Conditions | 10 |
Paths | 32 |
Total Lines | 51 |
Code Lines | 35 |
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 |
||
81 | public function getHTML() : string |
||
82 | { |
||
83 | $this->processFlags(); |
||
84 | |||
85 | $strSelect = $this->oFG->getData()->getValue($this->strName); |
||
86 | $aOptions = $this->aOptions ?: $this->oFG->getData()->getSelectOptions($this->strName); |
||
87 | |||
88 | $strWidth = ($this->oParent ? $this->oParent->getColWidth($this->iCol) : ''); |
||
89 | $strHTML = ''; |
||
90 | $strHTML .= ' '; |
||
91 | $strHTML .= '<div style="float: left; position: relative;'; |
||
92 | if (!empty($strWidth)) { |
||
93 | $strHTML .= ' width: ' . $strWidth . ';'; |
||
94 | } |
||
95 | $strHTML .= '">'; |
||
96 | if ($this->oFlags->isSet(FormFlags::SELECT_BTN)) { |
||
97 | $strHTML .= '<button class="sbBtn">' . $this->strSelectBtnText . '</button>'; |
||
98 | } |
||
99 | $strHTML .= '<select'; |
||
100 | $strHTML .= ' class="' . $this->strClass . '"'; |
||
101 | $strHTML .= ' name="' . $this->strName . '"'; |
||
102 | $strHTML .= ' id="' . $this->strName . '"'; |
||
103 | if ($this->size > 0) { |
||
104 | $strHTML .= ' size="' . $this->size . '"'; |
||
105 | } |
||
106 | $strHTML .= $this->buildStyle(); |
||
107 | $strHTML .= $this->buildAttributes(); |
||
108 | $strHTML .= $this->buildTabindex(); |
||
109 | $strHTML .= '>' . PHP_EOL; |
||
110 | |||
111 | if (count($aOptions) > 0) { |
||
112 | foreach ($aOptions as $strOption => $strValue) { |
||
113 | $strHTML .= ' '; |
||
114 | $strHTML .= '<option '; |
||
115 | if ($strValue == $strSelect) { |
||
116 | $strHTML .= 'selected '; |
||
117 | } |
||
118 | if (strlen($strOption) == 0) { |
||
119 | // to prevent HTML5 validation error "Element option without attribute label must not be empty." |
||
120 | $strOption = ' '; |
||
121 | } |
||
122 | $strHTML .= 'value="' . $strValue . '">' . $strOption . '</option>' . PHP_EOL; |
||
123 | } |
||
124 | } else { |
||
125 | // dropdown selectlist without options... |
||
126 | trigger_error('empty select options set!', E_USER_NOTICE); |
||
127 | } |
||
128 | |||
129 | $strHTML .= ' </select></div>' . PHP_EOL; |
||
130 | |||
131 | return $strHTML; |
||
132 | } |
||
158 |