Conditions | 15 |
Paths | 40 |
Total Lines | 55 |
Code Lines | 36 |
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 |
||
41 | public function parse(Buffer $src): \Generator |
||
42 | { |
||
43 | while ($n = $src->next()) { |
||
44 | switch ($n->char) { |
||
45 | case '"': |
||
46 | case "'": |
||
47 | if ($this->keyword !== []) { |
||
48 | yield $this->packToken($this->keyword, self::TYPE_KEYWORD); |
||
49 | $this->keyword = []; |
||
50 | } |
||
51 | |||
52 | $quoted[] = $n; |
||
53 | while ($nn = $src->next()) { |
||
54 | $quoted[] = $nn; |
||
55 | if ($nn instanceof Byte && $nn->char === $n->char) { |
||
56 | break; |
||
57 | } |
||
58 | } |
||
59 | |||
60 | yield $this->packToken($quoted, self::TYPE_QUOTED); |
||
61 | $quoted = []; |
||
62 | |||
63 | break; |
||
64 | case '=': |
||
65 | if ($this->keyword !== []) { |
||
66 | yield $this->packToken($this->keyword, self::TYPE_KEYWORD); |
||
67 | $this->keyword = []; |
||
68 | } |
||
69 | |||
70 | yield new Token(self::TYPE_EQUAL, $n->offset, '='); |
||
71 | break; |
||
72 | case ',': |
||
73 | if ($this->keyword !== []) { |
||
74 | yield $this->packToken($this->keyword, self::TYPE_KEYWORD); |
||
75 | $this->keyword = []; |
||
76 | } |
||
77 | |||
78 | yield new Token(self::TYPE_COMMA, $n->offset, ','); |
||
79 | break; |
||
80 | default: |
||
81 | if (preg_match(self::REGEXP_WHITESPACE, $n->char)) { |
||
82 | if ($this->keyword !== []) { |
||
83 | yield $this->packToken($this->keyword, self::TYPE_KEYWORD); |
||
84 | $this->keyword = []; |
||
85 | } |
||
86 | |||
87 | break; |
||
88 | } |
||
89 | |||
90 | $this->keyword[] = $n; |
||
91 | } |
||
92 | } |
||
93 | |||
94 | if ($this->keyword !== []) { |
||
95 | yield $this->packToken($this->keyword, self::TYPE_KEYWORD); |
||
96 | } |
||
118 |