Conditions | 12 |
Paths | 10 |
Total Lines | 39 |
Code Lines | 19 |
Lines | 0 |
Ratio | 0 % |
Tests | 19 |
CRAP Score | 12 |
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 |
||
40 | function formatValue(mixed $value, int $format = 0): string |
||
41 | { |
||
42 | 36 | if (($format & PRETTY_DATE) && $value instanceof \DateTimeInterface) { |
|
43 | 1 | return $value->format('Y-m-d H:i:s'); |
|
44 | } |
||
45 | |||
46 | 35 | if (\is_object($value)) { |
|
47 | 2 | if (($format & OBJECT_TO_STRING) && $value instanceof \Stringable) { |
|
48 | 1 | return $value->__toString(); |
|
49 | } |
||
50 | |||
51 | 1 | return 'object'; |
|
52 | } |
||
53 | |||
54 | 33 | if (\is_array($value)) { |
|
55 | 2 | return 'array'; |
|
56 | } |
||
57 | |||
58 | 31 | if (\is_string($value)) { |
|
59 | 22 | return '"' . $value . '"'; |
|
60 | } |
||
61 | |||
62 | 9 | if (\is_resource($value)) { |
|
63 | 1 | return 'resource'; |
|
64 | } |
||
65 | |||
66 | 8 | if (null === $value) { |
|
67 | 2 | return 'null'; |
|
68 | } |
||
69 | |||
70 | 7 | if (false === $value) { |
|
71 | 1 | return 'false'; |
|
72 | } |
||
73 | |||
74 | 6 | if (true === $value) { |
|
75 | 1 | return 'true'; |
|
76 | } |
||
77 | |||
78 | 5 | return (string) $value; |
|
79 | } |
||
80 |