Passed
Branch main (c778a9)
by Sammy
02:05
created
Lezer.class.php 1 patch
Spacing   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -9,9 +9,9 @@  discard block
 block discarded – undo
9 9
 namespace HexMakina\Lezer;
10 10
 
11 11
 use \HexMakina\LocalFS\FileSystem;
12
-use \HexMakina\Format\Tempo\{Dato,DatoTempo,Tempo};
12
+use \HexMakina\Format\Tempo\{Dato, DatoTempo, Tempo};
13 13
 
14
-class Lezer extends \i18n{
14
+class Lezer extends \i18n {
15 15
 
16 16
   private $detected_language_files = [];
17 17
   private $detected_language_env = [];
@@ -28,7 +28,7 @@  discard block
 block discarded – undo
28 28
     $this->detect_language_env();
29 29
     $the_one_language = current(array_intersect($this->detect_language_files(), $this->detect_language_env()));
30 30
 
31
-    if($the_one_language)
31
+    if ($the_one_language)
32 32
       $this->setForcedLang($the_one_language);
33 33
 
34 34
     return $the_one_language;
@@ -37,12 +37,12 @@  discard block
 block discarded – undo
37 37
   public function detect_language_files()
38 38
   {
39 39
     $files = FileSystem::preg_scandir(dirname($this->filePath), '/.json$/');
40
-    if(empty($files))
40
+    if (empty($files))
41 41
       return [];
42 42
 
43
-    $files = implode('',$files);
43
+    $files = implode('', $files);
44 44
     $res = preg_match_all('/([a-z]{3})\.json/', $files, $m);
45
-    if($res) // false or 0 is none found
45
+    if ($res) // false or 0 is none found
46 46
       $this->detected_language_files = $m[1];
47 47
     return $this->detected_language_files;
48 48
   }
@@ -101,16 +101,16 @@  discard block
 block discarded – undo
101 101
 
102 102
   public static function model_type_to_label($form_model)
103 103
   {
104
-    return L(sprintf('MODEL_%s_INSTANCE',get_class($form_model)::model_type()));
104
+    return L(sprintf('MODEL_%s_INSTANCE', get_class($form_model)::model_type()));
105 105
   }
106 106
   public static function field_name_to_label($form_model, $field_name)
107 107
   {
108
-    return L(sprintf('MODEL_%s_FIELD_%s',(get_class($form_model))::model_type(), $field_name));
108
+    return L(sprintf('MODEL_%s_FIELD_%s', (get_class($form_model))::model_type(), $field_name));
109 109
   }
110 110
 
111 111
   // options['decimals'] = int
112 112
   // options['abbrev'] = mixed: key needs to be set
113
-  public static function when($event, $options=[])
113
+  public static function when($event, $options = [])
114 114
   {
115 115
     try {
116 116
       $amount_of_days = DatoTempo::days_diff(new \DateTime($event), new \DateTime());
@@ -119,11 +119,11 @@  discard block
 block discarded – undo
119 119
       return __FUNCTION__.': error';
120 120
     }
121 121
 
122
-    if($amount_of_days === -1)
122
+    if ($amount_of_days === -1)
123 123
       return L('DATETIME_RANGE_YESTERDAY');
124
-    elseif($amount_of_days === 0)
124
+    elseif ($amount_of_days === 0)
125 125
       return L('DATETIME_RANGE_TODAY');
126
-    elseif($amount_of_days === 1)
126
+    elseif ($amount_of_days === 1)
127 127
       return L('DATETIME_RANGE_TOMORROW');
128 128
 
129 129
 
@@ -139,49 +139,49 @@  discard block
 block discarded – undo
139 139
 
140 140
     $date_diff = DatoTempo::days_diff_in_parts(abs($amount_of_days));
141 141
     $ordering = [];
142
-    foreach($datetime_parts as $unit => $label)
142
+    foreach ($datetime_parts as $unit => $label)
143 143
     {
144
-      if(!isset($date_diff[$unit]))
144
+      if (!isset($date_diff[$unit]))
145 145
         continue;
146 146
 
147 147
       $qty = (int)$date_diff[$unit];
148 148
 
149
-      if($qty === 0)
149
+      if ($qty === 0)
150 150
         continue;
151 151
 
152
-      if(isset($options['abbrev']))
153
-        $label.= '_ABBREV';
154
-      elseif($qty > 1)
155
-        $label.= '_PLURAL';
152
+      if (isset($options['abbrev']))
153
+        $label .= '_ABBREV';
154
+      elseif ($qty > 1)
155
+        $label .= '_PLURAL';
156 156
 
157 157
       $ordering[$unit] = $qty.' '.L($label).'.';
158 158
     }
159 159
     $ret = (isset($amount_of_days) && $amount_of_days >= 0) ? L('DATETIME_RANGE_PREFIX_FUTURE') : L('DATETIME_RANGE_PREFIX_PAST');
160
-    $ret.= ' '.implode(' & ', array_slice($ordering, 0,2));
160
+    $ret .= ' '.implode(' & ', array_slice($ordering, 0, 2));
161 161
 
162 162
     return $ret;
163 163
   }
164 164
 
165
-  public static function time($time_string, $short=true)
165
+  public static function time($time_string, $short = true)
166 166
   {
167 167
     if ($short === true)
168 168
       $time_string = substr($time_string, 0, 5);
169 169
     return $time_string;
170 170
   }
171 171
 
172
-  public static function human_date($date_string, $short=true)
172
+  public static function human_date($date_string, $short = true)
173 173
   {
174
-    if($date_string === '0000-00-00' || empty($date_string))
174
+    if ($date_string === '0000-00-00' || empty($date_string))
175 175
       return L('MODEL_common_VALUE_EMPTY');
176 176
 
177
-    if(preg_match('/^[0-9]{4}$/', $date_string) === 1)
177
+    if (preg_match('/^[0-9]{4}$/', $date_string) === 1)
178 178
       return intval($date_string);
179 179
 
180
-    list($year, $month, $day) = explode('-',$date_string);
180
+    list($year, $month, $day) = explode('-', $date_string);
181 181
 
182 182
     $ret = intval($day).' '.L("DATETIME_CALENDAR_MONTH_$month");
183 183
 
184
-    if($short === true && Dato::format(null, 'Y') === $year)
184
+    if ($short === true && Dato::format(null, 'Y') === $year)
185 185
       return $ret;
186 186
     else
187 187
       return "$ret $year";
@@ -200,10 +200,10 @@  discard block
 block discarded – undo
200 200
   public static function human_seconds($seconds)
201 201
   {
202 202
     $hours = floor($seconds / 3600);
203
-    $mins = floor(($seconds-$hours*3600) / 60);
203
+    $mins = floor(($seconds-$hours * 3600) / 60);
204 204
     $secs = floor($seconds % 60);
205 205
 
206
-    $hours_format ='%dh %dm %ds';
206
+    $hours_format = '%dh %dm %ds';
207 207
     return sprintf($hours_format, $hours, $mins, $secs);
208 208
   }
209 209
 
Please login to merge, or discard this patch.