| Conditions | 19 |
| Paths | 51 |
| Total Lines | 68 |
| Code Lines | 56 |
| Lines | 0 |
| Ratio | 0 % |
| 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 declare(strict_types=1); |
||
| 101 | public function displayParam(array $vals = []): ?string |
||
| 102 | { |
||
| 103 | $controltype = $this->controltype; |
||
| 104 | $fieldlength = $this->maxlength; |
||
|
|
|||
| 105 | |||
| 106 | if (!empty($vals) && isset($vals[$this->fieldname])) { |
||
| 107 | if (\is_array($vals[$this->fieldname])) { |
||
| 108 | $this->values = $vals[$this->fieldname][0]; |
||
| 109 | $this->value = $vals[$this->fieldname][1]; |
||
| 110 | } else { |
||
| 111 | $this->value = $vals[$this->fieldname]; |
||
| 112 | } |
||
| 113 | } |
||
| 114 | |||
| 115 | switch ($controltype) { |
||
| 116 | case \XHELP_CONTROL_TXTBOX: |
||
| 117 | return "<label for='" . $this->fieldname . "'>" . $this->name . '</label>' . "<input type='text' name='" . $this->fieldname . "' id='" . $this->fieldname . "' value='" . $this->value . "' maxlength='" . $this->maxlength . "' size='" . $this->fieldlength . "'>"; |
||
| 118 | case \XHELP_CONTROL_TXTAREA: |
||
| 119 | return "<label for='" . $this->fieldname . "'>" . $this->name . '</label>' . "<textarea name='" . $this->fieldname . "' id='" . $this->fieldname . "' cols='" . $this->fieldlength . "' rows='5'>" . $this->value . '</textarea>'; |
||
| 120 | case \XHELP_CONTROL_SELECT: |
||
| 121 | $ret = "<label for='" . $this->fieldname . "'>" . $this->name . '</label>' . "<select name='" . $this->fieldname . "' id='" . $this->fieldname . "' size='1'>"; |
||
| 122 | foreach ($this->values as $key => $value) { |
||
| 123 | $ret .= "<option value='" . $key . "' " . (($this->value == $key) ? 'selected' : '') . '>' . $value . '</option>'; |
||
| 124 | } |
||
| 125 | $ret .= '</select>'; |
||
| 126 | |||
| 127 | return $ret; |
||
| 128 | case \XHELP_CONTROL_MULTISELECT: |
||
| 129 | $ret = "<label for='" . $this->fieldname . "'>" . $this->name . '</label>' . "<select name='" . $this->fieldname . "' id='" . $this->fieldname . "' size='3' multiple='multiple'>"; |
||
| 130 | foreach ($this->values as $key => $value) { |
||
| 131 | $ret .= "<option value='" . $key . "' " . (($this->value == $key) ? 'selected' : '') . '>' . $value . '</option>'; |
||
| 132 | } |
||
| 133 | $ret .= '</select>'; |
||
| 134 | |||
| 135 | return $ret; |
||
| 136 | case \XHELP_CONTROL_YESNO: |
||
| 137 | return "<label for='" |
||
| 138 | . $this->fieldname |
||
| 139 | . "'>" |
||
| 140 | . $this->name |
||
| 141 | . '</label>' |
||
| 142 | . "<input type='radio' name='" |
||
| 143 | . $this->fieldname |
||
| 144 | . "' id='" |
||
| 145 | . $this->fieldname |
||
| 146 | . "1' value='1' " |
||
| 147 | . ((1 == $this->value) ? 'checked' : '') |
||
| 148 | . '>' |
||
| 149 | . \_XHELP_TEXT_YES |
||
| 150 | . "<input type='radio' name='" |
||
| 151 | . $this->fieldname |
||
| 152 | . "' id='" |
||
| 153 | . $this->fieldname |
||
| 154 | . "0' value='0' " |
||
| 155 | . ((1 == $this->value) ? 'checked' : '') |
||
| 156 | . '>' |
||
| 157 | . \_XHELP_TEXT_NO; |
||
| 158 | case \XHELP_CONTROL_RADIOBOX: |
||
| 159 | $ret = "<label for='" . $this->fieldname . "'>" . $this->name . '</label>'; |
||
| 160 | foreach ($this->values as $key => $value) { |
||
| 161 | $ret .= "<input type='checkbox' name='" . $this->fieldname . "' id='" . $this->fieldname . "1' value='1' " . (($key == $this->value) ? 'checked' : '') . '>' . $value; |
||
| 162 | } |
||
| 163 | |||
| 164 | return $ret; |
||
| 165 | case \XHELP_CONTROL_DATETIME: |
||
| 166 | return "<label for='" . $this->fieldname . "'>" . $this->name . '</label>' . "<input type='text' name='" . $this->fieldname . "' id='" . $this->fieldname . "' value='" . $this->value . "' maxlength='" . $this->maxlength . "' size='" . $this->fieldlength . "'>"; |
||
| 167 | default: |
||
| 168 | return "<label for='" . $this->fieldname . "'>" . $this->name . '</label>' . "<input type='text' name='" . $this->fieldname . "' id='" . $this->fieldname . "' value='" . $this->value . "' maxlength='" . $this->maxlength . "' size='" . $this->fieldlength . "'>"; |
||
| 169 | } |
||
| 172 |