Conditions | 10 |
Paths | 9 |
Total Lines | 30 |
Code Lines | 15 |
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 |
||
26 | public function quote($value): string { |
||
27 | if(is_null($value)) { |
||
28 | return 'NULL'; |
||
29 | } |
||
30 | |||
31 | if(is_bool($value)) { |
||
32 | return $value ? '1' : '0'; |
||
33 | } |
||
34 | |||
35 | if(is_array($value)) { |
||
36 | return implode(', ', array_map([$this, __FUNCTION__], $value)); |
||
37 | } |
||
38 | |||
39 | if($value instanceof DBExpr) { |
||
40 | return $value->getExpression(); |
||
41 | } |
||
42 | |||
43 | if($value instanceof Select) { |
||
44 | return sprintf('(%s)', (string) $value); |
||
45 | } |
||
46 | |||
47 | if(is_int($value) || is_float($value)) { |
||
48 | return (string) $value; |
||
49 | } |
||
50 | |||
51 | if($value instanceof DateTimeInterface) { |
||
52 | $value = date_create_immutable($value->format('c'))->setTimezone($this->timeZone)->format('Y-m-d H:i:s'); |
||
53 | } |
||
54 | |||
55 | return $this->pdo->quote($value); |
||
56 | } |
||
82 |