Total Complexity | 84 |
Total Lines | 337 |
Duplicated Lines | 0 % |
Changes | 4 | ||
Bugs | 3 | Features | 0 |
Complex classes like Calculators often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Calculators, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
7 | trait Calculators |
||
8 | { |
||
9 | use Digit; |
||
10 | |||
11 | public function classA($arr,$len = 1) |
||
14 | } |
||
15 | |||
16 | public function classB($arr,$len = 2) |
||
75 | } |
||
76 | |||
77 | public function classC($arr,$len = 3) |
||
93 | |||
94 | //return $this->hundreds[$arr[0]] . $this->config['connection_tool'] . $this->classA([$arr[2]]); |
||
95 | } |
||
96 | |||
97 | public function classD($arr,$len = 4) |
||
98 | { |
||
99 | $classC = [$arr[1],$arr[2],$arr[3]]; |
||
100 | |||
101 | if($arr[0]<=2) |
||
102 | $thousands = $this->thousands[$arr[0]] ; |
||
103 | else |
||
104 | $thousands = $this->ones[$arr[0]] . ' ' . $this->thousands['39']; |
||
105 | |||
106 | |||
107 | if($arr[1] == 0 and $arr[2] == 0 and $arr[3] == 0) |
||
108 | return $thousands; |
||
109 | |||
110 | return $thousands . $this->config['connection_tool'] . $this->classC($classC); |
||
111 | } |
||
112 | |||
113 | public function classE($arr,$len = 5) |
||
114 | { |
||
115 | $classC = [$arr[2],$arr[3],$arr[4]]; |
||
116 | |||
117 | if($arr[0] != 0) |
||
118 | { |
||
119 | $conn = ' '; |
||
120 | |||
121 | if($arr[1]>=2 and $arr[0]>1) |
||
122 | { |
||
123 | $conn = $this->config['connection_tool']; |
||
124 | } |
||
125 | |||
126 | if(in_array($arr[1],[2,1])) |
||
127 | $thousands = $this->others[$arr[1]] . $conn . $this->tens[$arr[0]] ; |
||
128 | else |
||
129 | $thousands = $this->ones[$arr[1]] . $conn . $this->tens[$arr[0]] ; |
||
130 | |||
131 | if($arr[1] == 0) |
||
132 | { |
||
133 | if($arr[0]==1) |
||
134 | { |
||
135 | $thousands = $this->ones[10] ; |
||
136 | $thousands.=' ' . $this->thousands[39]; |
||
137 | }else |
||
138 | { |
||
139 | $thousands = $this->tens[$arr[0]] ; |
||
140 | $thousands.=' ' . $this->thousands[1]; |
||
141 | } |
||
142 | |||
143 | }else{ |
||
144 | if($arr[2] == 0 and $arr[3] == 0 and $arr[4] == 0) |
||
145 | { |
||
146 | $thousands.=' ' . $this->thousands[1]; |
||
147 | }else |
||
148 | { |
||
149 | $thousands.=' ' . $this->thousands[1199]; |
||
150 | } |
||
151 | |||
152 | } |
||
153 | |||
154 | }else |
||
155 | { |
||
156 | if(in_array($arr[1],[2,1])) |
||
157 | $thousands = $this->others[$arr[1]] . ' ' ; |
||
158 | else |
||
159 | $thousands = $this->ones[$arr[1]] . ' ' ; |
||
160 | |||
161 | |||
162 | if($arr[1] == 0) |
||
163 | { |
||
164 | //dd($arr[1]); |
||
165 | //dd($arr[2]); |
||
166 | $thousands = $this->tens[$arr[2]] ; |
||
167 | } |
||
168 | |||
169 | $thousands.=' ' . $this->thousands[39]; |
||
170 | } |
||
171 | if($this->classC($classC) != '' ) |
||
172 | { |
||
173 | return $thousands . $this->config['connection_tool'] . $this->classC($classC); |
||
174 | } |
||
175 | return $thousands; |
||
176 | } |
||
177 | |||
178 | public function classF($arr,$len = 6) //100 000 |
||
229 | } |
||
230 | |||
231 | public function classG($arr,$len = 7) //1 000 000 |
||
246 | } |
||
247 | |||
248 | public function classH($arr,$len = 8) |
||
249 | { |
||
250 | //dd($arr,$len); |
||
251 | $classF = [$arr[2],$arr[3],$arr[4],$arr[5],$arr[6],$arr[7]]; |
||
252 | //$classC = [$arr[1],$arr[2],$arr[3]]; |
||
253 | |||
254 | if($arr[0] != 0) |
||
255 | { |
||
256 | $conn = ' '; |
||
257 | |||
258 | if($arr[1]>=2 and $arr[0]>1) |
||
259 | { |
||
260 | $conn = $this->config['connection_tool']; |
||
261 | } |
||
262 | |||
263 | if(in_array($arr[1],[2,1])) |
||
264 | $million = $this->others[$arr[1]] . $conn . $this->tens[$arr[0]] ; |
||
265 | else |
||
266 | $million = $this->ones[$arr[1]] . $conn . $this->tens[$arr[0]] ; |
||
267 | |||
268 | if($arr[1] == 0) |
||
269 | { |
||
270 | if($arr[0]==1) |
||
271 | { |
||
272 | $million = $this->ones[10] ; |
||
273 | $million.=' ' . $this->millions[39]; |
||
274 | }else |
||
275 | { |
||
276 | $million = $this->tens[$arr[0]] ; |
||
277 | $million.=' ' . $this->millions[1]; |
||
278 | } |
||
279 | |||
280 | }else{ |
||
281 | if($arr[2] == 0 and $arr[3] == 0 and $arr[4] == 0) |
||
282 | { |
||
283 | $million.=' ' . $this->millions[1]; |
||
284 | }else |
||
285 | { |
||
286 | $million.=' ' . $this->millions[1199]; |
||
287 | } |
||
288 | |||
289 | } |
||
290 | |||
291 | }else |
||
292 | { |
||
293 | if(in_array($arr[1],[2,1])) |
||
294 | $million = $this->others[$arr[1]] . ' ' ; |
||
295 | else |
||
296 | $million = $this->ones[$arr[1]] . ' ' ; |
||
297 | |||
298 | |||
299 | if($arr[1] == 0) |
||
300 | { |
||
301 | $million = $this->tens[$arr[2]] ; |
||
302 | } |
||
303 | |||
304 | $million.=' ' . $this->millions[39]; |
||
305 | } |
||
306 | // if(in_array($arr[1],[2])) |
||
307 | // $million = $this->others[$arr[1]] . $this->config['connection_tool'] . $this->tens[$arr[0]] ; |
||
308 | // else |
||
309 | // $million = $this->ones[$arr[1]] . $this->config['connection_tool'] . $this->tens[$arr[0]] ; |
||
310 | |||
311 | //$million = $this->ones[$arr[1]] . $this->config['connection_tool'] . $this->tens[$arr[0]] ; |
||
312 | |||
313 | // if($arr[1] == 0) |
||
314 | // { |
||
315 | // $million = $this->tens[$arr[0]] ; |
||
316 | // } |
||
317 | |||
318 | //$million.=' ' . $this->millions[1199]; |
||
319 | |||
320 | return $million . $this->config['connection_tool'] . $this->classC($classF); |
||
321 | } |
||
322 | |||
323 | public function classI($arr,$len = 9) |
||
344 | |||
345 | } |
||
346 | |||
347 | } |
||
351 |