Passed
Push — master ( 3c9beb...5bd5b0 )
by Mohammed
02:21 queued 11s
created

TransDate::handelDays()   A

Complexity

Conditions 5
Paths 4

Size

Total Lines 17
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 5
eloc 8
c 1
b 0
f 0
nc 4
nop 2
dl 0
loc 17
rs 9.6111
1
<?php
2
3
    namespace Alkoumi\CarbonDateTranslator;
4
    use Carbon\Carbon;
5
    use Illuminate\Support\Str;
0 ignored issues
show
Bug introduced by
The type Illuminate\Support\Str was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
7
    /*
8
     * this class translates carbon date difference to arabic
9
     */
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)
121
        {
122
            if($period == 1)
123
            {
124
                return $zaman."دقيقة واحدة";
125
            }
126
            elseif($period == 2)
127
            {
128
                return $zaman. "دقيقتين";
129
            }
130
            elseif($period >= 3 && $period <= 10  )
131
            {
132
                return $zaman. $period . " دقائق";
133
            }
134
            else
135
            {
136
                return $zaman.  $period . " دقيقة";
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)
201
        {
202
            if($period == 1)
203
            {
204
                return $zaman."شهر";
205
            }
206
            elseif($period == 2)
207
            {
208
                return $zaman. " شهرين";
209
            }
210
            elseif($period >= 3 && $period <= 10  )
211
            {
212
                return $zaman. $period . " شهور";
213
            }
214
            else
215
            {
216
                return $zaman.  $period . " شهر";
217
            }
218
        }
219
220
        public function handelYears($period,$zaman)
221
        {
222
            if($period == 1)
223
            {
224
                return $zaman."سنة";
225
            }
226
            elseif($period == 2)
227
            {
228
                return $zaman. " سنتين";
229
            }
230
            elseif($period >= 3 && $period <= 10  )
231
            {
232
                return $zaman. $period . " سنوات";
233
            }
234
            else
235
            {
236
                return $zaman.  $period . " سنة";
237
            }
238
        }
239
240
    }
241