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 |
||
21 | public function quote($value): string { |
||
22 | if(is_null($value)) { |
||
23 | return 'NULL'; |
||
24 | } |
||
25 | |||
26 | if(is_bool($value)) { |
||
27 | return $value ? '1' : '0'; |
||
28 | } |
||
29 | |||
30 | if(is_array($value)) { |
||
31 | return implode(', ', array_map([$this, __FUNCTION__], $value)); |
||
32 | } |
||
33 | |||
34 | if($value instanceof DBExpr) { |
||
35 | return $value->getExpression(); |
||
36 | } |
||
37 | |||
38 | if($value instanceof Select) { |
||
39 | return sprintf('(%s)', (string) $value); |
||
40 | } |
||
41 | |||
42 | if(is_int($value) || is_float($value)) { |
||
43 | return (string) $value; |
||
44 | } |
||
45 | |||
46 | if($value instanceof DateTimeInterface) { |
||
47 | $value = (new DateTimeImmutable($value->format('c')))->setTimezone($this->timeZone)->format('Y-m-d H:i:s'); |
||
48 | } |
||
49 | |||
50 | return $this->pdo->quote($value); |
||
51 | } |
||
77 |