Conditions | 14 |
Paths | 21 |
Total Lines | 42 |
Code Lines | 35 |
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 |
||
75 | public static function normalize($value) |
||
76 | { |
||
77 | |||
78 | switch (true) { |
||
79 | case $value === 0 : |
||
80 | return ""; |
||
81 | case isset(self::$trans[self::$lang][$value]) : |
||
82 | return self::$trans[self::$lang][$value]; |
||
83 | case $value < 100 : |
||
84 | $module = $value % 10; |
||
85 | $division = floor($value / 10); |
||
86 | if (self::LANG_BG === self::$lang) { |
||
87 | if (isset(self::$trans[self::$lang][$value])) { |
||
88 | return self::$trans[self::$lang][$value]; |
||
89 | } else { |
||
90 | return self::$trans[self::$lang][$division] . self::$trans[self::$lang]['tens'] . self::$trans[self::$lang]['and'] . self::$trans[self::$lang][$module]; |
||
91 | } |
||
92 | } else { |
||
93 | return self::$trans[self::$lang][$value - $module] . '-' . self::$trans[self::$lang][$module]; |
||
94 | } |
||
95 | case $value < 1000 : |
||
96 | $module = $value % 100; |
||
97 | $division = floor($value / 100); |
||
98 | $and = $module <= 20 || $module % 10 === 0 ? self::$trans[self::$lang]['and'] : ' '; |
||
99 | if (self::LANG_BG === self::$lang) { |
||
100 | return (isset(self::$trans[self::$lang][$value - $module]) ? self::$trans[self::$lang][$value - $module] : self::$trans[self::$lang][$division] . self::$trans[self::$lang]['hundreds']) . $and . self::normalize($module); |
||
101 | } else { |
||
102 | return self::$trans[self::$lang][$division] . ' ' . self::$trans[self::$lang]['hundreds'] . $and . self::normalize($module); |
||
103 | } |
||
104 | case $value < 1000000 : |
||
105 | $module = $value % 1000; |
||
106 | $division = $value / 1000; |
||
107 | return self::normalize($division) . ' ' . self::$trans[self::$lang]['thousands'] . ' ' . self::normalize($module); |
||
108 | case $value < 1000000000 : |
||
109 | $module = $value % 1000000; |
||
110 | $division = $value / 1000000; |
||
111 | $millions = floor($value / 1000000); |
||
112 | return self::normalize($division) . ' ' . ($millions == 1 ? self::$trans[self::$lang]['million'] : self::$trans[self::$lang]['millions']) . ' ' . self::normalize($module); |
||
113 | default : |
||
114 | throw new InvalidArgumentException("$value is greeater than 1000000000"); |
||
115 | } |
||
116 | } |
||
117 | |||
132 |
This check examines a number of code elements and verifies that they conform to the given naming conventions.
You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.