Total Complexity | 58 |
Total Lines | 227 |
Duplicated Lines | 0 % |
Changes | 8 | ||
Bugs | 2 | Features | 0 |
Complex classes like TransDate 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 TransDate, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
10 | class TransDate |
||
11 | { |
||
12 | public static function inArabic($theDate) |
||
13 | { |
||
14 | // Define The Zaman after or before |
||
15 | $theDate < Carbon::now() ? $zaman = "قبل " : $zaman = "بعد "; |
||
16 | $theDate = $theDate->diffForHumans(); |
||
17 | $dateArray = explode(" ", $theDate); //return $dateArray; // ["1","day","ago"] |
||
18 | //$period is number, $dateArray[1] is the time $dateArray[0] , $dateArray[2] is the word ago |
||
19 | $time = $dateArray[1]; |
||
20 | $period = $dateArray[0]; |
||
21 | if((new self)->isSecond($time)) |
||
22 | { |
||
23 | return (new self)->handelSeconds($period,$zaman); |
||
24 | } |
||
25 | // handl minutes |
||
26 | if((new self)->isMinute($time)) |
||
27 | { |
||
28 | return (new self)->handelMinutes($period,$zaman); |
||
29 | } |
||
30 | // handl hours |
||
31 | if((new self)->isHour($time)) |
||
32 | { |
||
33 | return (new self)->handelHours($period,$zaman); |
||
34 | } |
||
35 | // handl days |
||
36 | if((new self)->isDay($time)) |
||
37 | { |
||
38 | return (new self)->handelDays($period,$zaman); |
||
39 | } |
||
40 | // handl weeks |
||
41 | if((new self)->isWeek($time)) |
||
42 | { |
||
43 | return (new self)->handelWeeks($period,$zaman); |
||
44 | } |
||
45 | // handl months |
||
46 | if((new self)->isMonth($time)) |
||
47 | { |
||
48 | return (new self)->handelMonths($period,$zaman); |
||
49 | } |
||
50 | // handl years |
||
51 | if((new self)->isYear($time)) |
||
52 | { |
||
53 | return (new self)->handelYears($period,$zaman); |
||
54 | } |
||
55 | } |
||
56 | |||
57 | public function isSecond($time) |
||
58 | { |
||
59 | Str::startsWith($time,'second') ? $isSecond = true : $isSecond = false ; |
||
60 | return $isSecond; |
||
61 | } |
||
62 | |||
63 | public function isMinute($time) |
||
64 | { |
||
65 | Str::startsWith($time,'minute') ? $isMinute = true : $isMinute = false ; |
||
66 | return $isMinute; |
||
67 | } |
||
68 | |||
69 | public function isHour($time) |
||
70 | { |
||
71 | Str::startsWith($time,'hour') ? $isHour = true : $isHour = false ; |
||
72 | return $isHour; |
||
73 | } |
||
74 | |||
75 | public function isDay($time) |
||
76 | { |
||
77 | Str::startsWith($time,'day') ? $isDay = true : $isDay = false ; |
||
78 | return $isDay; |
||
79 | } |
||
80 | |||
81 | public function isWeek($time) |
||
82 | { |
||
83 | Str::startsWith($time,'week') ? $isWeek = true : $isWeek = false ; |
||
84 | return $isWeek; |
||
85 | } |
||
86 | |||
87 | public function isMonth($time) |
||
88 | { |
||
89 | Str::startsWith($time,'month') ? $isMonth = true : $isMonth = false ; |
||
90 | return $isMonth; |
||
91 | } |
||
92 | |||
93 | public function isYear($time) |
||
94 | { |
||
95 | Str::startsWith($time,'year') ? $isYear = true : $isYear = false ; |
||
96 | return $isYear; |
||
97 | } |
||
98 | |||
99 | public function handelSeconds($period,$zaman) |
||
100 | { |
||
101 | // handl seconds |
||
102 | if($period == 1) |
||
103 | { |
||
104 | return $zaman."ثانية واحدة"; |
||
105 | } |
||
106 | elseif($period == 2) |
||
107 | { |
||
108 | return $zaman. "ثانيتين"; |
||
109 | } |
||
110 | elseif($period >= 3 && $period <= 10 ) |
||
111 | { |
||
112 | return $zaman. $period . " ثواني"; |
||
113 | } |
||
114 | else |
||
115 | { |
||
116 | return $zaman. $period . " ثانية"; |
||
117 | } |
||
118 | } |
||
119 | |||
120 | public function handelMinutes($period,$zaman) |
||
137 | } |
||
138 | } |
||
139 | |||
140 | public function handelHours($period,$zaman) |
||
141 | { |
||
142 | if($period == 1) |
||
143 | { |
||
144 | return $zaman."ساعة"; |
||
145 | } |
||
146 | elseif($period == 2) |
||
147 | { |
||
148 | return $zaman. "ساعتين"; |
||
149 | } |
||
150 | elseif($period >= 3 && $period <= 10 ) |
||
151 | { |
||
152 | return $zaman. $period . " ساعات"; |
||
153 | } |
||
154 | else |
||
155 | { |
||
156 | return $zaman. $period . " ساعة"; |
||
157 | } |
||
158 | } |
||
159 | |||
160 | public function handelDays($period,$zaman) |
||
161 | { |
||
162 | if($period == 1) |
||
163 | { |
||
164 | return $zaman." يوم"; |
||
165 | } |
||
166 | elseif($period == 2) |
||
167 | { |
||
168 | return $zaman. "يومين"; |
||
169 | } |
||
170 | elseif($period >= 3 && $period <= 10 ) |
||
171 | { |
||
172 | return $zaman. $period . " أيام"; |
||
173 | } |
||
174 | else |
||
175 | { |
||
176 | return $zaman. $period . " يوم"; |
||
177 | } |
||
178 | } |
||
179 | |||
180 | public function handelWeeks($period,$zaman) |
||
181 | { |
||
182 | if($period == 1) |
||
183 | { |
||
184 | return $zaman." أسبوع"; |
||
185 | } |
||
186 | elseif($period == 2) |
||
187 | { |
||
188 | return $zaman. " أسبوعين"; |
||
189 | } |
||
190 | elseif($period >= 3 && $period <= 10 ) |
||
191 | { |
||
192 | return $zaman. $period . " أسابيع"; |
||
193 | } |
||
194 | else |
||
195 | { |
||
196 | return $zaman. $period . " أسبوع"; |
||
197 | } |
||
198 | } |
||
199 | |||
200 | public function handelMonths($period,$zaman) |
||
217 | } |
||
218 | } |
||
219 | |||
220 | public function handelYears($period,$zaman) |
||
221 | { |
||
222 | if($period == 1) |
||
223 | { |
||
224 | return $zaman."سنة"; |
||
225 | } |
||
226 | elseif($period == 2) |
||
237 | } |
||
238 | } |
||
239 | |||
241 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths