| Conditions | 2 |
| Paths | 1 |
| Total Lines | 51 |
| Code Lines | 33 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 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 |
||
| 10 | public static function create(Definitions $customOperators) |
||
| 11 | { |
||
| 12 | $defaultInlineOperators = [ |
||
| 13 | 'and' => function ($a, $b) { |
||
| 14 | return sprintf('(%s)', OperatorTools::inlineMixedInstructions([$a, $b], 'AND')); |
||
| 15 | }, |
||
| 16 | 'or' => function ($a, $b) { |
||
| 17 | return sprintf('(%s)', OperatorTools::inlineMixedInstructions([$a, $b], 'OR')); |
||
| 18 | }, |
||
| 19 | 'not' => function ($a) { |
||
| 20 | return sprintf('NOT (%s)', OperatorTools::inlineMixedInstructions([$a])); |
||
| 21 | }, |
||
| 22 | '=' => function ($a, $b) { |
||
| 23 | return OperatorTools::inlineMixedInstructions([$a, $b], '='); |
||
| 24 | }, |
||
| 25 | '!=' => function ($a, $b) { |
||
| 26 | return OperatorTools::inlineMixedInstructions([$a, $b], '!='); |
||
| 27 | }, |
||
| 28 | '>' => function ($a, $b) { |
||
| 29 | return OperatorTools::inlineMixedInstructions([$a, $b], '>'); |
||
| 30 | }, |
||
| 31 | '>=' => function ($a, $b) { |
||
| 32 | return OperatorTools::inlineMixedInstructions([$a, $b], '>='); |
||
| 33 | }, |
||
| 34 | '<' => function ($a, $b) { |
||
| 35 | return OperatorTools::inlineMixedInstructions([$a, $b], '<'); |
||
| 36 | }, |
||
| 37 | '<=' => function ($a, $b) { |
||
| 38 | return OperatorTools::inlineMixedInstructions([$a, $b], '<='); |
||
| 39 | }, |
||
| 40 | 'in' => function ($a, $b) { |
||
| 41 | if ($b[0] === '(') { |
||
| 42 | return OperatorTools::inlineMixedInstructions([$a, $b], 'IN'); |
||
| 43 | } else { |
||
| 44 | return sprintf( |
||
| 45 | '%s IN (%s)', |
||
| 46 | OperatorTools::inlineMixedInstructions([$a]), |
||
| 47 | OperatorTools::inlineMixedInstructions([$b]) |
||
| 48 | ); |
||
| 49 | } |
||
| 50 | }, |
||
| 51 | 'like' => function ($a, $b) { |
||
| 52 | return OperatorTools::inlineMixedInstructions([$a, $b], 'LIKE'); |
||
| 53 | }, |
||
| 54 | ]; |
||
| 55 | |||
| 56 | $definitions = new Definitions(); |
||
| 57 | $definitions->defineInlineOperators($defaultInlineOperators); |
||
| 58 | |||
| 59 | return $definitions->mergeWith($customOperators); |
||
|
|
|||
| 60 | } |
||
| 61 | } |
||
| 62 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: