| Conditions | 7 |
| Paths | 7 |
| Total Lines | 82 |
| Code Lines | 74 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 |
||
| 73 | public function render() |
||
| 74 | { |
||
| 75 | // if the string of label is empty then nothing to be processed. |
||
| 76 | if (empty($this->string)) { |
||
| 77 | return ''; |
||
| 78 | } |
||
| 79 | |||
| 80 | $string = str_repeat(' ', 2) . $this->string . str_repeat(' ', 2); |
||
| 81 | |||
| 82 | switch ($this->contextualClass) { |
||
| 83 | default: |
||
| 84 | $output = $string; |
||
| 85 | break; |
||
| 86 | case 'primary': |
||
| 87 | $output = str_repeat(' ', $this->indent) . "\033[1;37m" . "\033[44m" . str_repeat( |
||
| 88 | ' ', |
||
| 89 | strlen($string) |
||
| 90 | ) . "\033[0m" . "\r\n"; |
||
| 91 | $output .= str_repeat( |
||
| 92 | ' ', |
||
| 93 | $this->indent |
||
| 94 | ) . "\033[1;37m" . "\033[44m" . $string . "\033[0m" . "\r\n"; |
||
| 95 | $output .= str_repeat(' ', $this->indent) . "\033[1;37m" . "\033[44m" . str_repeat( |
||
| 96 | ' ', |
||
| 97 | strlen($string) |
||
| 98 | ) . "\033[0m"; |
||
| 99 | break; |
||
| 100 | case 'success': |
||
| 101 | $output = str_repeat(' ', $this->indent) . "\033[1;37m" . "\033[42m" . str_repeat( |
||
| 102 | ' ', |
||
| 103 | strlen($string) |
||
| 104 | ) . "\033[0m" . "\r\n"; |
||
| 105 | $output .= str_repeat( |
||
| 106 | ' ', |
||
| 107 | $this->indent |
||
| 108 | ) . "\033[1;37m" . "\033[42m" . $string . "\033[0m" . "\r\n"; |
||
| 109 | $output .= str_repeat(' ', $this->indent) . "\033[1;37m" . "\033[42m" . str_repeat( |
||
| 110 | ' ', |
||
| 111 | strlen($string) |
||
| 112 | ) . "\033[0m"; |
||
| 113 | break; |
||
| 114 | case 'info': |
||
| 115 | $output = str_repeat(' ', $this->indent) . "\033[1;37m" . "\033[46m" . str_repeat( |
||
| 116 | ' ', |
||
| 117 | strlen($string) |
||
| 118 | ) . "\033[0m" . "\r\n"; |
||
| 119 | $output .= str_repeat( |
||
| 120 | ' ', |
||
| 121 | $this->indent |
||
| 122 | ) . "\033[1;37m" . "\033[46m" . $string . "\033[0m" . "\r\n"; |
||
| 123 | $output .= str_repeat(' ', $this->indent) . "\033[1;37m" . "\033[46m" . str_repeat( |
||
| 124 | ' ', |
||
| 125 | strlen($string) |
||
| 126 | ) . "\033[0m"; |
||
| 127 | break; |
||
| 128 | case 'warning': |
||
| 129 | $output = str_repeat(' ', $this->indent) . "\033[1;37m" . "\033[43m" . str_repeat( |
||
| 130 | ' ', |
||
| 131 | strlen($string) |
||
| 132 | ) . "\033[0m" . "\r\n"; |
||
| 133 | $output .= str_repeat( |
||
| 134 | ' ', |
||
| 135 | $this->indent |
||
| 136 | ) . "\033[1;37m" . "\033[43m" . $string . "\033[0m" . "\r\n"; |
||
| 137 | $output .= str_repeat(' ', $this->indent) . "\033[1;37m" . "\033[43m" . str_repeat( |
||
| 138 | ' ', |
||
| 139 | strlen($string) |
||
| 140 | ) . "\033[0m"; |
||
| 141 | break; |
||
| 142 | case 'danger': |
||
| 143 | $output = str_repeat(' ', $this->indent) . "\033[1;37m" . "\033[41m" . |
||
| 144 | str_repeat(' ', strlen($string)) . "\033[0m" . "\r\n"; |
||
| 145 | $output .= str_repeat( |
||
| 146 | ' ', |
||
| 147 | $this->indent |
||
| 148 | ) . "\033[1;37m" . "\033[41m" . $string . "\033[0m" . "\r\n"; |
||
| 149 | $output .= str_repeat(' ', $this->indent) . "\033[1;37m" . "\033[41m" . |
||
| 150 | str_repeat(' ', strlen($string)) . "\033[0m"; |
||
| 151 | break; |
||
| 152 | } |
||
| 153 | |||
| 154 | return str_repeat(PHP_EOL, $this->newLinesBefore) . $output . str_repeat(PHP_EOL, $this->newLinesAfter); |
||
| 155 | } |
||
| 156 | } |