| Conditions | 11 |
| Paths | 5 |
| Total Lines | 37 |
| Code Lines | 21 |
| 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 |
||
| 70 | public static function fromArrayDefinition(string $operator, array $operands): self |
||
| 71 | { |
||
| 72 | if (!isset($operands[0], $operands[1], $operands[2])) { |
||
| 73 | throw new InvalidArgumentException("Operator '$operator' requires three operands."); |
||
| 74 | } |
||
| 75 | |||
| 76 | if ( |
||
| 77 | !is_array($operands[0]) && |
||
| 78 | !is_int($operands[0]) && |
||
| 79 | !is_string($operands[0]) && |
||
| 80 | !($operands[0] instanceof Iterator) && |
||
| 81 | !($operands[0] instanceof ExpressionInterface) |
||
| 82 | ) { |
||
| 83 | throw new InvalidArgumentException( |
||
| 84 | "Operator '$operator' requires value to be array, int, string, Iterator or ExpressionInterface." |
||
| 85 | ); |
||
| 86 | } |
||
| 87 | |||
| 88 | if ( |
||
| 89 | !is_string($operands[1]) && |
||
| 90 | !($operands[1] instanceof ExpressionInterface) |
||
| 91 | ) { |
||
| 92 | throw new InvalidArgumentException( |
||
| 93 | "Operator '$operator' requires interval start column to be string or ExpressionInterface." |
||
| 94 | ); |
||
| 95 | } |
||
| 96 | |||
| 97 | if ( |
||
| 98 | !is_string($operands[2]) && |
||
| 99 | !($operands[2] instanceof ExpressionInterface) |
||
| 100 | ) { |
||
| 101 | throw new InvalidArgumentException( |
||
| 102 | "Operator '$operator' requires interval end column to be string or ExpressionInterface." |
||
| 103 | ); |
||
| 104 | } |
||
| 105 | |||
| 106 | return new self($operands[0], $operator, $operands[1], $operands[2]); |
||
| 107 | } |
||
| 109 |