| Conditions | 17 |
| Paths | 12 |
| Total Lines | 92 |
| Code Lines | 42 |
| Lines | 9 |
| Ratio | 9.78 % |
| Tests | 42 |
| CRAP Score | 17.8433 |
| 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 |
||
| 79 | 6 | public static function parse(Parser $parser, TokensList $list, array $options = array()) |
|
| 80 | { |
||
| 81 | 6 | $ret = array(); |
|
| 82 | |||
| 83 | 6 | $expr = new JoinKeyword(); |
|
| 84 | |||
| 85 | /** |
||
| 86 | * The state of the parser. |
||
| 87 | * |
||
| 88 | * Below are the states of the parser. |
||
| 89 | * |
||
| 90 | * 0 -----------------------[ JOIN ]----------------------> 1 |
||
| 91 | * |
||
| 92 | * 1 -----------------------[ expr ]----------------------> 2 |
||
| 93 | * |
||
| 94 | * 2 ------------------------[ ON ]-----------------------> 3 |
||
| 95 | * 2 -----------------------[ USING ]---------------------> 4 |
||
| 96 | * |
||
| 97 | * 3 --------------------[ conditions ]-------------------> 0 |
||
| 98 | * |
||
| 99 | * 4 ----------------------[ columns ]--------------------> 0 |
||
| 100 | * |
||
| 101 | * @var int $state |
||
| 102 | */ |
||
| 103 | 6 | $state = 0; |
|
| 104 | |||
| 105 | // By design, the parser will parse first token after the keyword. |
||
| 106 | // In this case, the keyword must be analyzed too, in order to determine |
||
| 107 | // the type of this join. |
||
| 108 | 6 | if ($list->idx > 0) { |
|
| 109 | 4 | --$list->idx; |
|
| 110 | 4 | } |
|
| 111 | |||
| 112 | 6 | for (; $list->idx < $list->count; ++$list->idx) { |
|
| 113 | /** |
||
| 114 | * Token parsed at this moment. |
||
| 115 | * |
||
| 116 | * @var Token $token |
||
| 117 | */ |
||
| 118 | 6 | $token = $list->tokens[$list->idx]; |
|
| 119 | |||
| 120 | // End of statement. |
||
| 121 | 6 | if ($token->type === Token::TYPE_DELIMITER) { |
|
| 122 | 5 | break; |
|
| 123 | } |
||
| 124 | |||
| 125 | // Skipping whitespaces and comments. |
||
| 126 | 6 | if (($token->type === Token::TYPE_WHITESPACE) || ($token->type === Token::TYPE_COMMENT)) { |
|
| 127 | 6 | continue; |
|
| 128 | } |
||
| 129 | |||
| 130 | 6 | if ($state === 0) { |
|
| 131 | 6 | if (($token->type === Token::TYPE_KEYWORD) |
|
| 132 | 6 | && (!empty(static::$JOINS[$token->value])) |
|
| 133 | 6 | ) { |
|
| 134 | 6 | $expr->type = static::$JOINS[$token->value]; |
|
| 135 | 6 | $state = 1; |
|
|
|
|||
| 136 | 6 | } else { |
|
| 137 | 1 | break; |
|
| 138 | } |
||
| 139 | 6 | } elseif ($state === 1) { |
|
| 140 | 6 | $expr->expr = Expression::parse($parser, $list, array('field' => 'table')); |
|
| 141 | 6 | $state = 2; |
|
| 142 | 6 | View Code Duplication | } elseif ($state === 2) { |
|
1 ignored issue
–
show
|
|||
| 143 | 5 | if ($token->type === Token::TYPE_KEYWORD) { |
|
| 144 | 5 | if ($token->value === 'ON') { |
|
| 145 | 5 | $state = 3; |
|
| 146 | 5 | } elseif ($token->value === 'USING') { |
|
| 147 | $state = 4; |
||
| 148 | } |
||
| 149 | 5 | } |
|
| 150 | 5 | } elseif ($state === 3) { |
|
| 151 | 5 | $expr->on = Condition::parse($parser, $list); |
|
| 152 | 5 | $ret[] = $expr; |
|
| 153 | 5 | $expr = new JoinKeyword(); |
|
| 154 | 5 | $state = 0; |
|
| 155 | 5 | } elseif ($state === 4) { |
|
| 156 | $expr->using = ArrayObj::parse($parser, $list); |
||
| 157 | $ret[] = $expr; |
||
| 158 | $expr = new JoinKeyword(); |
||
| 159 | $state = 0; |
||
| 160 | } |
||
| 161 | |||
| 162 | 6 | } |
|
| 163 | |||
| 164 | 6 | if (!empty($expr->type)) { |
|
| 165 | 1 | $ret[] = $expr; |
|
| 166 | 1 | } |
|
| 167 | |||
| 168 | 6 | --$list->idx; |
|
| 169 | 6 | return $ret; |
|
| 170 | } |
||
| 171 | |||
| 190 |
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.
To visualize
will produce issues in the first and second line, while this second example
will produce no issues.