Conditions | 10 |
Paths | 12 |
Total Lines | 74 |
Code Lines | 48 |
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 |
||
23 | function smarty_modifier_capitalize($string, $uc_digits = false, $lc_rest = false) |
||
24 | { |
||
25 | if (Smarty::$_MBSTRING) { |
||
26 | if ($lc_rest) { |
||
27 | // uppercase (including hyphenated words) |
||
28 | $upper_string = mb_convert_case($string, MB_CASE_TITLE, Smarty::$_CHARSET); |
||
29 | } else { |
||
30 | // uppercase word breaks |
||
31 | $upper_string = preg_replace_callback( |
||
32 | "!(^|[^\p{L}'])([\p{Ll}])!S" . Smarty::$_UTF8_MODIFIER, |
||
33 | 'smarty_mod_cap_mbconvert_cb', |
||
34 | $string |
||
35 | ); |
||
36 | } |
||
37 | // check uc_digits case |
||
38 | if (!$uc_digits) { |
||
39 | if (preg_match_all( |
||
40 | "!\b([\p{L}]*[\p{N}]+[\p{L}]*)\b!" . Smarty::$_UTF8_MODIFIER, |
||
41 | $string, |
||
42 | $matches, |
||
43 | PREG_OFFSET_CAPTURE |
||
44 | ) |
||
45 | ) { |
||
46 | foreach ($matches[ 1 ] as $match) { |
||
47 | $upper_string = |
||
48 | substr_replace( |
||
49 | $upper_string, |
||
50 | mb_strtolower($match[ 0 ], Smarty::$_CHARSET), |
||
51 | $match[ 1 ], |
||
52 | strlen($match[ 0 ]) |
||
53 | ); |
||
54 | } |
||
55 | } |
||
56 | } |
||
57 | $upper_string = |
||
58 | preg_replace_callback( |
||
59 | "!((^|\s)['\"])(\w)!" . Smarty::$_UTF8_MODIFIER, |
||
60 | 'smarty_mod_cap_mbconvert2_cb', |
||
61 | $upper_string |
||
62 | ); |
||
63 | return $upper_string; |
||
64 | } |
||
65 | // lowercase first |
||
66 | if ($lc_rest) { |
||
67 | $string = strtolower($string); |
||
68 | } |
||
69 | // uppercase (including hyphenated words) |
||
70 | $upper_string = |
||
71 | preg_replace_callback( |
||
72 | "!(^|[^\p{L}'])([\p{Ll}])!S" . Smarty::$_UTF8_MODIFIER, |
||
73 | 'smarty_mod_cap_ucfirst_cb', |
||
74 | $string |
||
75 | ); |
||
76 | // check uc_digits case |
||
77 | if (!$uc_digits) { |
||
78 | if (preg_match_all( |
||
79 | "!\b([\p{L}]*[\p{N}]+[\p{L}]*)\b!" . Smarty::$_UTF8_MODIFIER, |
||
80 | $string, |
||
81 | $matches, |
||
82 | PREG_OFFSET_CAPTURE |
||
83 | ) |
||
84 | ) { |
||
85 | foreach ($matches[ 1 ] as $match) { |
||
86 | $upper_string = |
||
87 | substr_replace($upper_string, strtolower($match[ 0 ]), $match[ 1 ], strlen($match[ 0 ])); |
||
88 | } |
||
89 | } |
||
90 | } |
||
91 | $upper_string = preg_replace_callback( |
||
92 | "!((^|\s)['\"])(\w)!" . Smarty::$_UTF8_MODIFIER, |
||
93 | 'smarty_mod_cap_ucfirst2_cb', |
||
94 | $upper_string |
||
95 | ); |
||
96 | return $upper_string; |
||
97 | } |
||
146 |