Conditions | 13 |
Paths | 13 |
Total Lines | 44 |
Code Lines | 29 |
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 'regex': |
||
34 | return $adapter->quoteColumn($column) . ' REGEXP ' . $adapter->quoteValue('/' . $value . '/'); |
||
35 | |||
36 | case 'iregex': |
||
37 | return $adapter->quoteColumn($column) . ' REGEXP ' . $adapter->quoteValue('/' . $value . '/i'); |
||
38 | |||
39 | case 'second': |
||
40 | return "strftime('%S', " . $adapter->quoteColumn($column) . ')=' . $adapter->quoteValue((string)$value); |
||
41 | |||
42 | case 'year': |
||
43 | return "strftime('%Y', " . $adapter->quoteColumn($column) . ')=' . $adapter->quoteValue((string)$value); |
||
44 | |||
45 | case 'minute': |
||
46 | return "strftime('%M', " . $adapter->quoteColumn($column) . ')=' . $adapter->quoteValue((string)$value); |
||
47 | |||
48 | case 'hour': |
||
49 | return "strftime('%H', " . $adapter->quoteColumn($column) . ')=' . $adapter->quoteValue((string)$value); |
||
50 | |||
51 | case 'day': |
||
52 | return "strftime('%d', " . $adapter->quoteColumn($column) . ')=' . $adapter->quoteValue((string)$value); |
||
53 | |||
54 | case 'month': |
||
55 | $value = (int)$value; |
||
56 | if (strlen($value) == 1) { |
||
57 | $value = "0" . (string)$value; |
||
58 | } |
||
59 | return "strftime('%m', " . $adapter->quoteColumn($column) . ')=' . $adapter->quoteValue((string)$value); |
||
60 | |||
61 | case 'week_day': |
||
62 | $value = (int)$value + 1; |
||
63 | if ($value == 7) { |
||
64 | $value = 1; |
||
65 | } |
||
66 | return "strftime('%w', " . $adapter->quoteColumn($column) . ')=' . $adapter->quoteValue((string)$value); |
||
67 | |||
68 | case 'range': |
||
69 | list($min, $max) = $value; |
||
70 | return $adapter->quoteColumn($column) . ' BETWEEN ' . (int)$min . ' AND ' . (int)$max; |
||
71 | } |
||
72 | |||
73 | return parent::process($adapter, $lookup, $column, $value); |
||
74 | } |
||
75 | } |