| Conditions | 7 |
| Paths | 4 |
| Total Lines | 62 |
| Code Lines | 49 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| 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 |
||
| 85 | public function write($string, $newline = false) |
||
| 86 | { |
||
| 87 | if ($this->colorEnabled && $this->consoleOutput->isDecorated()) { |
||
| 88 | $array = array("000" => self::b_black, |
||
| 89 | "100" => self::red, |
||
| 90 | "010" => self::green, |
||
| 91 | "110" => self::yellow, |
||
| 92 | "001" => self::blue, |
||
| 93 | "011" => self::magenta, |
||
| 94 | "101" => self::cyan, |
||
| 95 | "111" => self::white, |
||
| 96 | "200" => self::b_red, |
||
| 97 | "211" => self::red, |
||
| 98 | "121" => self::green, |
||
| 99 | "020" => self::b_green, |
||
| 100 | "021" => self::green, |
||
| 101 | "012" => self::cyan, |
||
| 102 | "221" => self::b_yellow, |
||
| 103 | "220" => self::b_yellow, |
||
| 104 | "120" => self::green, |
||
| 105 | "210" => self::yellow, |
||
| 106 | "112" => self::b_blue, |
||
| 107 | "002" => self::b_blue, |
||
| 108 | "122" => self::b_cyan, |
||
| 109 | "022" => self::b_cyan, |
||
| 110 | "202" => self::b_magenta, |
||
| 111 | "212" => self::b_magenta, |
||
| 112 | "102" => self::magenta, |
||
| 113 | "201" => self::b_red, |
||
| 114 | "222" => self::b_white, |
||
| 115 | ); |
||
| 116 | $matches = array(); |
||
| 117 | preg_match_all("/\\$[A-Fa-f0-9]{3}/", $string, $matches); |
||
| 118 | $split = preg_split("/\\$[A-Fa-f0-9]{3}/", $string); |
||
| 119 | |||
| 120 | $out = ""; |
||
| 121 | foreach ($matches[0] as $i => $rgb) { |
||
| 122 | $code = $this->fixColors(hexdec($rgb[1]), hexdec($rgb[2]), hexdec($rgb[3])); |
||
| 123 | if (array_key_exists($code, $array)) { |
||
| 124 | $out .= $array[$code] . $this->stripStyles($split[$i + 1]); |
||
| 125 | } else { |
||
| 126 | $out .= self::white . $this->stripStyles($split[$i + 1]); |
||
| 127 | } |
||
| 128 | $end = $this->stripStyles($split[$i + 1]); |
||
| 129 | } |
||
| 130 | |||
| 131 | |||
| 132 | if (!empty($end)) { |
||
| 133 | if ($end == $this->stripStyles(end($split))) { |
||
| 134 | $end = ""; |
||
| 135 | } |
||
| 136 | } else { |
||
| 137 | $end = ""; |
||
| 138 | } |
||
| 139 | |||
| 140 | $out = self::white . $this->stripStyles(reset($split)) . $out . $end; |
||
| 141 | } else { |
||
| 142 | $out = $this->stripStyles($string); |
||
| 143 | } |
||
| 144 | |||
| 145 | $this->ansiOut($out, $newline); |
||
| 146 | } |
||
| 147 | |||
| 225 |