Complex classes like ParserInput often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use ParserInput, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 18 | final class ParserInput |
||
| 19 | { |
||
| 20 | const CHARCODE_SPACE = 32; |
||
| 21 | const CHARCODE_TAB = 9; |
||
| 22 | const CHARCODE_LF = 10; |
||
| 23 | const CHARCODE_CR = 13; |
||
| 24 | const CHARCODE_PLUS = 43; |
||
| 25 | const CHARCODE_COMMA = 44; |
||
| 26 | const CHARCODE_FORWARD_SLASH = 47; |
||
| 27 | const CHARCODE_9 = 57; |
||
| 28 | |||
| 29 | /** |
||
| 30 | * Current index. |
||
| 31 | * |
||
| 32 | * @var int |
||
| 33 | */ |
||
| 34 | public $i = 0; |
||
| 35 | |||
| 36 | /** |
||
| 37 | * LeSS input string. |
||
| 38 | * |
||
| 39 | * @var string |
||
| 40 | */ |
||
| 41 | private $input; |
||
| 42 | |||
| 43 | /** |
||
| 44 | * Current chunk. |
||
| 45 | * |
||
| 46 | * @var |
||
| 47 | */ |
||
| 48 | private $j = 0; |
||
| 49 | private $saveStack = []; |
||
| 50 | private $furthest; |
||
| 51 | private $furthestPossibleErrorMessage; |
||
| 52 | private $chunks; |
||
| 53 | private $current; |
||
| 54 | private $currentPos; |
||
| 55 | |||
| 56 | /** |
||
| 57 | * @var bool |
||
| 58 | */ |
||
| 59 | public $autoCommentAbsorb = true; |
||
| 60 | |||
| 61 | /** |
||
| 62 | * @var array |
||
| 63 | */ |
||
| 64 | public $commentStore = []; |
||
| 65 | |||
| 66 | /** |
||
| 67 | * @var bool |
||
| 68 | */ |
||
| 69 | public $finished = false; |
||
| 70 | |||
| 71 | /** |
||
| 72 | * Constructor. |
||
| 73 | */ |
||
| 74 | public function __construct() |
||
| 77 | |||
| 78 | public function save() |
||
| 87 | |||
| 88 | /** |
||
| 89 | * @param null $possibleErrorMessage |
||
| 90 | */ |
||
| 91 | public function restore($possibleErrorMessage = null) |
||
| 103 | |||
| 104 | public function forget() |
||
| 108 | |||
| 109 | /** |
||
| 110 | * @param $offset |
||
| 111 | * |
||
| 112 | * @return bool |
||
| 113 | */ |
||
| 114 | public function isWhiteSpace($offset = 0) |
||
| 121 | |||
| 122 | public function re($tok) |
||
| 143 | |||
| 144 | public function char($tok) |
||
| 154 | |||
| 155 | public function str($tok) |
||
| 168 | |||
| 169 | /** |
||
| 170 | * @return null|string |
||
| 171 | */ |
||
| 172 | public function quoted() |
||
| 201 | |||
| 202 | private function skipWhitespace($length) |
||
| 264 | |||
| 265 | /** |
||
| 266 | * Original less.js function handles string and regexp here, I have to create |
||
| 267 | * additional method for regexp, see `peekReg`. |
||
| 268 | * |
||
| 269 | * @param $tok |
||
| 270 | * |
||
| 271 | * @return bool |
||
| 272 | */ |
||
| 273 | public function peek($tok) |
||
| 284 | |||
| 285 | public function peekReg($regexp) |
||
| 291 | |||
| 292 | public function peekChar($tok) |
||
| 296 | |||
| 297 | public function currentChar() |
||
| 301 | |||
| 302 | public function getInput() |
||
| 306 | |||
| 307 | public function peekNotNumeric() |
||
| 314 | |||
| 315 | /** |
||
| 316 | * @param $string |
||
| 317 | */ |
||
| 318 | public function start($string) |
||
| 326 | |||
| 327 | /** |
||
| 328 | * @return stdClass |
||
| 329 | */ |
||
| 330 | public function end() |
||
| 347 | } |
||
| 348 |