Test Setup Failed
Push — master ( c742e7...f262d3 )
by Php Easy Api
03:42
created
src/resta/Exception/ErrorProvider.php 1 patch
Spacing   +60 added lines, -61 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
 
@@ -127,7 +127,7 @@  discard block
 block discarded – undo
127 127
      * @param null|string $errLine
128 128
      * @param null|string $errContext
129 129
      */
130
-    public function setErrorHandler($errNo=null, $errStr=null, $errFile=null, $errLine=null, $errContext=null)
130
+    public function setErrorHandler($errNo = null, $errStr = null, $errFile = null, $errLine = null, $errContext = null)
131 131
     {
132 132
         // in case of a deficiency,
133 133
         // we need to boot our general needs to be needed for the exception.
@@ -154,7 +154,7 @@  discard block
 block discarded – undo
154 154
         //get lang message for exception
155 155
         $this->getLangMessageForException();
156 156
 
157
-        if($this->app->has('exceptiontrace')){
157
+        if ($this->app->has('exceptiontrace')) {
158 158
 
159 159
             $customExceptionTrace   = $this->app['exceptiontrace'];
160 160
             $this->data['errFile']  = $customExceptionTrace['file'];
@@ -163,42 +163,41 @@  discard block
 block discarded – undo
163 163
 
164 164
         $environment = $this->app->environment();
165 165
 
166
-        $vendorDirectory = str_replace(root.''.DIRECTORY_SEPARATOR.'','',$this->data['errFile']);
166
+        $vendorDirectory = str_replace(root.''.DIRECTORY_SEPARATOR.'', '', $this->data['errFile']);
167 167
 
168
-        if(preg_match('@vendor.*\.php@is',$vendorDirectory,$vd)){
168
+        if (preg_match('@vendor.*\.php@is', $vendorDirectory, $vd)) {
169 169
             $vendorDirectory = $vd[0];
170 170
         }
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
 
176 176
             $externalMessage = ($environment==="production") ?
177
-                'An unexpected external error has occurred' :
178
-                $this->data['errStrReal'];
177
+                'An unexpected external error has occurred' : $this->data['errStrReal'];
179 178
 
180
-            $this->result = $this->getAppException($environment,$externalMessage);
179
+            $this->result = $this->getAppException($environment, $externalMessage);
181 180
 
182 181
 
183 182
             //Get or Set the HTTP response code
184 183
             http_response_code(500);
185 184
             $this->app->terminate('responseStatus');
186
-            $this->app->register('responseStatus',500);
185
+            $this->app->register('responseStatus', 500);
187 186
 
188 187
 
189 188
         }
190
-        else{
189
+        else {
191 190
 
192
-            $this->result = $this->getAppException($environment,$this->data['errStrReal']);
191
+            $this->result = $this->getAppException($environment, $this->data['errStrReal']);
193 192
 
194 193
             //Get or Set the HTTP response code
195 194
             http_response_code($this->data['status']);
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,17 +206,17 @@  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 217
         header("HTTP/1.1 ".$this->data['status']);
219 218
 
220
-        if($restaOutHandle===null){
219
+        if ($restaOutHandle===null) {
221 220
 
222 221
             //header set and symfony response call
223 222
             header('Content-type:application/json;charset=utf-8');
@@ -225,7 +224,7 @@  discard block
 block discarded – undo
225 224
             echo json_encode($this->app->get('out')->outputFormatter($this->result));
226 225
             exit();
227 226
         }
228
-        else{
227
+        else {
229 228
             echo $restaOutHandle;
230 229
             exit();
231 230
         }
@@ -235,7 +234,7 @@  discard block
 block discarded – undo
235 234
      * @param $environment
236 235
      * @return mixed
237 236
      */
238
-    private function getAppException($environment,$message)
237
+    private function getAppException($environment, $message)
239 238
     {
240 239
         return $this->data['appExceptionSuccess']+$this->data['exception']::$environment(
241 240
                 $this->data['errNo'],
@@ -255,7 +254,7 @@  discard block
 block discarded – undo
255 254
     private function getExceptionExtender()
256 255
     {
257 256
         return $this->app->resolve(
258
-            $this->app->get('macro')->call('exceptionExtender',function(){
257
+            $this->app->get('macro')->call('exceptionExtender', function() {
259 258
                 return ExceptionExtender::class;
260 259
             }),
261 260
             ['result'=>$this->result])->getResult();
@@ -273,13 +272,13 @@  discard block
 block discarded – undo
273 272
 
274 273
         $this->inStackTrace($last_error);
275 274
 
276
-        if(!is_null($last_error)){
275
+        if (!is_null($last_error)) {
277 276
 
278
-            if(!defined('methodName')){
279
-                define('methodName',null);
277
+            if (!defined('methodName')) {
278
+                define('methodName', null);
280 279
             }
281 280
 
282
-            if($this->app->has('exceptionFile')){
281
+            if ($this->app->has('exceptionFile')) {
283 282
                 $last_error['file'] = $this->app['exceptionFile'];
284 283
                 $last_error['line'] = $this->app['exceptionLine'];
285 284
             }
@@ -299,13 +298,13 @@  discard block
 block discarded – undo
299 298
      */
300 299
     public function inStackTrace($error)
301 300
     {
302
-        if($this->app->has('urlComponent')){
303
-            if(!preg_match('@'.$this->app['urlComponent']['project'].'@',$error['file'])
304
-                && !$this->app->has('exceptionFile')){
305
-                if(preg_match('@ in\s(.*?)\n@is',$error['message'],$result)){
306
-                    $errorMessage = explode(":",$result[1]);
307
-                    $this->app->register('exceptionFile',$errorMessage[0]);
308
-                    $this->app->register('exceptionLine',$errorMessage[1]);
301
+        if ($this->app->has('urlComponent')) {
302
+            if (!preg_match('@'.$this->app['urlComponent']['project'].'@', $error['file'])
303
+                && !$this->app->has('exceptionFile')) {
304
+                if (preg_match('@ in\s(.*?)\n@is', $error['message'], $result)) {
305
+                    $errorMessage = explode(":", $result[1]);
306
+                    $this->app->register('exceptionFile', $errorMessage[0]);
307
+                    $this->app->register('exceptionLine', $errorMessage[1]);
309 308
                 }
310 309
             }
311 310
         }
@@ -318,33 +317,33 @@  discard block
 block discarded – undo
318 317
     {
319 318
         $clone = clone $this;
320 319
 
321
-        if($this->app->has('exceptionTranslate')){
320
+        if ($this->app->has('exceptionTranslate')) {
322 321
 
323 322
             $langMessage = trans('exception.'.$this->app->get('exceptionTranslate'));
324 323
 
325
-            if(!is_null($langMessage) && $this->app->has('exceptionTranslateParams')){
324
+            if (!is_null($langMessage) && $this->app->has('exceptionTranslateParams')) {
326 325
 
327
-                if(count($this->app['exceptionTranslateParams'][$this->app['exceptionTranslate']])){
328
-                    foreach ($this->app['exceptionTranslateParams'][$this->app['exceptionTranslate']] as $key=>$value){
326
+                if (count($this->app['exceptionTranslateParams'][$this->app['exceptionTranslate']])) {
327
+                    foreach ($this->app['exceptionTranslateParams'][$this->app['exceptionTranslate']] as $key=>$value) {
329 328
 
330 329
                         $valueLangName = !is_null(trans('default.'.$value)) ? trans('default.'.$value) : $value;
331
-                        $langMessage = preg_replace('@\('.$key.'\)@is',$valueLangName,$langMessage);
330
+                        $langMessage = preg_replace('@\('.$key.'\)@is', $valueLangName, $langMessage);
332 331
                     }
333 332
                 }
334 333
             }
335 334
 
336
-            if($langMessage!==null){
335
+            if ($langMessage!==null) {
337 336
                 $this->data['errStrReal'] = $langMessage;
338 337
             }
339 338
         }
340 339
 
341
-        if(class_exists($this->data['errorClassNamespace'])
340
+        if (class_exists($this->data['errorClassNamespace'])
342 341
             &&
343
-            (Str::startsWith($this->data['errorClassNamespace'],'App')
344
-                || Str::startsWith($this->data['errorClassNamespace'],__NAMESPACE__))){
342
+            (Str::startsWith($this->data['errorClassNamespace'], 'App')
343
+                || Str::startsWith($this->data['errorClassNamespace'], __NAMESPACE__))) {
345 344
 
346 345
             ClosureDispatcher::bind($this->data['errorClassNamespace'])->call(function() use ($clone) {
347
-                if(property_exists($this,'lang')){
346
+                if (property_exists($this, 'lang')) {
348 347
                     $clone->setLang($this->lang);
349 348
                 }
350 349
             });
@@ -354,7 +353,7 @@  discard block
 block discarded – undo
354 353
 
355 354
         $langMessage = (!is_null($this->data['lang'])) ? trans('exception.'.$this->data['lang']) : null;
356 355
 
357
-        if($langMessage!==null){
356
+        if ($langMessage!==null) {
358 357
             $this->data['errStrReal'] = $langMessage;
359 358
         }
360 359
     }
@@ -368,14 +367,14 @@  discard block
 block discarded – undo
368 367
     {
369 368
         // catch exception via preg match
370 369
         // and then clear the Uncaught statement from inside.
371
-        if(preg_match('@(.*?):@is',$this->data['errStrReal'],$errArr)){
370
+        if (preg_match('@(.*?):@is', $this->data['errStrReal'], $errArr)) {
372 371
 
373
-            $this->data['errType'] = trim(str_replace('Uncaught','',$errArr[1]));
372
+            $this->data['errType'] = trim(str_replace('Uncaught', '', $errArr[1]));
374 373
             $this->data['errorClassNamespace'] = $this->data['errType'];
375 374
         }
376 375
 
377
-        if(preg_match('@Uncaught@is',$this->data['errStrReal'])
378
-            && preg_match('@(.*?):(.*?)\sin\s@is',$this->data['errStrReal'],$errStrRealArray)){
376
+        if (preg_match('@Uncaught@is', $this->data['errStrReal'])
377
+            && preg_match('@(.*?):(.*?)\sin\s@is', $this->data['errStrReal'], $errStrRealArray)) {
379 378
             $this->data['errStrReal'] = trim($errStrRealArray[2]);
380 379
         }
381 380
 
@@ -395,7 +394,7 @@  discard block
 block discarded – undo
395 394
     /**
396 395
      * @param null|string $lang
397 396
      */
398
-    public function setLang($lang=null)
397
+    public function setLang($lang = null)
399 398
     {
400 399
         $this->lang = $lang;
401 400
     }
Please login to merge, or discard this patch.