| Total Complexity | 60 |
| Total Lines | 281 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
Complex classes like Scanner 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 Scanner, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 15 | final class Scanner |
||
| 16 | { |
||
| 17 | |||
| 18 | public $is; |
||
| 19 | public $value; |
||
| 20 | public $token; |
||
| 21 | |||
| 22 | public $recurse = false; |
||
| 23 | public $it = 0; |
||
| 24 | |||
| 25 | /** |
||
| 26 | * Given a new input stream, tokenize the CSS selector string. |
||
| 27 | * |
||
| 28 | * @see InputStream |
||
| 29 | * @param InputStream $in |
||
| 30 | * An input stream to be scanned. |
||
| 31 | */ |
||
| 32 | public function __construct(InputStream $in) |
||
| 35 | } |
||
| 36 | |||
| 37 | /** |
||
| 38 | * Return the position of the reader in the string. |
||
| 39 | */ |
||
| 40 | public function position(): int |
||
| 43 | } |
||
| 44 | |||
| 45 | /** |
||
| 46 | * See the next char without removing it from the stack. |
||
| 47 | * |
||
| 48 | * @return string |
||
| 49 | * Returns the next character on the stack. |
||
| 50 | */ |
||
| 51 | public function peek(): string |
||
| 54 | } |
||
| 55 | |||
| 56 | /** |
||
| 57 | * Get the next token in the input stream. |
||
| 58 | * |
||
| 59 | * This sets the current token to the value of the next token in |
||
| 60 | * the stream. |
||
| 61 | * |
||
| 62 | * @return int |
||
| 63 | * Returns an int value corresponding to one of the Token constants, |
||
| 64 | * or FALSE if the end of the string is reached. (Remember to use |
||
| 65 | * strong equality checking on FALSE, since 0 is a valid token id.) |
||
| 66 | * @throws ParseException |
||
| 67 | * @throws \QueryPath\Exception |
||
| 68 | */ |
||
| 69 | public function nextToken(): int |
||
| 187 | } |
||
| 188 | |||
| 189 | /** |
||
| 190 | * Get a name string from the input stream. |
||
| 191 | * A name string must be composed of |
||
| 192 | * only characters defined in Token:char: -_a-zA-Z0-9 |
||
| 193 | */ |
||
| 194 | public function getNameString() |
||
| 195 | { |
||
| 196 | $buf = ''; |
||
| 197 | while ($this->token === Token::CHAR) { |
||
| 198 | $buf .= $this->value; |
||
| 199 | $this->nextToken(); |
||
| 200 | } |
||
| 201 | |||
| 202 | return $buf; |
||
| 203 | } |
||
| 204 | |||
| 205 | /** |
||
| 206 | * This gets a string with any legal 'string' characters. |
||
| 207 | * See CSS Selectors specification, section 11, for the |
||
| 208 | * definition of string. |
||
| 209 | * |
||
| 210 | * This will check for string1, string2, and the case where a |
||
| 211 | * string is unquoted (Oddly absent from the "official" grammar, |
||
| 212 | * though such strings are present as examples in the spec.) |
||
| 213 | * |
||
| 214 | * Note: |
||
| 215 | * Though the grammar supplied by CSS 3 Selectors section 11 does not |
||
| 216 | * address the contents of a pseudo-class value, the spec itself indicates |
||
| 217 | * that a pseudo-class value is a "value between parenthesis" [6.6]. The |
||
| 218 | * examples given use URLs among other things, making them closer to the |
||
| 219 | * definition of 'string' than to 'name'. So we handle them here as strings. |
||
| 220 | */ |
||
| 221 | public function getQuotedString() |
||
| 254 | } |
||
| 255 | } |
||
| 256 | |||
| 257 | // Get the contents inside of a pseudoClass(). |
||
| 258 | public function getPseudoClassString() |
||
| 318 |