Passed
Push — main ( 5ac80e...93508d )
by Sammy
01:29
created
Logger/LogLaddy.class.php 3 patches
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -265,7 +265,7 @@
 block discarded – undo
265 265
    * const NOTICE    = 'notice'; // Normal but significant events.
266 266
    * const INFO      = 'info'; // Interesting events. User logs in, SQL logs.
267 267
    * const DEBUG     = 'debug'; // Detailed debug information.
268
-  */
268
+   */
269 269
   private static function map_error_level_to_log_level($level) : string
270 270
   {
271 271
     // http://php.net/manual/en/errorfunc.constants.php
Please login to merge, or discard this patch.
Spacing   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -11,7 +11,7 @@  discard block
 block discarded – undo
11 11
 
12 12
 namespace HexMakina\kadro\Logger;
13 13
 
14
-use \HexMakina\Crudites\{Crudites,CruditesException,Table};
14
+use \HexMakina\Crudites\{Crudites, CruditesException, Table};
15 15
 use \HexMakina\Crudites\TableInterface;
16 16
 
17 17
 
@@ -68,9 +68,9 @@  discard block
 block discarded – undo
68 68
     $context['class'] = get_class($throwable);
69 69
     $context['trace'] = $throwable->getTrace();
70 70
 
71
-    if(is_subclass_of($throwable, 'Error') || get_class($throwable) === 'Error')
71
+    if (is_subclass_of($throwable, 'Error') || get_class($throwable) === 'Error')
72 72
       (new LogLaddy())->alert(self::INTERNAL_ERROR, $context);
73
-    elseif(is_subclass_of($throwable, 'Exception') || get_class($throwable) === 'Exception')
73
+    elseif (is_subclass_of($throwable, 'Exception') || get_class($throwable) === 'Exception')
74 74
       (new LogLaddy())->notice(self::USER_EXCEPTION, $context);
75 75
     else
76 76
     {
@@ -82,7 +82,7 @@  discard block
 block discarded – undo
82 82
   public function system_halted($level)
83 83
   {
84 84
 
85
-    switch($level)
85
+    switch ($level)
86 86
     {
87 87
       case LogLevel::ERROR:
88 88
       case LogLevel::CRITICAL:
@@ -101,19 +101,19 @@  discard block
 block discarded – undo
101 101
     $display_error = null;
102 102
 
103 103
     // --- Handles Throwables (exception_handler())
104
-    if($message==self::INTERNAL_ERROR || $message== self::USER_EXCEPTION)
104
+    if ($message == self::INTERNAL_ERROR || $message == self::USER_EXCEPTION)
105 105
     {
106 106
       $this->has_halting_messages = true;
107 107
       $display_error = \HexMakina\Debugger\Debugger::format_throwable_message($context['class'], $context['code'], $context['file'], $context['line'], $context['text']);
108 108
       error_log($display_error);
109
-      $display_error.= \HexMakina\Debugger\Debugger::format_trace($context['trace'], false);
109
+      $display_error .= \HexMakina\Debugger\Debugger::format_trace($context['trace'], false);
110 110
       self::HTTP_500($display_error);
111 111
     }
112
-    elseif($this->system_halted($level)) // analyses error level
112
+    elseif ($this->system_halted($level)) // analyses error level
113 113
     {
114 114
       $display_error = sprintf(PHP_EOL.'%s in file %s:%d'.PHP_EOL.'%s', $level, \HexMakina\Debugger\Debugger::format_file($context['file']), $context['line'], $message);
115 115
       error_log($display_error);
116
-      $display_error.= \HexMakina\Debugger\Debugger::format_trace($context['trace'], false);
116
+      $display_error .= \HexMakina\Debugger\Debugger::format_trace($context['trace'], false);
117 117
       self::HTTP_500($display_error);
118 118
     }
119 119
     else
@@ -165,10 +165,10 @@  discard block
 block discarded – undo
165 165
   // ----------------------------------------------------------- User messages:add one
166 166
   public function report_to_user($level, $message, $context = [])
167 167
   {
168
-    if(!isset($_SESSION[self::REPORTING_USER]))
168
+    if (!isset($_SESSION[self::REPORTING_USER]))
169 169
       $_SESSION[self::REPORTING_USER] = [];
170 170
 
171
-    if(!isset($_SESSION[self::REPORTING_USER][$level]))
171
+    if (!isset($_SESSION[self::REPORTING_USER][$level]))
172 172
       $_SESSION[self::REPORTING_USER][$level] = [];
173 173
 
174 174
     $_SESSION[self::REPORTING_USER][$level][] = [$message, $context];
@@ -203,16 +203,16 @@  discard block
 block discarded – undo
203 203
   // }
204 204
 
205 205
   // ----------------------------------------------------------- CRUD Tracking:get for many models
206
-  public function changes($options=[])
206
+  public function changes($options = [])
207 207
   {
208 208
 
209
-    if(!isset($options['limit']) || empty($options['limit']))
209
+    if (!isset($options['limit']) || empty($options['limit']))
210 210
       $limit = 1000;
211 211
     else  $limit = intval($options['limit']);
212 212
 
213 213
     // TODO SELECT field order can't change without adapting the result parsing code (foreach $res)
214 214
     $table = Crudites::inspect(self::LOG_TABLE_NAME);
215
-    $select_fields = ['SUBSTR(query_on, 1, 10) AS working_day', 'query_table', 'query_id',  'GROUP_CONCAT(DISTINCT query_type, "-", query_by) as action_by'];
215
+    $select_fields = ['SUBSTR(query_on, 1, 10) AS working_day', 'query_table', 'query_id', 'GROUP_CONCAT(DISTINCT query_type, "-", query_by) as action_by'];
216 216
     $q = $table->select($select_fields);
217 217
     $q->order_by(['', 'working_day', 'DESC']);
218 218
     $q->order_by([self::LOG_TABLE_NAME, 'query_table', 'DESC']);
@@ -224,30 +224,30 @@  discard block
 block discarded – undo
224 224
     $q->having("action_by NOT LIKE '%D%'");
225 225
     $q->limit($limit);
226 226
 
227
-    foreach($options as $o => $v)
227
+    foreach ($options as $o => $v)
228 228
     {
229
-          if(preg_match('/id/', $o))                    $q->aw_eq('query_id', $v);
230
-      elseif(preg_match('/tables/', $o))                $q->aw_string_in('query_table', is_array($v) ? $v : [$v]);
231
-      elseif(preg_match('/table/', $o))                 $q->aw_eq('query_table', $v);
232
-      elseif(preg_match('/(type|action)/', $o))         $q->aw_string_in('query_type', is_array($v) ? $v : [$v]);
233
-      elseif(preg_match('/(date|query_on)/', $o))       $q->aw_like('query_on', "$v%");
234
-      elseif(preg_match('/(oper|user|query_by)/', $o))  $q->aw_eq('query_by', $v);
229
+          if (preg_match('/id/', $o))                    $q->aw_eq('query_id', $v);
230
+      elseif (preg_match('/tables/', $o))                $q->aw_string_in('query_table', is_array($v) ? $v : [$v]);
231
+      elseif (preg_match('/table/', $o))                 $q->aw_eq('query_table', $v);
232
+      elseif (preg_match('/(type|action)/', $o))         $q->aw_string_in('query_type', is_array($v) ? $v : [$v]);
233
+      elseif (preg_match('/(date|query_on)/', $o))       $q->aw_like('query_on', "$v%");
234
+      elseif (preg_match('/(oper|user|query_by)/', $o))  $q->aw_eq('query_by', $v);
235 235
     }
236 236
 
237
-    try{$q->run();}
238
-    catch(CruditesException $e){vdt($e);return false;}
237
+    try {$q->run(); }
238
+    catch (CruditesException $e) {vdt($e); return false; }
239 239
 
240 240
     $res = $q->ret_num(); // ret num to list()
241 241
     // ddt($res);
242 242
     $ret = [];
243 243
 
244
-    foreach($res as $r)
244
+    foreach ($res as $r)
245 245
     {
246 246
       list($working_day, $class, $instance_id, $logs) = $r;
247 247
 
248
-      if(!isset($ret[$working_day]))
248
+      if (!isset($ret[$working_day]))
249 249
         $ret[$working_day] = [];
250
-      if(!isset($ret[$working_day][$class]))
250
+      if (!isset($ret[$working_day][$class]))
251 251
         $ret[$working_day][$class] = [];
252 252
 
253 253
       $ret[$working_day][$class][$instance_id] = $logs;
@@ -270,19 +270,19 @@  discard block
 block discarded – undo
270 270
   {
271 271
     // http://php.net/manual/en/errorfunc.constants.php
272 272
 
273
-    $m[E_ERROR]=$m[E_PARSE]=$m[E_CORE_ERROR]=$m[E_COMPILE_ERROR]=$m[E_USER_ERROR]=$m[E_RECOVERABLE_ERROR]=LogLevel::ALERT;
274
-    $m[1]=$m[4]=$m[16]=$m[64]=$m[256]=$m[4096]=LogLevel::ALERT;
273
+    $m[E_ERROR] = $m[E_PARSE] = $m[E_CORE_ERROR] = $m[E_COMPILE_ERROR] = $m[E_USER_ERROR] = $m[E_RECOVERABLE_ERROR] = LogLevel::ALERT;
274
+    $m[1] = $m[4] = $m[16] = $m[64] = $m[256] = $m[4096] = LogLevel::ALERT;
275 275
 
276
-    $m[E_WARNING]=$m[E_CORE_WARNING]=$m[E_COMPILE_WARNING]=$m[E_USER_WARNING]=LogLevel::CRITICAL;
277
-    $m[2]=$m[32]=$m[128]=$m[512]=LogLevel::CRITICAL;
276
+    $m[E_WARNING] = $m[E_CORE_WARNING] = $m[E_COMPILE_WARNING] = $m[E_USER_WARNING] = LogLevel::CRITICAL;
277
+    $m[2] = $m[32] = $m[128] = $m[512] = LogLevel::CRITICAL;
278 278
 
279
-    $m[E_NOTICE]=$m[E_USER_NOTICE]=LogLevel::ERROR;
280
-    $m[8]=$m[1024]=LogLevel::ERROR;
279
+    $m[E_NOTICE] = $m[E_USER_NOTICE] = LogLevel::ERROR;
280
+    $m[8] = $m[1024] = LogLevel::ERROR;
281 281
 
282
-    $m[E_STRICT]=$m[E_DEPRECATED]=$m[E_USER_DEPRECATED]=$m[E_ALL]=LogLevel::DEBUG;
283
-    $m[2048]=$m[8192]=$m[16384]=$m[32767]=LogLevel::DEBUG;
282
+    $m[E_STRICT] = $m[E_DEPRECATED] = $m[E_USER_DEPRECATED] = $m[E_ALL] = LogLevel::DEBUG;
283
+    $m[2048] = $m[8192] = $m[16384] = $m[32767] = LogLevel::DEBUG;
284 284
 
285
-    if(isset($m[$level]))
285
+    if (isset($m[$level]))
286 286
       return $m[$level];
287 287
 
288 288
     throw new \Exception(__FUNCTION__."($level): $level is unknown");
Please login to merge, or discard this patch.
Braces   +43 added lines, -30 removed lines patch added patch discarded remove patch
@@ -68,11 +68,11 @@  discard block
 block discarded – undo
68 68
     $context['class'] = get_class($throwable);
69 69
     $context['trace'] = $throwable->getTrace();
70 70
 
71
-    if(is_subclass_of($throwable, 'Error') || get_class($throwable) === 'Error')
72
-      (new LogLaddy())->alert(self::INTERNAL_ERROR, $context);
73
-    elseif(is_subclass_of($throwable, 'Exception') || get_class($throwable) === 'Exception')
74
-      (new LogLaddy())->notice(self::USER_EXCEPTION, $context);
75
-    else
71
+    if(is_subclass_of($throwable, 'Error') || get_class($throwable) === 'Error') {
72
+          (new LogLaddy())->alert(self::INTERNAL_ERROR, $context);
73
+    } elseif(is_subclass_of($throwable, 'Exception') || get_class($throwable) === 'Exception') {
74
+          (new LogLaddy())->notice(self::USER_EXCEPTION, $context);
75
+    } else
76 76
     {
77 77
       die('This Throwable is not an Error or an Exception. This is unfortunate.');
78 78
     }
@@ -108,15 +108,15 @@  discard block
 block discarded – undo
108 108
       error_log($display_error);
109 109
       $display_error.= \HexMakina\Debugger\Debugger::format_trace($context['trace'], false);
110 110
       self::HTTP_500($display_error);
111
-    }
112
-    elseif($this->system_halted($level)) // analyses error level
111
+    } elseif($this->system_halted($level)) {
112
+      // analyses error level
113 113
     {
114 114
       $display_error = sprintf(PHP_EOL.'%s in file %s:%d'.PHP_EOL.'%s', $level, \HexMakina\Debugger\Debugger::format_file($context['file']), $context['line'], $message);
115
+    }
115 116
       error_log($display_error);
116 117
       $display_error.= \HexMakina\Debugger\Debugger::format_trace($context['trace'], false);
117 118
       self::HTTP_500($display_error);
118
-    }
119
-    else
119
+    } else
120 120
     {// --- Handles user messages, through SESSION storage
121 121
       $this->report_to_user($level, $message, $context);
122 122
     }
@@ -165,11 +165,13 @@  discard block
 block discarded – undo
165 165
   // ----------------------------------------------------------- User messages:add one
166 166
   public function report_to_user($level, $message, $context = [])
167 167
   {
168
-    if(!isset($_SESSION[self::REPORTING_USER]))
169
-      $_SESSION[self::REPORTING_USER] = [];
168
+    if(!isset($_SESSION[self::REPORTING_USER])) {
169
+          $_SESSION[self::REPORTING_USER] = [];
170
+    }
170 171
 
171
-    if(!isset($_SESSION[self::REPORTING_USER][$level]))
172
-      $_SESSION[self::REPORTING_USER][$level] = [];
172
+    if(!isset($_SESSION[self::REPORTING_USER][$level])) {
173
+          $_SESSION[self::REPORTING_USER][$level] = [];
174
+    }
173 175
 
174 176
     $_SESSION[self::REPORTING_USER][$level][] = [$message, $context];
175 177
   }
@@ -206,9 +208,11 @@  discard block
 block discarded – undo
206 208
   public function changes($options=[])
207 209
   {
208 210
 
209
-    if(!isset($options['limit']) || empty($options['limit']))
210
-      $limit = 1000;
211
-    else  $limit = intval($options['limit']);
211
+    if(!isset($options['limit']) || empty($options['limit'])) {
212
+          $limit = 1000;
213
+    } else {
214
+      $limit = intval($options['limit']);
215
+    }
212 216
 
213 217
     // TODO SELECT field order can't change without adapting the result parsing code (foreach $res)
214 218
     $table = Crudites::inspect(self::LOG_TABLE_NAME);
@@ -226,16 +230,22 @@  discard block
 block discarded – undo
226 230
 
227 231
     foreach($options as $o => $v)
228 232
     {
229
-          if(preg_match('/id/', $o))                    $q->aw_eq('query_id', $v);
230
-      elseif(preg_match('/tables/', $o))                $q->aw_string_in('query_table', is_array($v) ? $v : [$v]);
231
-      elseif(preg_match('/table/', $o))                 $q->aw_eq('query_table', $v);
232
-      elseif(preg_match('/(type|action)/', $o))         $q->aw_string_in('query_type', is_array($v) ? $v : [$v]);
233
-      elseif(preg_match('/(date|query_on)/', $o))       $q->aw_like('query_on', "$v%");
234
-      elseif(preg_match('/(oper|user|query_by)/', $o))  $q->aw_eq('query_by', $v);
233
+          if(preg_match('/id/', $o)) {
234
+            $q->aw_eq('query_id', $v);
235
+          } elseif(preg_match('/tables/', $o)) {
236
+        $q->aw_string_in('query_table', is_array($v) ? $v : [$v]);
237
+      } elseif(preg_match('/table/', $o)) {
238
+        $q->aw_eq('query_table', $v);
239
+      } elseif(preg_match('/(type|action)/', $o)) {
240
+        $q->aw_string_in('query_type', is_array($v) ? $v : [$v]);
241
+      } elseif(preg_match('/(date|query_on)/', $o)) {
242
+        $q->aw_like('query_on', "$v%");
243
+      } elseif(preg_match('/(oper|user|query_by)/', $o)) {
244
+        $q->aw_eq('query_by', $v);
245
+      }
235 246
     }
236 247
 
237
-    try{$q->run();}
238
-    catch(CruditesException $e){vdt($e);return false;}
248
+    try{$q->run();} catch(CruditesException $e){vdt($e);return false;}
239 249
 
240 250
     $res = $q->ret_num(); // ret num to list()
241 251
     // ddt($res);
@@ -245,10 +255,12 @@  discard block
 block discarded – undo
245 255
     {
246 256
       list($working_day, $class, $instance_id, $logs) = $r;
247 257
 
248
-      if(!isset($ret[$working_day]))
249
-        $ret[$working_day] = [];
250
-      if(!isset($ret[$working_day][$class]))
251
-        $ret[$working_day][$class] = [];
258
+      if(!isset($ret[$working_day])) {
259
+              $ret[$working_day] = [];
260
+      }
261
+      if(!isset($ret[$working_day][$class])) {
262
+              $ret[$working_day][$class] = [];
263
+      }
252 264
 
253 265
       $ret[$working_day][$class][$instance_id] = $logs;
254 266
     }
@@ -282,8 +294,9 @@  discard block
 block discarded – undo
282 294
     $m[E_STRICT]=$m[E_DEPRECATED]=$m[E_USER_DEPRECATED]=$m[E_ALL]=LogLevel::DEBUG;
283 295
     $m[2048]=$m[8192]=$m[16384]=$m[32767]=LogLevel::DEBUG;
284 296
 
285
-    if(isset($m[$level]))
286
-      return $m[$level];
297
+    if(isset($m[$level])) {
298
+          return $m[$level];
299
+    }
287 300
 
288 301
     throw new \Exception(__FUNCTION__."($level): $level is unknown");
289 302
   }
Please login to merge, or discard this patch.