| 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 |
||
| 16 | public function display($confirmText = 'OK') |
||
| 17 | { |
||
| 18 | $this->assertMenuOpen(); |
||
| 19 | |||
| 20 | $this->terminal->moveCursorToRow($this->y); |
||
| 21 | |||
| 22 | $promptWidth = mb_strlen($this->text) + 4; |
||
| 23 | |||
| 24 | $this->emptyRow(); |
||
| 25 | |||
| 26 | $this->write(sprintf( |
||
| 27 | "%s%s%s%s%s\n", |
||
| 28 | $this->style->getUnselectedSetCode(), |
||
| 29 | str_repeat(' ', $this->style->getPadding()), |
||
| 30 | $this->text, |
||
| 31 | str_repeat(' ', $this->style->getPadding()), |
||
| 32 | $this->style->getUnselectedUnsetCode() |
||
| 33 | )); |
||
| 34 | |||
| 35 | $this->emptyRow(); |
||
| 36 | |||
| 37 | $confirmText = sprintf(' < %s > ', $confirmText); |
||
| 38 | $leftFill = ($promptWidth / 2) - (mb_strlen($confirmText) / 2); |
||
| 39 | |||
| 40 | $this->write(sprintf( |
||
| 41 | '%s%s%s', |
||
| 42 | $this->style->getUnselectedSetCode(), |
||
| 43 | str_repeat(' ', $leftFill), |
||
| 44 | $this->style->getUnselectedSetCode() |
||
| 45 | )); |
||
| 46 | |||
| 47 | $this->write( |
||
| 48 | sprintf( |
||
| 49 | '%s%s%s', |
||
| 50 | $this->style->getSelectedSetCode(), |
||
| 51 | $confirmText, |
||
| 52 | $this->style->getSelectedUnsetCode() |
||
| 53 | ), |
||
| 54 | -1 |
||
| 55 | ); |
||
| 56 | |||
| 57 | $this->write( |
||
| 58 | sprintf( |
||
| 59 | "%s%s%s\n", |
||
| 60 | $this->style->getUnselectedSetCode(), |
||
| 61 | str_repeat(' ', ceil($promptWidth - $leftFill - mb_strlen($confirmText))), |
||
| 62 | $this->style->getSelectedUnsetCode() |
||
| 63 | ), |
||
| 64 | -1 |
||
| 65 | ); |
||
| 66 | |||
| 67 | $this->write(sprintf( |
||
| 68 | "%s%s%s%s%s\n", |
||
| 69 | $this->style->getUnselectedSetCode(), |
||
| 70 | str_repeat(' ', $this->style->getPadding()), |
||
| 71 | str_repeat(' ', mb_strlen($this->text)), |
||
| 72 | str_repeat(' ', $this->style->getPadding()), |
||
| 73 | $this->style->getUnselectedUnsetCode() |
||
| 74 | )); |
||
| 75 | |||
| 76 | $this->terminal->moveCursorToTop(); |
||
| 77 | $input = $this->terminal->getKeyedInput(); |
||
| 78 | |||
| 79 | while ($input !== 'enter') { |
||
| 80 | $input = $this->terminal->getKeyedInput(); |
||
| 81 | } |
||
| 82 | |||
| 83 | $this->parentMenu->redraw(); |
||
| 84 | } |
||
| 85 | } |
||
| 86 |