| Conditions | 6 |
| Paths | 2 |
| Total Lines | 69 |
| Code Lines | 55 |
| 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 |
||
| 53 | private function displayBody() |
||
| 54 | { |
||
| 55 | $this->terminal->moveCursorToRow($this->y); |
||
| 56 | $this->emptyRow(); |
||
| 57 | $this->write(sprintf( |
||
| 58 | "%s%s%s%s%s\n", |
||
| 59 | $this->style->getUnselectedSetCode(), |
||
| 60 | str_repeat(' ', $this->style->getPadding()), |
||
| 61 | $this->text, |
||
| 62 | str_repeat(' ', $this->style->getPadding()), |
||
| 63 | $this->style->getUnselectedUnsetCode() |
||
| 64 | )); |
||
| 65 | $this->emptyRow(); |
||
| 66 | |||
| 67 | $promptWidth = mb_strlen($this->text) + 4; |
||
| 68 | $fillWidth = $promptWidth - (mb_strlen($this->getYesText()) + mb_strlen($this->getNoText())); |
||
| 69 | $placeHolderWidth = 0 == ($fillWidth % 2) ? 2 : 1;//中间位宽度 |
||
| 70 | $fillWidth = ($fillWidth - $placeHolderWidth) / 2; |
||
| 71 | |||
| 72 | $this->write(sprintf( |
||
| 73 | '%s%s%s', |
||
| 74 | $this->style->getUnselectedSetCode(), |
||
| 75 | str_repeat(' ', $fillWidth), |
||
| 76 | $this->style->getUnselectedSetCode() |
||
| 77 | )); |
||
| 78 | $this->write( |
||
| 79 | sprintf( |
||
| 80 | '%s%s%s', |
||
| 81 | $this->getOptionValue() ? $this->style->getSelectedSetCode() : $this->style->getUnselectedSetCode(), |
||
| 82 | $this->getYesText(), |
||
| 83 | $this->getOptionValue() ? $this->style->getSelectedSetCode() : $this->style->getUnselectedSetCode() |
||
| 84 | ), |
||
| 85 | -1 |
||
| 86 | ); |
||
| 87 | $this->write( |
||
| 88 | sprintf( |
||
| 89 | '%s%s%s', |
||
| 90 | $this->style->getUnselectedSetCode(), |
||
| 91 | str_repeat(' ', $placeHolderWidth), |
||
| 92 | $this->style->getUnselectedSetCode() |
||
| 93 | ), |
||
| 94 | -1 |
||
| 95 | ); |
||
| 96 | $this->write( |
||
| 97 | sprintf( |
||
| 98 | '%s%s%s', |
||
| 99 | $this->getOptionValue() ? $this->style->getUnselectedSetCode() : $this->style->getSelectedSetCode(), |
||
| 100 | $this->getNoText(), |
||
| 101 | $this->getOptionValue() ? $this->style->getUnselectedSetCode() : $this->style->getSelectedSetCode() |
||
| 102 | ), |
||
| 103 | -1 |
||
| 104 | ); |
||
| 105 | $this->write(sprintf( |
||
| 106 | "%s%s%s\n", |
||
| 107 | $this->style->getUnselectedSetCode(), |
||
| 108 | str_repeat(' ', $fillWidth), |
||
| 109 | $this->style->getUnselectedSetCode() |
||
| 110 | ), -1); |
||
| 111 | |||
| 112 | $this->write(sprintf( |
||
| 113 | "%s%s%s%s%s\n", |
||
| 114 | $this->style->getUnselectedSetCode(), |
||
| 115 | str_repeat(' ', $this->style->getPadding()), |
||
| 116 | str_repeat(' ', mb_strlen($this->text)), |
||
| 117 | str_repeat(' ', $this->style->getPadding()), |
||
| 118 | $this->style->getUnselectedUnsetCode() |
||
| 119 | )); |
||
| 120 | $this->terminal->moveCursorToTop(); |
||
| 121 | } |
||
| 122 | |||
| 217 |