Conditions | 14 |
Paths | 11 |
Total Lines | 38 |
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 |
||
41 | public function stringify($value, $exportObject = true) |
||
42 | { |
||
43 | if (is_array($value)) { |
||
44 | if (range(0, count($value) - 1) === array_keys($value)) { |
||
45 | return '['.implode(', ', array_map(array($this, __FUNCTION__), $value)).']'; |
||
46 | } |
||
47 | |||
48 | $stringify = array($this, __FUNCTION__); |
||
49 | |||
50 | return '['.implode(', ', array_map(function ($item, $key) use ($stringify) { |
||
51 | return (is_integer($key) ? $key : '"'.$key.'"'). |
||
52 | ' => '.call_user_func($stringify, $item); |
||
53 | }, $value, array_keys($value))).']'; |
||
54 | } |
||
55 | if (is_resource($value)) { |
||
56 | return get_resource_type($value).':'.$value; |
||
57 | } |
||
58 | if (is_object($value)) { |
||
59 | return $exportObject ? ExportUtil::export($value) : sprintf('%s:%s', get_class($value), spl_object_hash($value)); |
||
60 | } |
||
61 | if (true === $value || false === $value) { |
||
62 | return $value ? 'true' : 'false'; |
||
63 | } |
||
64 | if (is_string($value)) { |
||
65 | $str = sprintf('"%s"', str_replace("\n", '\\n', $value)); |
||
66 | |||
67 | if (!$this->verbose && 50 <= strlen($str)) { |
||
68 | return substr($str, 0, 50).'"...'; |
||
69 | } |
||
70 | |||
71 | return $str; |
||
72 | } |
||
73 | if (null === $value) { |
||
74 | return 'null'; |
||
75 | } |
||
76 | |||
77 | return (string) $value; |
||
78 | } |
||
79 | |||
100 |