Conditions | 13 |
Paths | 18 |
Total Lines | 45 |
Code Lines | 24 |
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 |
||
73 | public function getFormatted() |
||
74 | { |
||
75 | $value = $this->value; |
||
76 | $characters = $this->characters; |
||
77 | $useHyphen = $this->useHyphen; |
||
78 | |||
79 | // Check if "+" is present, then use it as a hyphen |
||
80 | if (strpos($value, '+') !== false) { |
||
81 | $this->typeHyphen = '+'; |
||
82 | } |
||
83 | |||
84 | // Remove hyphen |
||
85 | $value = str_replace(['-', '+'], '', $value); |
||
86 | |||
87 | if (strlen($value) != 12 && strlen($value) != 10) { |
||
88 | return false; |
||
|
|||
89 | } |
||
90 | |||
91 | if ($characters == 12 && strlen($value) == 10) { |
||
92 | $value = 19 . $value; |
||
93 | } |
||
94 | |||
95 | if ($characters == 10 && strlen($value) == 12) { |
||
96 | $newNumber = null; |
||
97 | for ($i = 0; $i < strlen($value); $i++) { |
||
98 | if ($i > 1) { |
||
99 | $newNumber .= $value[$i]; |
||
100 | } |
||
101 | } |
||
102 | $value = $newNumber; |
||
103 | } |
||
104 | |||
105 | // Insert hyphen if you need to |
||
106 | if ($useHyphen == true) { |
||
107 | $newNumber = null; |
||
108 | for ($i = 0; $i < strlen($value); $i++) { |
||
109 | $newNumber .= $value[$i]; |
||
110 | if ($i == strlen($value) - 5) { |
||
111 | $newNumber .= $this->typeHyphen; |
||
112 | } |
||
113 | } |
||
114 | $value = $newNumber; |
||
115 | } |
||
116 | |||
117 | return $value; |
||
118 | } |
||
120 |