Conditions | 4 |
Paths | 3 |
Total Lines | 52 |
Code Lines | 36 |
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 |
||
17 | public function display(string $confirmText = 'OK') : void |
||
18 | { |
||
19 | $this->assertMenuOpen(); |
||
20 | |||
21 | $this->terminal->moveCursorToRow($this->y); |
||
22 | |||
23 | $promptWidth = mb_strlen($this->text) + 4; |
||
24 | |||
25 | $this->emptyRow(); |
||
26 | |||
27 | $this->write(sprintf( |
||
28 | "%s%s%s%s%s\n", |
||
29 | $this->style->getColoursSetCode(), |
||
30 | str_repeat(' ', $this->style->getPaddingLeftRight()), |
||
31 | $this->text, |
||
32 | str_repeat(' ', $this->style->getPaddingLeftRight()), |
||
33 | $this->style->getColoursResetCode() |
||
34 | )); |
||
35 | |||
36 | $this->emptyRow(); |
||
37 | |||
38 | $confirmText = sprintf(' < %s > ', $confirmText); |
||
39 | $leftFill = ($promptWidth / 2) - (mb_strlen($confirmText) / 2); |
||
40 | |||
41 | $this->write(sprintf( |
||
42 | "%s%s%s%s%s%s%s\n", |
||
43 | $this->style->getColoursSetCode(), |
||
44 | str_repeat(' ', $leftFill), |
||
45 | $this->style->getInvertedColoursSetCode(), |
||
46 | $confirmText, |
||
47 | $this->style->getInvertedColoursUnsetCode(), |
||
48 | str_repeat(' ', ceil($promptWidth - $leftFill - mb_strlen($confirmText))), |
||
1 ignored issue
–
show
|
|||
49 | $this->style->getColoursResetCode() |
||
50 | )); |
||
51 | |||
52 | $this->write(sprintf( |
||
53 | "%s%s%s%s%s\n", |
||
54 | $this->style->getColoursSetCode(), |
||
55 | str_repeat(' ', $this->style->getPaddingLeftRight()), |
||
56 | str_repeat(' ', mb_strlen($this->text)), |
||
57 | str_repeat(' ', $this->style->getPaddingLeftRight()), |
||
58 | $this->style->getColoursResetCode() |
||
59 | )); |
||
60 | |||
61 | $this->terminal->moveCursorToTop(); |
||
62 | |||
63 | $reader = new NonCanonicalReader($this->terminal); |
||
64 | |||
65 | while ($char = $reader->readCharacter()) { |
||
66 | if ($char->isControl() && $char->getControl() === InputCharacter::ENTER) { |
||
67 | $this->parentMenu->redraw(); |
||
68 | return; |
||
69 | } |
||
73 |