| Conditions | 10 |
| Paths | 10 |
| Total Lines | 25 |
| Code Lines | 21 |
| 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 |
||
| 85 | private function getValue($comparator, $value) |
||
| 86 | { |
||
| 87 | switch ($comparator) { |
||
| 88 | case self::TYPE_EQUAL: |
||
| 89 | return $value; |
||
| 90 | case self::TYPE_EMPTY: |
||
| 91 | return; |
||
| 92 | case self::TYPE_NOT_EMPTY: |
||
| 93 | return; |
||
| 94 | case self::TYPE_CONTAINS: |
||
| 95 | return '%' . $value . '%'; |
||
| 96 | case self::TYPE_NOT_CONTAINS: |
||
| 97 | return '%' . $value . '%'; |
||
| 98 | case self::TYPE_STARTS_WITH: |
||
| 99 | return $value . '%'; |
||
| 100 | case self::TYPE_ENDS_WITH: |
||
| 101 | return '%' . $value; |
||
| 102 | case self::TYPE_IN: |
||
| 103 | return array_map('trim', explode(',', $value)); |
||
| 104 | case self::TYPE_NOT_IN: |
||
| 105 | return array_map('trim', explode(',', $value)); |
||
| 106 | } |
||
| 107 | |||
| 108 | throw new \InvalidArgumentException(sprintf('Could not determine value for comparator "%s"', $comparator)); |
||
| 109 | } |
||
| 110 | } |
||
| 111 |