| Total Complexity | 60 |
| Total Lines | 189 |
| Duplicated Lines | 0 % |
| Changes | 13 | ||
| Bugs | 4 | 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 |
||
| 11 | class TransDate |
||
| 12 | { |
||
| 13 | public static function inArabic($theDate) |
||
| 14 | { |
||
| 15 | // Define The Zaman after or before |
||
| 16 | $theDate < Carbon::now() ? $zaman = 'قبل ' : $zaman = 'بعد '; |
||
| 17 | $theDate = $theDate->diffForHumans(); |
||
| 18 | $dateArray = explode(' ', $theDate); //return $dateArray; // ["1","day","ago"] |
||
| 19 | //$period is number, $dateArray[1] is the time $dateArray[0] , $dateArray[2] is the word ago |
||
| 20 | $time = $dateArray[1]; |
||
| 21 | $period = $dateArray[0]; |
||
| 22 | //$dateArray[0] >= 3 ? $period = (new self)->TransNumbers($dateArray[0]) : $period = $dateArray[0]; |
||
| 23 | if ((new self())->isSecond($time)) { |
||
| 24 | return (new self())->handelSeconds($period, $zaman); |
||
| 25 | } |
||
| 26 | // handl minutes |
||
| 27 | if ((new self())->isMinute($time)) { |
||
| 28 | return (new self())->handelMinutes($period, $zaman); |
||
| 29 | } |
||
| 30 | // handl hours |
||
| 31 | if ((new self())->isHour($time)) { |
||
| 32 | return (new self())->handelHours($period, $zaman); |
||
| 33 | } |
||
| 34 | // handl days |
||
| 35 | if ((new self())->isDay($time)) { |
||
| 36 | return (new self())->handelDays($period, $zaman); |
||
| 37 | } |
||
| 38 | // handl weeks |
||
| 39 | if ((new self())->isWeek($time)) { |
||
| 40 | return (new self())->handelWeeks($period, $zaman); |
||
| 41 | } |
||
| 42 | // handl months |
||
| 43 | if ((new self())->isMonth($time)) { |
||
| 44 | return (new self())->handelMonths($period, $zaman); |
||
| 45 | } |
||
| 46 | // handl years |
||
| 47 | if ((new self())->isYear($time)) { |
||
| 48 | return (new self())->handelYears($period, $zaman); |
||
| 49 | } |
||
| 50 | } |
||
| 51 | |||
| 52 | public function isSecond($time) |
||
| 53 | { |
||
| 54 | Str::startsWith($time, 'second') ? $isSecond = true : $isSecond = false; |
||
| 55 | |||
| 56 | return $isSecond; |
||
| 57 | } |
||
| 58 | |||
| 59 | public function isMinute($time) |
||
| 60 | { |
||
| 61 | Str::startsWith($time, 'minute') ? $isMinute = true : $isMinute = false; |
||
| 62 | |||
| 63 | return $isMinute; |
||
| 64 | } |
||
| 65 | |||
| 66 | public function isHour($time) |
||
| 67 | { |
||
| 68 | Str::startsWith($time, 'hour') ? $isHour = true : $isHour = false; |
||
| 69 | |||
| 70 | return $isHour; |
||
| 71 | } |
||
| 72 | |||
| 73 | public function isDay($time) |
||
| 74 | { |
||
| 75 | Str::startsWith($time, 'day') ? $isDay = true : $isDay = false; |
||
| 76 | |||
| 77 | return $isDay; |
||
| 78 | } |
||
| 79 | |||
| 80 | public function isWeek($time) |
||
| 81 | { |
||
| 82 | Str::startsWith($time, 'week') ? $isWeek = true : $isWeek = false; |
||
| 83 | |||
| 84 | return $isWeek; |
||
| 85 | } |
||
| 86 | |||
| 87 | public function isMonth($time) |
||
| 88 | { |
||
| 89 | Str::startsWith($time, 'month') ? $isMonth = true : $isMonth = false; |
||
| 90 | |||
| 91 | return $isMonth; |
||
| 92 | } |
||
| 93 | |||
| 94 | public function isYear($time) |
||
| 95 | { |
||
| 96 | Str::startsWith($time, 'year') ? $isYear = true : $isYear = false; |
||
| 97 | |||
| 98 | return $isYear; |
||
| 99 | } |
||
| 100 | |||
| 101 | public function handelSeconds($period, $zaman) |
||
| 102 | { |
||
| 103 | if ($period == 1) { |
||
| 104 | return $zaman.'ثانية واحدة'; |
||
| 105 | } elseif ($period == 2) { |
||
| 106 | return $zaman.'ثانيتين'; |
||
| 107 | } elseif ($period >= 3 && $period <= 10) { |
||
| 108 | return $zaman.$this->TransNumbers($period).' ثواني'; |
||
| 109 | } else { |
||
| 110 | return $zaman.$this->TransNumbers($period).' ثانية'; |
||
| 111 | } |
||
| 112 | } |
||
| 113 | |||
| 114 | public function handelMinutes($period, $zaman) |
||
| 124 | } |
||
| 125 | } |
||
| 126 | |||
| 127 | public function handelHours($period, $zaman) |
||
| 128 | { |
||
| 129 | if ($period == 1) { |
||
| 130 | return $zaman.'ساعة'; |
||
| 131 | } elseif ($period == 2) { |
||
| 132 | return $zaman.'ساعتين'; |
||
| 133 | } elseif ($period >= 3 && $period <= 10) { |
||
| 134 | return $zaman.$this->TransNumbers($period).' ساعات'; |
||
| 135 | } else { |
||
| 136 | return $zaman.$this->TransNumbers($period).' ساعة'; |
||
| 137 | } |
||
| 138 | } |
||
| 139 | |||
| 140 | public function handelDays($period, $zaman) |
||
| 150 | } |
||
| 151 | } |
||
| 152 | |||
| 153 | public function handelWeeks($period, $zaman) |
||
| 154 | { |
||
| 155 | if ($period == 1) { |
||
| 156 | return $zaman.' أسبوع'; |
||
| 157 | } elseif ($period == 2) { |
||
| 158 | return $zaman.' أسبوعين'; |
||
| 159 | } elseif ($period >= 3 && $period <= 10) { |
||
| 160 | return $zaman.$this->TransNumbers($period).' أسابيع'; |
||
| 161 | } else { |
||
| 162 | return $zaman.$this->TransNumbers($period).' أسبوع'; |
||
| 163 | } |
||
| 164 | } |
||
| 165 | |||
| 166 | public function handelMonths($period, $zaman) |
||
| 176 | } |
||
| 177 | } |
||
| 178 | |||
| 179 | public function handelYears($period, $zaman) |
||
| 180 | { |
||
| 181 | if ($period == 1) { |
||
| 182 | return $zaman.'سنة'; |
||
| 183 | } elseif ($period == 2) { |
||
| 184 | return $zaman.' سنتين'; |
||
| 189 | } |
||
| 190 | } |
||
| 191 | |||
| 192 | protected function TransNumbers($value) |
||
| 200 | } |
||
| 201 | |||
| 202 | } |
||
| 203 |
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