| Conditions | 16 |
| Paths | 16 |
| Total Lines | 50 |
| Code Lines | 32 |
| 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 |
||
| 30 | public function process(IAdapter $adapter, $lookup, $column, $value) |
||
| 31 | { |
||
| 32 | switch (strtolower($lookup)) { |
||
| 33 | case 'second': |
||
| 34 | return 'EXTRACT(SECOND FROM ' . $adapter->quoteColumn($column) . '::timestamp)=' . $adapter->quoteValue((string)$value); |
||
| 35 | |||
| 36 | case 'year': |
||
| 37 | return 'EXTRACT(YEAR FROM ' . $adapter->quoteColumn($column) . '::timestamp)=' . $adapter->quoteValue((string)$value); |
||
| 38 | |||
| 39 | case 'minute': |
||
| 40 | return 'EXTRACT(MINUTE FROM ' . $adapter->quoteColumn($column) . '::timestamp)=' . $adapter->quoteValue((string)$value); |
||
| 41 | |||
| 42 | case 'hour': |
||
| 43 | return 'EXTRACT(HOUR FROM ' . $adapter->quoteColumn($column) . '::timestamp)=' . $adapter->quoteValue((string)$value); |
||
| 44 | |||
| 45 | case 'day': |
||
| 46 | return 'EXTRACT(DAY FROM ' . $adapter->quoteColumn($column) . '::timestamp)=' . $adapter->quoteValue((string)$value); |
||
| 47 | |||
| 48 | case 'month': |
||
| 49 | return 'EXTRACT(MONTH FROM ' . $adapter->quoteColumn($column) . '::timestamp)=' . $adapter->quoteValue((string)$value); |
||
| 50 | |||
| 51 | case 'week_day': |
||
| 52 | return 'EXTRACT(DOW FROM ' . $adapter->quoteColumn($column) . '::timestamp)=' . $adapter->quoteValue((string)$value); |
||
| 53 | |||
| 54 | case 'regex': |
||
| 55 | return $adapter->quoteColumn($column) . "~" . $adapter->quoteValue($value); |
||
| 56 | |||
| 57 | case 'iregex': |
||
| 58 | return $adapter->quoteColumn($column) . "~*" . $adapter->quoteValue($value); |
||
| 59 | |||
| 60 | case 'contains': |
||
| 61 | return $adapter->quoteColumn($column) . '::text LIKE ' . $adapter->quoteValue('%' . $value . '%'); |
||
| 62 | |||
| 63 | case 'icontains': |
||
| 64 | return 'LOWER(' . $adapter->quoteColumn($column) . '::text) LIKE ' . $adapter->quoteValue('%' . mb_strtolower($value, 'UTF-8') . '%'); |
||
| 65 | |||
| 66 | case 'startswith': |
||
| 67 | return $adapter->quoteColumn($column) . '::text LIKE ' . $adapter->quoteValue($value . '%'); |
||
| 68 | |||
| 69 | case 'istartswith': |
||
| 70 | return 'LOWER(' . $adapter->quoteColumn($column) . '::text) LIKE ' . $adapter->quoteValue(mb_strtolower($value, 'UTF-8') . '%'); |
||
| 71 | |||
| 72 | case 'endswith': |
||
| 73 | return $adapter->quoteColumn($column) . '::text LIKE ' . $adapter->quoteValue('%' . $value); |
||
| 74 | |||
| 75 | case 'iendswith': |
||
| 76 | return 'LOWER(' . $adapter->quoteColumn($column) . '::text) LIKE ' . $adapter->quoteValue('%' . mb_strtolower($value, 'UTF-8')); |
||
| 77 | } |
||
| 78 | |||
| 79 | return parent::process($adapter, $lookup, $column, $value); |
||
| 80 | } |
||
| 81 | } |