Conditions | 17 |
Paths | 12 |
Total Lines | 92 |
Code Lines | 42 |
Lines | 9 |
Ratio | 9.78 % |
Tests | 49 |
CRAP Score | 17 |
Changes | 6 | ||
Bugs | 1 | 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 |
||
80 | 7 | public static function parse(Parser $parser, TokensList $list, array $options = array()) |
|
81 | { |
||
82 | 7 | $ret = array(); |
|
83 | |||
84 | 7 | $expr = new JoinKeyword(); |
|
85 | |||
86 | /** |
||
87 | * The state of the parser. |
||
88 | * |
||
89 | * Below are the states of the parser. |
||
90 | * |
||
91 | * 0 -----------------------[ JOIN ]----------------------> 1 |
||
92 | * |
||
93 | * 1 -----------------------[ expr ]----------------------> 2 |
||
94 | * |
||
95 | * 2 ------------------------[ ON ]-----------------------> 3 |
||
96 | * 2 -----------------------[ USING ]---------------------> 4 |
||
97 | * |
||
98 | * 3 --------------------[ conditions ]-------------------> 0 |
||
99 | * |
||
100 | * 4 ----------------------[ columns ]--------------------> 0 |
||
101 | * |
||
102 | * @var int $state |
||
103 | */ |
||
104 | 7 | $state = 0; |
|
105 | |||
106 | // By design, the parser will parse first token after the keyword. |
||
107 | // In this case, the keyword must be analyzed too, in order to determine |
||
108 | // the type of this join. |
||
109 | 7 | if ($list->idx > 0) { |
|
110 | 4 | --$list->idx; |
|
111 | 4 | } |
|
112 | |||
113 | 7 | for (; $list->idx < $list->count; ++$list->idx) { |
|
114 | /** |
||
115 | * Token parsed at this moment. |
||
116 | * |
||
117 | * @var Token $token |
||
118 | */ |
||
119 | 7 | $token = $list->tokens[$list->idx]; |
|
120 | |||
121 | // End of statement. |
||
122 | 7 | if ($token->type === Token::TYPE_DELIMITER) { |
|
123 | 6 | break; |
|
124 | } |
||
125 | |||
126 | // Skipping whitespaces and comments. |
||
127 | 7 | if (($token->type === Token::TYPE_WHITESPACE) || ($token->type === Token::TYPE_COMMENT)) { |
|
128 | 7 | continue; |
|
129 | } |
||
130 | |||
131 | 7 | if ($state === 0) { |
|
132 | 7 | if (($token->type === Token::TYPE_KEYWORD) |
|
133 | 7 | && (!empty(static::$JOINS[$token->value])) |
|
134 | 7 | ) { |
|
135 | 7 | $expr->type = static::$JOINS[$token->value]; |
|
136 | 7 | $state = 1; |
|
137 | 7 | } else { |
|
138 | 1 | break; |
|
139 | } |
||
140 | 7 | } elseif ($state === 1) { |
|
141 | 7 | $expr->expr = Expression::parse($parser, $list, array('field' => 'table')); |
|
142 | 7 | $state = 2; |
|
143 | 7 | View Code Duplication | } elseif ($state === 2) { |
1 ignored issue
–
show
|
|||
144 | 6 | if ($token->type === Token::TYPE_KEYWORD) { |
|
145 | 6 | if ($token->value === 'ON') { |
|
146 | 5 | $state = 3; |
|
147 | 6 | } elseif ($token->value === 'USING') { |
|
148 | 1 | $state = 4; |
|
149 | 1 | } |
|
150 | 6 | } |
|
151 | 6 | } elseif ($state === 3) { |
|
152 | 5 | $expr->on = Condition::parse($parser, $list); |
|
153 | 5 | $ret[] = $expr; |
|
154 | 5 | $expr = new JoinKeyword(); |
|
155 | 5 | $state = 0; |
|
156 | 6 | } elseif ($state === 4) { |
|
157 | 1 | $expr->using = ArrayObj::parse($parser, $list); |
|
158 | 1 | $ret[] = $expr; |
|
159 | 1 | $expr = new JoinKeyword(); |
|
160 | 1 | $state = 0; |
|
161 | 1 | } |
|
162 | |||
163 | 7 | } |
|
164 | |||
165 | 7 | if (!empty($expr->type)) { |
|
166 | 1 | $ret[] = $expr; |
|
167 | 1 | } |
|
168 | |||
169 | 7 | --$list->idx; |
|
170 | 7 | return $ret; |
|
171 | } |
||
172 | |||
191 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.