Test Setup Failed
Push — master ( c3303e...380e22 )
by Php Easy Api
02:57
created
src/resta/Exception/ExceptionExtender.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -22,14 +22,14 @@  discard block
 block discarded – undo
22 22
      * @param ApplicationContracts $app
23 23
      * @param array $result
24 24
      */
25
-    public function __construct(ApplicationContracts $app,$result=array())
25
+    public function __construct(ApplicationContracts $app, $result = array())
26 26
     {
27 27
         parent::__construct($app);
28 28
 
29 29
         $this->result = $result;
30 30
 
31
-        foreach($this->extender as $item){
32
-            if(method_exists($this,$item)){
31
+        foreach ($this->extender as $item) {
32
+            if (method_exists($this, $item)) {
33 33
                 $this->{$item}();
34 34
             }
35 35
         }
@@ -54,8 +54,8 @@  discard block
 block discarded – undo
54 54
     {
55 55
         // we will look at the requestExpected container value to show
56 56
         // the expected values ​​for the request object in the exception output.
57
-        if($this->app->has('requestExpected') && config('app.requestWithError')===true){
58
-            if($requestExpected = $this->app->get('requestExpected')){
57
+        if ($this->app->has('requestExpected') && config('app.requestWithError')===true) {
58
+            if ($requestExpected = $this->app->get('requestExpected')) {
59 59
                 $this->result['request']['expected'] = $requestExpected;
60 60
             }
61 61
         }
Please login to merge, or discard this patch.
src/resta/Exception/ErrorProvider.php 2 patches
Spacing   +63 added lines, -64 removed lines patch added patch discarded remove patch
@@ -48,7 +48,7 @@  discard block
 block discarded – undo
48 48
     {
49 49
         $exception = $this->exception;
50 50
 
51
-        if($this->app->has('exceptiontrace'))
51
+        if ($this->app->has('exceptiontrace'))
52 52
         {
53 53
             $this->data['status'] = (int)$this->app['exceptiontrace']['callNamespace']->getCode();
54 54
         }
@@ -59,21 +59,21 @@  discard block
 block discarded – undo
59 59
 
60 60
         $this->app->terminate('responseSuccess');
61 61
         $this->app->terminate('responseStatus');
62
-        $this->app->register('responseSuccess',(bool)false);
63
-        $this->app->register('responseStatus',$this->data['status']);
62
+        $this->app->register('responseSuccess', (bool)false);
63
+        $this->app->register('responseStatus', $this->data['status']);
64 64
 
65 65
 
66
-        $optionalException = str_replace("\\","\\\\",$this->app->namespace()->exception());
66
+        $optionalException = str_replace("\\", "\\\\", $this->app->namespace()->exception());
67 67
 
68
-        if(preg_match('@'.$optionalException.'@is',$this->data['errType'])){
68
+        if (preg_match('@'.$optionalException.'@is', $this->data['errType'])) {
69 69
 
70 70
             //linux test
71 71
             $trace = $this->data['errContext']['trace'];
72
-            if(preg_match('@Stack trace:\n#0(.*)\n#1@is',$trace,$traceArray)){
72
+            if (preg_match('@Stack trace:\n#0(.*)\n#1@is', $trace, $traceArray)) {
73 73
 
74
-                $traceFile = str_replace(root,'',$traceArray[1]);
74
+                $traceFile = str_replace(root, '', $traceArray[1]);
75 75
 
76
-                if(preg_match('@(.*)\((\d+)\)@is',$traceFile,$traceResolve)){
76
+                if (preg_match('@(.*)\((\d+)\)@is', $traceFile, $traceResolve)) {
77 77
                     $this->data['errFile'] = $traceResolve[1];
78 78
                     $this->data['errLine'] = (int)$traceResolve[2];
79 79
                 }
@@ -83,15 +83,15 @@  discard block
 block discarded – undo
83 83
             $this->data['errType'] = class_basename($this->data['errType']);
84 84
         }
85 85
 
86
-        if(is_array($meta = config('response.meta'))){
86
+        if (is_array($meta = config('response.meta'))) {
87 87
 
88 88
             //set as the success object is false
89 89
             $this->data['appExceptionSuccess'] = [];
90 90
         }
91
-        else{
91
+        else {
92 92
 
93 93
             //set as the success object is false
94
-            $this->data['appExceptionSuccess'] = ['success'=>(bool)false,'status'=>$this->data['status']];
94
+            $this->data['appExceptionSuccess'] = ['success'=>(bool)false, 'status'=>$this->data['status']];
95 95
         }
96 96
     }
97 97
 
@@ -113,13 +113,13 @@  discard block
 block discarded – undo
113 113
         //This function can be used for defining your own way of handling errors during runtime,
114 114
         //for example in applications in which you need to do cleanup of data/files when a critical error happens,
115 115
         //or when you need to trigger an error under certain conditions (using trigger_error()).
116
-        set_error_handler([$this,'setErrorHandler']);
116
+        set_error_handler([$this, 'setErrorHandler']);
117 117
 
118 118
         //Registers a callback to be executed after script execution finishes or exit() is called.
119 119
         //Multiple calls to register_shutdown_function() can be made, and each will be called in the same order as
120 120
         //they were registered. If you call exit() within one registered shutdown function,
121 121
         //processing will stop completely and no other registered shutdown functions will be called.
122
-        register_shutdown_function([$this,'fatalErrorShutdownHandler']);
122
+        register_shutdown_function([$this, 'fatalErrorShutdownHandler']);
123 123
     }
124 124
 
125 125
     /**
@@ -131,7 +131,7 @@  discard block
 block discarded – undo
131 131
      * @param null|string $errLine
132 132
      * @param null|string $errContext
133 133
      */
134
-    public function setErrorHandler($errNo=null, $errStr=null, $errFile=null, $errLine=null, $errContext=null)
134
+    public function setErrorHandler($errNo = null, $errStr = null, $errFile = null, $errLine = null, $errContext = null)
135 135
     {
136 136
         // in case of a deficiency,
137 137
         // we need to boot our general needs to be needed for the exception.
@@ -158,7 +158,7 @@  discard block
 block discarded – undo
158 158
         //get lang message for exception
159 159
         $this->getLangMessageForException();
160 160
 
161
-        if($this->app->has('exceptiontrace')){
161
+        if ($this->app->has('exceptiontrace')) {
162 162
 
163 163
             $customExceptionTrace   = $this->app['exceptiontrace'];
164 164
             $this->data['errFile']  = $customExceptionTrace['file'];
@@ -167,38 +167,37 @@  discard block
 block discarded – undo
167 167
 
168 168
         $environment = $this->getEnvironmentStatus();
169 169
 
170
-        $vendorDirectory = str_replace(root.''.DIRECTORY_SEPARATOR.'','',$this->data['errFile']);
170
+        $vendorDirectory = str_replace(root.''.DIRECTORY_SEPARATOR.'', '', $this->data['errFile']);
171 171
 
172
-        if(Str::startsWith($vendorDirectory,'vendor')
173
-            && Str::startsWith($vendorDirectory,'vendor/php-resta')===false)
172
+        if (Str::startsWith($vendorDirectory, 'vendor')
173
+            && Str::startsWith($vendorDirectory, 'vendor/php-resta')===false)
174 174
         {
175 175
             $externalMessage = ($environment==="production") ?
176
-                'An unexpected external error has occurred' :
177
-                $this->data['errStrReal'];
176
+                'An unexpected external error has occurred' : $this->data['errStrReal'];
178 177
 
179
-            $this->result = $this->getAppException($environment,$externalMessage);
178
+            $this->result = $this->getAppException($environment, $externalMessage);
180 179
 
181 180
 
182 181
             //Get or Set the HTTP response code
183 182
             http_response_code(500);
184 183
             $this->app->terminate('responseStatus');
185
-            $this->app->register('responseStatus',500);
184
+            $this->app->register('responseStatus', 500);
186 185
 
187 186
 
188 187
         }
189
-        else{
188
+        else {
190 189
 
191
-            $this->result = $this->getAppException($environment,$this->data['errStrReal']);
190
+            $this->result = $this->getAppException($environment, $this->data['errStrReal']);
192 191
 
193 192
             //Get or Set the HTTP response code
194 193
             http_response_code($this->data['status']);
195 194
         }
196 195
 
197 196
 
198
-        if($environment==="production"){
197
+        if ($environment==="production") {
199 198
 
200
-            $productionLogMessage = $this->getAppException('local',$this->data['errStrReal']);
201
-            $this->app->register('productionLogMessage',$this->app->get('out')->outputFormatter($productionLogMessage));
199
+            $productionLogMessage = $this->getAppException('local', $this->data['errStrReal']);
200
+            $this->app->register('productionLogMessage', $this->app->get('out')->outputFormatter($productionLogMessage));
202 201
         }
203 202
 
204 203
         // exception extender The exception information
@@ -207,15 +206,15 @@  discard block
 block discarded – undo
207 206
 
208 207
 
209 208
         //set json app exception
210
-        $this->app->register('routerResult',$this->result);
209
+        $this->app->register('routerResult', $this->result);
211 210
 
212 211
         $restaOutHandle = null;
213 212
 
214
-        if(!defined('responseApp')){
213
+        if (!defined('responseApp')) {
215 214
             $restaOutHandle = $this->app->get('out')->handle();
216 215
         }
217 216
 
218
-        if($restaOutHandle===null){
217
+        if ($restaOutHandle===null) {
219 218
 
220 219
             //header set and symfony response call
221 220
             header('Content-type:application/json;charset=utf-8');
@@ -223,7 +222,7 @@  discard block
 block discarded – undo
223 222
             echo json_encode($this->app->get('out')->outputFormatter($this->result));
224 223
             exit();
225 224
         }
226
-        else{
225
+        else {
227 226
             echo $restaOutHandle;
228 227
             exit();
229 228
         }
@@ -233,7 +232,7 @@  discard block
 block discarded – undo
233 232
      * @param $environment
234 233
      * @return mixed
235 234
      */
236
-    private function getAppException($environment,$message)
235
+    private function getAppException($environment, $message)
237 236
     {
238 237
         return $this->data['appExceptionSuccess']+$this->data['exception']::$environment(
239 238
                 $this->data['errNo'],
@@ -268,13 +267,13 @@  discard block
 block discarded – undo
268 267
 
269 268
         $this->inStackTrace($last_error);
270 269
 
271
-        if(!is_null($last_error)){
270
+        if (!is_null($last_error)) {
272 271
 
273
-            if(!defined('methodName')){
274
-                define('methodName',null);
272
+            if (!defined('methodName')) {
273
+                define('methodName', null);
275 274
             }
276 275
 
277
-            if($this->app->has('exceptionFile')){
276
+            if ($this->app->has('exceptionFile')) {
278 277
                 $last_error['file'] = $this->app['exceptionFile'];
279 278
                 $last_error['line'] = $this->app['exceptionLine'];
280 279
             }
@@ -294,13 +293,13 @@  discard block
 block discarded – undo
294 293
      */
295 294
     public function inStackTrace($error)
296 295
     {
297
-        if($this->app->has('urlComponent')){
298
-            if(!preg_match('@'.$this->app['urlComponent']['project'].'@',$error['file'])
299
-                && !$this->app->has('exceptionFile')){
300
-                if(preg_match('@ in\s(.*?)\n@is',$error['message'],$result)){
301
-                    $errorMessage = explode(":",$result[1]);
302
-                    $this->app->register('exceptionFile',$errorMessage[0]);
303
-                    $this->app->register('exceptionLine',$errorMessage[1]);
296
+        if ($this->app->has('urlComponent')) {
297
+            if (!preg_match('@'.$this->app['urlComponent']['project'].'@', $error['file'])
298
+                && !$this->app->has('exceptionFile')) {
299
+                if (preg_match('@ in\s(.*?)\n@is', $error['message'], $result)) {
300
+                    $errorMessage = explode(":", $result[1]);
301
+                    $this->app->register('exceptionFile', $errorMessage[0]);
302
+                    $this->app->register('exceptionLine', $errorMessage[1]);
304 303
                 }
305 304
             }
306 305
         }
@@ -313,31 +312,31 @@  discard block
 block discarded – undo
313 312
     {
314 313
         $clone = clone $this;
315 314
 
316
-        if($this->app->has('exceptionTranslate')){
315
+        if ($this->app->has('exceptionTranslate')) {
317 316
 
318 317
             $langMessage = trans('exception.'.$this->app->get('exceptionTranslate'));
319 318
 
320
-            if(!is_null($langMessage) && $this->app->has('exceptionTranslateParams')){
319
+            if (!is_null($langMessage) && $this->app->has('exceptionTranslateParams')) {
321 320
 
322
-                if(count($this->app['exceptionTranslateParams'][$this->app['exceptionTranslate']])){
323
-                    foreach ($this->app['exceptionTranslateParams'][$this->app['exceptionTranslate']] as $key=>$value){
324
-                        $langMessage=preg_replace('@\('.$key.'\)@is',$value,$langMessage);
321
+                if (count($this->app['exceptionTranslateParams'][$this->app['exceptionTranslate']])) {
322
+                    foreach ($this->app['exceptionTranslateParams'][$this->app['exceptionTranslate']] as $key=>$value) {
323
+                        $langMessage = preg_replace('@\('.$key.'\)@is', $value, $langMessage);
325 324
                     }
326 325
                 }
327 326
             }
328 327
 
329
-            if($langMessage!==null){
328
+            if ($langMessage!==null) {
330 329
                 $this->data['errStrReal'] = $langMessage;
331 330
             }
332 331
         }
333 332
 
334
-        if(class_exists($this->data['errorClassNamespace'])
333
+        if (class_exists($this->data['errorClassNamespace'])
335 334
             &&
336
-            (Str::startsWith($this->data['errorClassNamespace'],'App')
337
-                || Str::startsWith($this->data['errorClassNamespace'],__NAMESPACE__))){
335
+            (Str::startsWith($this->data['errorClassNamespace'], 'App')
336
+                || Str::startsWith($this->data['errorClassNamespace'], __NAMESPACE__))) {
338 337
 
339 338
             ClosureDispatcher::bind($this->data['errorClassNamespace'])->call(function() use ($clone) {
340
-                if(property_exists($this,'lang')){
339
+                if (property_exists($this, 'lang')) {
341 340
                     $clone->lang = $this->lang;
342 341
                 }
343 342
             });
@@ -345,15 +344,15 @@  discard block
 block discarded – undo
345 344
 
346 345
         $this->data['lang'] = $lang = $clone->lang;
347 346
 
348
-        if($lang!==null){
347
+        if ($lang!==null) {
349 348
             $langMessage = trans('exception.'.$lang);
350 349
         }
351
-        else{
350
+        else {
352 351
             $langMessage = null;
353 352
         }
354 353
 
355 354
 
356
-        if($langMessage!==null){
355
+        if ($langMessage!==null) {
357 356
             $this->data['errStrReal'] = $langMessage;
358 357
         }
359 358
     }
@@ -367,21 +366,21 @@  discard block
 block discarded – undo
367 366
     {
368 367
         // catch exception via preg match
369 368
         // and then clear the Uncaught statement from inside.
370
-        if(preg_match('@(.*?):@is',$this->data['errStrReal'],$errArr)){
369
+        if (preg_match('@(.*?):@is', $this->data['errStrReal'], $errArr)) {
371 370
 
372
-            $this->data['errType']=trim(str_replace('Uncaught','',$errArr[1]));
373
-            $this->data['errorClassNamespace']=$this->data['errType'];
371
+            $this->data['errType'] = trim(str_replace('Uncaught', '', $errArr[1]));
372
+            $this->data['errorClassNamespace'] = $this->data['errType'];
374 373
         }
375 374
 
376
-        if(preg_match('@Uncaught@is',$this->data['errStrReal'])
377
-            && preg_match('@(.*?):(.*?)\sin\s@is',$this->data['errStrReal'],$errStrRealArray)){
378
-            $this->data['errStrReal']=trim($errStrRealArray[2]);
375
+        if (preg_match('@Uncaught@is', $this->data['errStrReal'])
376
+            && preg_match('@(.*?):(.*?)\sin\s@is', $this->data['errStrReal'], $errStrRealArray)) {
377
+            $this->data['errStrReal'] = trim($errStrRealArray[2]);
379 378
         }
380 379
 
381
-        if($this->data['errType']==="Undefined"){
380
+        if ($this->data['errType']==="Undefined") {
382 381
             $this->data['errStrReal'] = $this->data['errStrReal'];
383 382
         }
384
-        else{
383
+        else {
385 384
             $this->data['errContext']['trace'] = $this->data['errStrReal'];
386 385
         }
387 386
     }
Please login to merge, or discard this patch.
Braces   +6 added lines, -12 removed lines patch added patch discarded remove patch
@@ -51,8 +51,7 @@  discard block
 block discarded – undo
51 51
         if($this->app->has('exceptiontrace'))
52 52
         {
53 53
             $this->data['status'] = (int)$this->app['exceptiontrace']['callNamespace']->getCode();
54
-        }
55
-        else {
54
+        } else {
56 55
 
57 56
             $this->data['status'] = (int)$exception::exceptionTypeCodes($this->data['errType']);
58 57
         }
@@ -87,8 +86,7 @@  discard block
 block discarded – undo
87 86
 
88 87
             //set as the success object is false
89 88
             $this->data['appExceptionSuccess'] = [];
90
-        }
91
-        else{
89
+        } else{
92 90
 
93 91
             //set as the success object is false
94 92
             $this->data['appExceptionSuccess'] = ['success'=>(bool)false,'status'=>$this->data['status']];
@@ -185,8 +183,7 @@  discard block
 block discarded – undo
185 183
             $this->app->register('responseStatus',500);
186 184
 
187 185
 
188
-        }
189
-        else{
186
+        } else{
190 187
 
191 188
             $this->result = $this->getAppException($environment,$this->data['errStrReal']);
192 189
 
@@ -222,8 +219,7 @@  discard block
 block discarded – undo
222 219
 
223 220
             echo json_encode($this->app->get('out')->outputFormatter($this->result));
224 221
             exit();
225
-        }
226
-        else{
222
+        } else{
227 223
             echo $restaOutHandle;
228 224
             exit();
229 225
         }
@@ -347,8 +343,7 @@  discard block
 block discarded – undo
347 343
 
348 344
         if($lang!==null){
349 345
             $langMessage = trans('exception.'.$lang);
350
-        }
351
-        else{
346
+        } else{
352 347
             $langMessage = null;
353 348
         }
354 349
 
@@ -380,8 +375,7 @@  discard block
 block discarded – undo
380 375
 
381 376
         if($this->data['errType']==="Undefined"){
382 377
             $this->data['errStrReal'] = $this->data['errStrReal'];
383
-        }
384
-        else{
378
+        } else{
385 379
             $this->data['errContext']['trace'] = $this->data['errStrReal'];
386 380
         }
387 381
     }
Please login to merge, or discard this patch.