Passed
Push — main ( 5be53a...df551c )
by Sammy
01:31
created
LogLaddy.php 1 patch
Spacing   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -17,14 +17,14 @@  discard block
 block discarded – undo
17 17
 
18 18
 class LogLaddy implements LoggerInterface
19 19
 {
20
-    use \Psr\Log\LoggerTrait;           // PSR implementation
20
+    use \Psr\Log\LoggerTrait; // PSR implementation
21 21
 
22
-    public const REPORTING_USER = 'user_messages';
23
-    public const INTERNAL_ERROR = 'error';
24
-    public const USER_EXCEPTION = 'exception';
25
-    public const LOG_LEVEL_SUCCESS = 'ok';
22
+    public const REPORTING_USER='user_messages';
23
+    public const INTERNAL_ERROR='error';
24
+    public const USER_EXCEPTION='exception';
25
+    public const LOG_LEVEL_SUCCESS='ok';
26 26
 
27
-    private $has_halting_messages = false;
27
+    private $has_halting_messages=false;
28 28
 
29 29
   /**
30 30
    * Everything went fine, which is always nice.
@@ -34,7 +34,7 @@  discard block
 block discarded – undo
34 34
    *
35 35
    * @return void
36 36
    */
37
-    public function nice($message, array $context = array())
37
+    public function nice($message, array $context=array())
38 38
     {
39 39
         $this->log(LogLevel::NICE, $message, $context);
40 40
     }
@@ -43,9 +43,9 @@  discard block
 block discarded – undo
43 43
     * static handlers for error,
44 44
     * use set_error_handler('\HexMakina\kadro\Logger\LogLaddy::error_handler')
45 45
     */
46
-    public static function error_handler($level, $message, $file = '', $line = 0)
46
+    public static function error_handler($level, $message, $file='', $line=0)
47 47
     {
48
-        $loglevel = self::map_error_level_to_log_level($level);
48
+        $loglevel=self::map_error_level_to_log_level($level);
49 49
 
50 50
         (new LogLaddy())->$loglevel($message, ['file' => $file, 'line' => $line, 'trace' => debug_backtrace()]);
51 51
     }
@@ -56,7 +56,7 @@  discard block
 block discarded – undo
56 56
     */
57 57
     public static function exception_handler(\Throwable $throwable)
58 58
     {
59
-        $lad = new LogLaddy();
59
+        $lad=new LogLaddy();
60 60
 
61 61
         if ($throwable instanceof \Exception) {
62 62
             $lad->alert(self::USER_EXCEPTION, [$throwable]);
@@ -82,22 +82,22 @@  discard block
 block discarded – undo
82 82
 
83 83
   // -- Implementation of LoggerInterface::log(), all other methods are in LoggerTrait
84 84
 
85
-    public function log($level, $message, array $context = [])
85
+    public function log($level, $message, array $context=[])
86 86
     {
87
-        $display_error = null;
87
+        $display_error=null;
88 88
 
89 89
       // --- Handles Throwables (exception_handler())
90 90
         if ($message === self::INTERNAL_ERROR || $message === self::USER_EXCEPTION) {
91
-            $this->has_halting_messages = true;
92
-            if (($context = current($context)) !== false) {
93
-                $display_error = Debugger::formatThrowable($context);
91
+            $this->has_halting_messages=true;
92
+            if (($context=current($context)) !== false) {
93
+                $display_error=Debugger::formatThrowable($context);
94 94
             }
95 95
             error_log($display_error);
96
-            $display_error .= Debugger::tracesToString($context['trace'], false);
96
+            $display_error.=Debugger::tracesToString($context['trace'], false);
97 97
             self::HTTP_500($display_error);
98 98
         } elseif ($this->system_halted($level)) { // analyses error level
99
-            $display_error = sprintf(
100
-                PHP_EOL . '%s in file %s:%d' . PHP_EOL . '%s',
99
+            $display_error=sprintf(
100
+                PHP_EOL.'%s in file %s:%d'.PHP_EOL.'%s',
101 101
                 $level,
102 102
                 Debugger::formatFilename($context['file']),
103 103
                 $context['line'],
@@ -105,7 +105,7 @@  discard block
 block discarded – undo
105 105
             );
106 106
 
107 107
             error_log($display_error);
108
-            $display_error .= Debugger::tracesToString($context['trace'], true);
108
+            $display_error.=Debugger::tracesToString($context['trace'], true);
109 109
             self::HTTP_500($display_error);
110 110
         } else {// --- Handles user messages, through SESSION storage
111 111
             $this->report_to_user($level, $message, $context);
@@ -128,17 +128,17 @@  discard block
 block discarded – undo
128 128
   // -- User messages
129 129
 
130 130
   // -- User messages:add one
131
-    public function report_to_user($level, $message, $context = [])
131
+    public function report_to_user($level, $message, $context=[])
132 132
     {
133 133
         if (!isset($_SESSION[self::REPORTING_USER])) {
134
-            $_SESSION[self::REPORTING_USER] = [];
134
+            $_SESSION[self::REPORTING_USER]=[];
135 135
         }
136 136
 
137 137
         if (!isset($_SESSION[self::REPORTING_USER][$level])) {
138
-            $_SESSION[self::REPORTING_USER][$level] = [];
138
+            $_SESSION[self::REPORTING_USER][$level]=[];
139 139
         }
140 140
 
141
-        $_SESSION[self::REPORTING_USER][$level][] = [$message, $context];
141
+        $_SESSION[self::REPORTING_USER][$level][]=[$message, $context];
142 142
     }
143 143
 
144 144
   // -- User messages:get all
@@ -167,24 +167,24 @@  discard block
 block discarded – undo
167 167
     private static function map_error_level_to_log_level($level): string
168 168
     {
169 169
       // http://php.net/manual/en/errorfunc.constants.php
170
-        $m = [];
170
+        $m=[];
171 171
 
172
-        $m[E_ERROR] = $m[E_PARSE] = $m[E_CORE_ERROR] = $m[E_COMPILE_ERROR] = $m[E_USER_ERROR] = $m[E_RECOVERABLE_ERROR] = LogLevel::ALERT;
173
-        $m[1] = $m[4] = $m[16] = $m[64] = $m[256] = $m[4096] = LogLevel::ALERT;
172
+        $m[E_ERROR]=$m[E_PARSE]=$m[E_CORE_ERROR]=$m[E_COMPILE_ERROR]=$m[E_USER_ERROR]=$m[E_RECOVERABLE_ERROR]=LogLevel::ALERT;
173
+        $m[1]=$m[4]=$m[16]=$m[64]=$m[256]=$m[4096]=LogLevel::ALERT;
174 174
 
175
-        $m[E_WARNING] = $m[E_CORE_WARNING] = $m[E_COMPILE_WARNING] = $m[E_USER_WARNING] = LogLevel::CRITICAL;
176
-        $m[2] = $m[32] = $m[128] = $m[512] = LogLevel::CRITICAL;
175
+        $m[E_WARNING]=$m[E_CORE_WARNING]=$m[E_COMPILE_WARNING]=$m[E_USER_WARNING]=LogLevel::CRITICAL;
176
+        $m[2]=$m[32]=$m[128]=$m[512]=LogLevel::CRITICAL;
177 177
 
178
-        $m[E_NOTICE] = $m[E_USER_NOTICE] = LogLevel::ERROR;
179
-        $m[8] = $m[1024] = LogLevel::ERROR;
178
+        $m[E_NOTICE]=$m[E_USER_NOTICE]=LogLevel::ERROR;
179
+        $m[8]=$m[1024]=LogLevel::ERROR;
180 180
 
181
-        $m[E_STRICT] = $m[E_DEPRECATED] = $m[E_USER_DEPRECATED] = $m[E_ALL] = LogLevel::DEBUG;
182
-        $m[2048] = $m[8192] = $m[16384] = $m[32767] = LogLevel::DEBUG;
181
+        $m[E_STRICT]=$m[E_DEPRECATED]=$m[E_USER_DEPRECATED]=$m[E_ALL]=LogLevel::DEBUG;
182
+        $m[2048]=$m[8192]=$m[16384]=$m[32767]=LogLevel::DEBUG;
183 183
 
184 184
         if (isset($m[$level])) {
185 185
             return $m[$level];
186 186
         }
187 187
 
188
-        throw new \Exception(__FUNCTION__ . "($level): $level is unknown");
188
+        throw new \Exception(__FUNCTION__."($level): $level is unknown");
189 189
     }
190 190
 }
Please login to merge, or discard this patch.