| Conditions | 2 |
| Paths | 2 |
| Total Lines | 69 |
| Code Lines | 46 |
| 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 |
||
| 147 | public function display($confirmText = 'OK') |
||
| 148 | { |
||
| 149 | $this->assertMenuOpen(); |
||
| 150 | |||
| 151 | $this->terminal->moveCursorToRow($this->y); |
||
| 152 | |||
| 153 | $promptWidth = mb_strlen($this->text) + 4; |
||
| 154 | |||
| 155 | $this->emptyRow(); |
||
| 156 | |||
| 157 | $this->write(sprintf( |
||
| 158 | "%s%s%s%s%s\n", |
||
| 159 | $this->style->getUnselectedSetCode(), |
||
| 160 | str_repeat(' ', $this->style->getPadding()), |
||
| 161 | $this->text, |
||
| 162 | str_repeat(' ', $this->style->getPadding()), |
||
| 163 | $this->style->getUnselectedUnsetCode() |
||
| 164 | )); |
||
| 165 | |||
| 166 | $this->emptyRow(); |
||
| 167 | |||
| 168 | $confirmText = sprintf(' < %s > ', $confirmText); |
||
| 169 | $leftFill = ($promptWidth / 2) - (mb_strlen($confirmText) / 2); |
||
| 170 | |||
| 171 | $this->write(sprintf( |
||
| 172 | '%s%s%s', |
||
| 173 | $this->style->getUnselectedSetCode(), |
||
| 174 | str_repeat(' ', $leftFill), |
||
| 175 | $this->style->getUnselectedSetCode() |
||
| 176 | )); |
||
| 177 | |||
| 178 | $this->write( |
||
| 179 | sprintf( |
||
| 180 | '%s%s%s', |
||
| 181 | $this->style->getSelectedSetCode(), |
||
| 182 | $confirmText, |
||
| 183 | $this->style->getSelectedUnsetCode() |
||
| 184 | ), |
||
| 185 | -1 |
||
| 186 | ); |
||
| 187 | |||
| 188 | $this->write( |
||
| 189 | sprintf( |
||
| 190 | "%s%s%s\n", |
||
| 191 | $this->style->getUnselectedSetCode(), |
||
| 192 | str_repeat(' ', ceil($promptWidth - $leftFill - mb_strlen($confirmText))), |
||
| 193 | $this->style->getSelectedUnsetCode() |
||
| 194 | ), |
||
| 195 | -1 |
||
| 196 | ); |
||
| 197 | |||
| 198 | $this->write(sprintf( |
||
| 199 | "%s%s%s%s%s\n", |
||
| 200 | $this->style->getUnselectedSetCode(), |
||
| 201 | str_repeat(' ', $this->style->getPadding()), |
||
| 202 | str_repeat(' ', mb_strlen($this->text)), |
||
| 203 | str_repeat(' ', $this->style->getPadding()), |
||
| 204 | $this->style->getUnselectedUnsetCode() |
||
| 205 | )); |
||
| 206 | |||
| 207 | $this->terminal->moveCursorToTop(); |
||
| 208 | $input = $this->terminal->getKeyedInput(); |
||
| 209 | |||
| 210 | while ($input !== 'enter') { |
||
| 211 | $input = $this->terminal->getKeyedInput(); |
||
| 212 | } |
||
| 213 | |||
| 214 | $this->parentMenu->redraw(); |
||
| 215 | } |
||
| 216 | } |
||
| 217 |