Test Setup Failed
Push — master ( 5f91b0...6744c8 )
by Php Easy Api
03:31
created
src/resta/Exception/ErrorProvider.php 2 patches
Spacing   +57 added lines, -58 removed lines patch added patch discarded remove patch
@@ -37,7 +37,7 @@  discard block
 block discarded – undo
37 37
      */
38 38
     private function getStatusAccordingToExceptionTrace()
39 39
     {
40
-        if($this->app->has('exceptiontrace')) {
40
+        if ($this->app->has('exceptiontrace')) {
41 41
             $this->data['status'] = (int)$this->app['exceptiontrace']['callNamespace']->getCode();
42 42
         }
43 43
         else {
@@ -54,21 +54,21 @@  discard block
 block discarded – undo
54 54
 
55 55
         $this->app->terminate('responseSuccess');
56 56
         $this->app->terminate('responseStatus');
57
-        $this->app->register('responseSuccess',(bool)false);
58
-        $this->app->register('responseStatus',$this->data['status']);
57
+        $this->app->register('responseSuccess', (bool)false);
58
+        $this->app->register('responseStatus', $this->data['status']);
59 59
 
60 60
 
61
-        $optionalException = str_replace("\\","\\\\",$this->app->namespace()->exception());
61
+        $optionalException = str_replace("\\", "\\\\", $this->app->namespace()->exception());
62 62
 
63
-        if(preg_match('@'.$optionalException.'@is',$this->data['errType'])){
63
+        if (preg_match('@'.$optionalException.'@is', $this->data['errType'])) {
64 64
 
65 65
             //trace pattern
66 66
             $trace = $this->data['errContext']['trace'];
67
-            if(preg_match('@Stack trace:\n#0(.*)\n#1@is',$trace,$traceArray)){
67
+            if (preg_match('@Stack trace:\n#0(.*)\n#1@is', $trace, $traceArray)) {
68 68
 
69
-                $traceFile = str_replace(root,'',$traceArray[1]);
69
+                $traceFile = str_replace(root, '', $traceArray[1]);
70 70
 
71
-                if(preg_match('@(.*)\((\d+)\)@is',$traceFile,$traceResolve)){
71
+                if (preg_match('@(.*)\((\d+)\)@is', $traceFile, $traceResolve)) {
72 72
                     $this->data['errFile'] = $traceResolve[1];
73 73
                     $this->data['errLine'] = (int)$traceResolve[2];
74 74
                 }
@@ -78,15 +78,15 @@  discard block
 block discarded – undo
78 78
             $this->data['errType'] = class_basename($this->data['errType']);
79 79
         }
80 80
 
81
-        if(is_array($meta = config('response.meta'))){
81
+        if (is_array($meta = config('response.meta'))) {
82 82
 
83 83
             //set as the success object is false
84 84
             $this->data['appExceptionSuccess'] = [];
85 85
         }
86
-        else{
86
+        else {
87 87
 
88 88
             //set as the success object is false
89
-            $this->data['appExceptionSuccess'] = ['success'=>(bool)false,'status'=>$this->data['status']];
89
+            $this->data['appExceptionSuccess'] = ['success'=>(bool)false, 'status'=>$this->data['status']];
90 90
         }
91 91
     }
92 92
 
@@ -108,13 +108,13 @@  discard block
 block discarded – undo
108 108
         //This function can be used for defining your own way of handling errors during runtime,
109 109
         //for example in applications in which you need to do cleanup of data/files when a critical error happens,
110 110
         //or when you need to trigger an error under certain conditions (using trigger_error()).
111
-        set_error_handler([$this,'setErrorHandler']);
111
+        set_error_handler([$this, 'setErrorHandler']);
112 112
 
113 113
         //Registers a callback to be executed after script execution finishes or exit() is called.
114 114
         //Multiple calls to register_shutdown_function() can be made, and each will be called in the same order as
115 115
         //they were registered. If you call exit() within one registered shutdown function,
116 116
         //processing will stop completely and no other registered shutdown functions will be called.
117
-        register_shutdown_function([$this,'fatalErrorShutdownHandler']);
117
+        register_shutdown_function([$this, 'fatalErrorShutdownHandler']);
118 118
     }
119 119
 
120 120
     /**
@@ -126,7 +126,7 @@  discard block
 block discarded – undo
126 126
      * @param null|string $errLine
127 127
      * @param null|string $errContext
128 128
      */
129
-    public function setErrorHandler($errNo=null, $errStr=null, $errFile=null, $errLine=null, $errContext=null)
129
+    public function setErrorHandler($errNo = null, $errStr = null, $errFile = null, $errLine = null, $errContext = null)
130 130
     {
131 131
         // in case of a deficiency,
132 132
         // we need to boot our general needs to be needed for the exception.
@@ -153,7 +153,7 @@  discard block
 block discarded – undo
153 153
         //get lang message for exception
154 154
         $this->getLangMessageForException();
155 155
 
156
-        if($this->app->has('exceptiontrace')){
156
+        if ($this->app->has('exceptiontrace')) {
157 157
 
158 158
             $customExceptionTrace   = $this->app['exceptiontrace'];
159 159
             $this->data['errFile']  = $customExceptionTrace['file'];
@@ -162,37 +162,36 @@  discard block
 block discarded – undo
162 162
 
163 163
         $environment = $this->app->environment();
164 164
 
165
-        $vendorDirectory = str_replace(root.''.DIRECTORY_SEPARATOR.'','',$this->data['errFile']);
165
+        $vendorDirectory = str_replace(root.''.DIRECTORY_SEPARATOR.'', '', $this->data['errFile']);
166 166
 
167
-        if(Str::startsWith($vendorDirectory,'vendor')
168
-            && Str::startsWith($vendorDirectory,'vendor/php-resta')===false)
167
+        if (Str::startsWith($vendorDirectory, 'vendor')
168
+            && Str::startsWith($vendorDirectory, 'vendor/php-resta')===false)
169 169
         {
170 170
             $externalMessage = ($environment==="production") ?
171
-                'An unexpected external error has occurred' :
172
-                $this->data['errStrReal'];
171
+                'An unexpected external error has occurred' : $this->data['errStrReal'];
173 172
 
174
-            $this->result = $this->getAppException($environment,$externalMessage);
173
+            $this->result = $this->getAppException($environment, $externalMessage);
175 174
 
176 175
 
177 176
             //Get or Set the HTTP response code
178 177
             http_response_code(500);
179 178
             $this->app->terminate('responseStatus');
180
-            $this->app->register('responseStatus',500);
179
+            $this->app->register('responseStatus', 500);
181 180
 
182 181
 
183 182
         }
184
-        else{
183
+        else {
185 184
 
186
-            $this->result = $this->getAppException($environment,$this->data['errStrReal']);
185
+            $this->result = $this->getAppException($environment, $this->data['errStrReal']);
187 186
 
188 187
             //Get or Set the HTTP response code
189 188
             http_response_code($this->data['status']);
190 189
         }
191 190
 
192
-        if($environment==="production"){
191
+        if ($environment==="production") {
193 192
 
194
-            $productionLogMessage = $this->getAppException('local',$this->data['errStrReal']);
195
-            $this->app->register('productionLogMessage',$this->app->get('out')->outputFormatter($productionLogMessage));
193
+            $productionLogMessage = $this->getAppException('local', $this->data['errStrReal']);
194
+            $this->app->register('productionLogMessage', $this->app->get('out')->outputFormatter($productionLogMessage));
196 195
         }
197 196
 
198 197
         // exception extender The exception information
@@ -201,15 +200,15 @@  discard block
 block discarded – undo
201 200
 
202 201
 
203 202
         //set json app exception
204
-        $this->app->register('routerResult',$this->result);
203
+        $this->app->register('routerResult', $this->result);
205 204
 
206 205
         $restaOutHandle = null;
207 206
 
208
-        if(!defined('responseApp')){
207
+        if (!defined('responseApp')) {
209 208
             $restaOutHandle = $this->app->get('out')->handle();
210 209
         }
211 210
 
212
-        if($restaOutHandle===null){
211
+        if ($restaOutHandle===null) {
213 212
 
214 213
             //header set and symfony response call
215 214
             header('Content-type:application/json;charset=utf-8');
@@ -217,7 +216,7 @@  discard block
 block discarded – undo
217 216
             echo json_encode($this->app->get('out')->outputFormatter($this->result));
218 217
             exit();
219 218
         }
220
-        else{
219
+        else {
221 220
             echo $restaOutHandle;
222 221
             exit();
223 222
         }
@@ -227,7 +226,7 @@  discard block
 block discarded – undo
227 226
      * @param $environment
228 227
      * @return mixed
229 228
      */
230
-    private function getAppException($environment,$message)
229
+    private function getAppException($environment, $message)
231 230
     {
232 231
         return $this->data['appExceptionSuccess']+$this->data['exception']::$environment(
233 232
                 $this->data['errNo'],
@@ -262,13 +261,13 @@  discard block
 block discarded – undo
262 261
 
263 262
         $this->inStackTrace($last_error);
264 263
 
265
-        if(!is_null($last_error)){
264
+        if (!is_null($last_error)) {
266 265
 
267
-            if(!defined('methodName')){
268
-                define('methodName',null);
266
+            if (!defined('methodName')) {
267
+                define('methodName', null);
269 268
             }
270 269
 
271
-            if($this->app->has('exceptionFile')){
270
+            if ($this->app->has('exceptionFile')) {
272 271
                 $last_error['file'] = $this->app['exceptionFile'];
273 272
                 $last_error['line'] = $this->app['exceptionLine'];
274 273
             }
@@ -288,13 +287,13 @@  discard block
 block discarded – undo
288 287
      */
289 288
     public function inStackTrace($error)
290 289
     {
291
-        if($this->app->has('urlComponent')){
292
-            if(!preg_match('@'.$this->app['urlComponent']['project'].'@',$error['file'])
293
-                && !$this->app->has('exceptionFile')){
294
-                if(preg_match('@ in\s(.*?)\n@is',$error['message'],$result)){
295
-                    $errorMessage = explode(":",$result[1]);
296
-                    $this->app->register('exceptionFile',$errorMessage[0]);
297
-                    $this->app->register('exceptionLine',$errorMessage[1]);
290
+        if ($this->app->has('urlComponent')) {
291
+            if (!preg_match('@'.$this->app['urlComponent']['project'].'@', $error['file'])
292
+                && !$this->app->has('exceptionFile')) {
293
+                if (preg_match('@ in\s(.*?)\n@is', $error['message'], $result)) {
294
+                    $errorMessage = explode(":", $result[1]);
295
+                    $this->app->register('exceptionFile', $errorMessage[0]);
296
+                    $this->app->register('exceptionLine', $errorMessage[1]);
298 297
                 }
299 298
             }
300 299
         }
@@ -307,33 +306,33 @@  discard block
 block discarded – undo
307 306
     {
308 307
         $clone = clone $this;
309 308
 
310
-        if($this->app->has('exceptionTranslate')){
309
+        if ($this->app->has('exceptionTranslate')) {
311 310
 
312 311
             $langMessage = trans('exception.'.$this->app->get('exceptionTranslate'));
313 312
 
314
-            if(!is_null($langMessage) && $this->app->has('exceptionTranslateParams')){
313
+            if (!is_null($langMessage) && $this->app->has('exceptionTranslateParams')) {
315 314
 
316
-                if(count($this->app['exceptionTranslateParams'][$this->app['exceptionTranslate']])){
317
-                    foreach ($this->app['exceptionTranslateParams'][$this->app['exceptionTranslate']] as $key=>$value){
315
+                if (count($this->app['exceptionTranslateParams'][$this->app['exceptionTranslate']])) {
316
+                    foreach ($this->app['exceptionTranslateParams'][$this->app['exceptionTranslate']] as $key=>$value) {
318 317
 
319 318
                         $valueLangName = !is_null(trans('default.'.$value)) ? trans('default.'.$value) : $value;
320
-                        $langMessage = preg_replace('@\('.$key.'\)@is',$valueLangName,$langMessage);
319
+                        $langMessage = preg_replace('@\('.$key.'\)@is', $valueLangName, $langMessage);
321 320
                     }
322 321
                 }
323 322
             }
324 323
 
325
-            if($langMessage!==null){
324
+            if ($langMessage!==null) {
326 325
                 $this->data['errStrReal'] = $langMessage;
327 326
             }
328 327
         }
329 328
 
330
-        if(class_exists($this->data['errorClassNamespace'])
329
+        if (class_exists($this->data['errorClassNamespace'])
331 330
             &&
332
-            (Str::startsWith($this->data['errorClassNamespace'],'App')
333
-                || Str::startsWith($this->data['errorClassNamespace'],__NAMESPACE__))){
331
+            (Str::startsWith($this->data['errorClassNamespace'], 'App')
332
+                || Str::startsWith($this->data['errorClassNamespace'], __NAMESPACE__))) {
334 333
 
335 334
             ClosureDispatcher::bind($this->data['errorClassNamespace'])->call(function() use ($clone) {
336
-                if(property_exists($this,'lang')){
335
+                if (property_exists($this, 'lang')) {
337 336
                     $clone->lang = $this->lang;
338 337
                 }
339 338
             });
@@ -343,7 +342,7 @@  discard block
 block discarded – undo
343 342
 
344 343
         $langMessage = (!is_null($this->data['lang'])) ? trans('exception.'.$this->data['lang']) : null;
345 344
 
346
-        if($langMessage!==null){
345
+        if ($langMessage!==null) {
347 346
             $this->data['errStrReal'] = $langMessage;
348 347
         }
349 348
     }
@@ -357,14 +356,14 @@  discard block
 block discarded – undo
357 356
     {
358 357
         // catch exception via preg match
359 358
         // and then clear the Uncaught statement from inside.
360
-        if(preg_match('@(.*?):@is',$this->data['errStrReal'],$errArr)){
359
+        if (preg_match('@(.*?):@is', $this->data['errStrReal'], $errArr)) {
361 360
 
362
-            $this->data['errType'] = trim(str_replace('Uncaught','',$errArr[1]));
361
+            $this->data['errType'] = trim(str_replace('Uncaught', '', $errArr[1]));
363 362
             $this->data['errorClassNamespace'] = $this->data['errType'];
364 363
         }
365 364
 
366
-        if(preg_match('@Uncaught@is',$this->data['errStrReal'])
367
-            && preg_match('@(.*?):(.*?)\sin\s@is',$this->data['errStrReal'],$errStrRealArray)){
365
+        if (preg_match('@Uncaught@is', $this->data['errStrReal'])
366
+            && preg_match('@(.*?):(.*?)\sin\s@is', $this->data['errStrReal'], $errStrRealArray)) {
368 367
             $this->data['errStrReal'] = trim($errStrRealArray[2]);
369 368
         }
370 369
 
Please login to merge, or discard this patch.
Braces   +4 added lines, -8 removed lines patch added patch discarded remove patch
@@ -39,8 +39,7 @@  discard block
 block discarded – undo
39 39
     {
40 40
         if($this->app->has('exceptiontrace')) {
41 41
             $this->data['status'] = (int)$this->app['exceptiontrace']['callNamespace']->getCode();
42
-        }
43
-        else {
42
+        } else {
44 43
             $this->data['status'] = (int)$this->exception::exceptionTypeCodes($this->data['errType']);
45 44
         }
46 45
     }
@@ -82,8 +81,7 @@  discard block
 block discarded – undo
82 81
 
83 82
             //set as the success object is false
84 83
             $this->data['appExceptionSuccess'] = [];
85
-        }
86
-        else{
84
+        } else{
87 85
 
88 86
             //set as the success object is false
89 87
             $this->data['appExceptionSuccess'] = ['success'=>(bool)false,'status'=>$this->data['status']];
@@ -180,8 +178,7 @@  discard block
 block discarded – undo
180 178
             $this->app->register('responseStatus',500);
181 179
 
182 180
 
183
-        }
184
-        else{
181
+        } else{
185 182
 
186 183
             $this->result = $this->getAppException($environment,$this->data['errStrReal']);
187 184
 
@@ -216,8 +213,7 @@  discard block
 block discarded – undo
216 213
 
217 214
             echo json_encode($this->app->get('out')->outputFormatter($this->result));
218 215
             exit();
219
-        }
220
-        else{
216
+        } else{
221 217
             echo $restaOutHandle;
222 218
             exit();
223 219
         }
Please login to merge, or discard this patch.