Conditions | 14 |
Paths | 3 |
Total Lines | 45 |
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 |
||
67 | public static function convertString($value) |
||
68 | { |
||
69 | if (strpos($value, '\\') === false) { |
||
70 | return substr($value, 1, -1); |
||
71 | } |
||
72 | |||
73 | if ($value[0] === "'") { |
||
74 | return strtr(substr($value, 1, -1), ['\\\\' => '\\', '\\\'' => '\'']); |
||
75 | } |
||
76 | |||
77 | $value = substr($value, 1, -1); |
||
78 | |||
79 | return preg_replace_callback( |
||
80 | '/\\\(n|r|t|v|e|f|\$|"|\\\|x[0-9A-Fa-f]{1,2}|u{[0-9a-f]{1,6}}|[0-7]{1,3})/', |
||
81 | function ($match) { |
||
82 | switch ($match[1][0]) { |
||
83 | case 'n': |
||
84 | return "\n"; |
||
85 | case 'r': |
||
86 | return "\r"; |
||
87 | case 't': |
||
88 | return "\t"; |
||
89 | case 'v': |
||
90 | return "\v"; |
||
91 | case 'e': |
||
92 | return "\e"; |
||
93 | case 'f': |
||
94 | return "\f"; |
||
95 | case '$': |
||
96 | return '$'; |
||
97 | case '"': |
||
98 | return '"'; |
||
99 | case '\\': |
||
100 | return '\\'; |
||
101 | case 'x': |
||
102 | return chr(hexdec(substr($match[0], 1))); |
||
103 | case 'u': |
||
104 | return self::unicodeChar(hexdec(substr($match[0], 1))); |
||
105 | default: |
||
106 | return chr(octdec($match[0])); |
||
107 | } |
||
108 | }, |
||
109 | $value |
||
110 | ); |
||
111 | } |
||
112 | |||
139 |