Passed
Push — master ( 00d2da...21d927 )
by Php Easy Api
03:21
created
src/resta/Request/Request.php 1 patch
Spacing   +74 added lines, -74 removed lines patch added patch discarded remove patch
@@ -58,7 +58,7 @@  discard block
 block discarded – undo
58 58
         // if we leave the request process to the application side,
59 59
         // then in this case we refer to the requestClient object in
60 60
         // the services section of the store directory.
61
-        (property_exists($this,'app') && $this->app) ? parent::handle() : $this->handle();
61
+        (property_exists($this, 'app') && $this->app) ? parent::handle() : $this->handle();
62 62
     }
63 63
 
64 64
     /**
@@ -68,16 +68,16 @@  discard block
 block discarded – undo
68 68
      */
69 69
     private function autoValidate($validate)
70 70
     {
71
-        foreach ($this->{$validate} as $object=>$datas){
72
-            if(Utils::isNamespaceExists($object)){
71
+        foreach ($this->{$validate} as $object=>$datas) {
72
+            if (Utils::isNamespaceExists($object)) {
73 73
                 $getObjectInstance = app()->resolve($object);
74
-                foreach ($datas as $dataKey=>$data){
75
-                    if(is_numeric($dataKey) && method_exists($getObjectInstance,$data)){
76
-                        if(isset($this->origin[$data])){
77
-                            if(!is_array($this->origin[$data])){
74
+                foreach ($datas as $dataKey=>$data) {
75
+                    if (is_numeric($dataKey) && method_exists($getObjectInstance, $data)) {
76
+                        if (isset($this->origin[$data])) {
77
+                            if (!is_array($this->origin[$data])) {
78 78
                                 $this->origin[$data] = array($this->origin[$data]);
79 79
                             }
80
-                            foreach ($this->origin[$data] as $originData){
80
+                            foreach ($this->origin[$data] as $originData) {
81 81
                                 $getObjectInstance->{$data}($originData);
82 82
                             }
83 83
                         }
@@ -99,15 +99,15 @@  discard block
 block discarded – undo
99 99
 
100 100
         // Determines which HTTP method
101 101
         // the request object will be exposed to.
102
-        if($this->checkProperties('http')){
102
+        if ($this->checkProperties('http')) {
103 103
 
104 104
             // if the current http method does not exist
105 105
             // in the http object, the exception will be thrown.
106
-            if(!in_array($method,$this->http)){
106
+            if (!in_array($method, $this->http)) {
107 107
 
108 108
                 //exception batMethodCall
109 109
                 exception()->badMethodCall(
110
-                    'Invalid http method process for '.class_basename($this).'.That is accepted http methods ['.implode(",",$this->http).'] ');
110
+                    'Invalid http method process for '.class_basename($this).'.That is accepted http methods ['.implode(",", $this->http).'] ');
111 111
             }
112 112
         }
113 113
     }
@@ -122,7 +122,7 @@  discard block
 block discarded – undo
122 122
     {
123 123
         // from the properties of the object properties to
124 124
         // the existing variables, control the array and at least one element.
125
-        return (property_exists($this,$properties)
125
+        return (property_exists($this, $properties)
126 126
             && is_array($this->{$properties}) && count($this->{$properties})) ? true : false;
127 127
     }
128 128
 
@@ -135,7 +135,7 @@  discard block
 block discarded – undo
135 135
     {
136 136
         // we are saving the expected values ​​for the request in container.
137 137
         // this record can be returned in exception information.
138
-        app()->register('requestExpected',$this->expected);
138
+        app()->register('requestExpected', $this->expected);
139 139
     }
140 140
 
141 141
     /**
@@ -147,15 +147,15 @@  discard block
 block discarded – undo
147 147
     public function except($except)
148 148
     {
149 149
         // the except parameter is a callable value.
150
-        if(is_callable($except)){
151
-            $call = call_user_func_array($except,[$this]);
150
+        if (is_callable($except)) {
151
+            $call = call_user_func_array($except, [$this]);
152 152
             $except = $call;
153 153
         }
154 154
 
155 155
         // except with the except exceptions property
156 156
         // and then assigning them to the inputs property.
157
-        $this->except = array_merge($this->except,$except);
158
-        $this->inputs = array_diff_key($this->inputs,array_flip($this->except));
157
+        $this->except = array_merge($this->except, $except);
158
+        $this->inputs = array_diff_key($this->inputs, array_flip($this->except));
159 159
 
160 160
         return $this;
161 161
     }
@@ -169,12 +169,12 @@  discard block
 block discarded – undo
169 169
     {
170 170
         // expected method is executed.
171 171
         // this method is a must for http method values to be found in this property.
172
-        if($this->checkProperties('expected')){
172
+        if ($this->checkProperties('expected')) {
173 173
 
174 174
             // if the expected values are not found in the inputs array,
175 175
             // the exception will be thrown.
176
-            foreach ($this->expected as $expected){
177
-                if(!isset($this->inputs[$expected])){
176
+            foreach ($this->expected as $expected) {
177
+                if (!isset($this->inputs[$expected])) {
178 178
                     exception()->unexpectedValue('You absolutely have to send the value '.$expected.' for request object');
179 179
                 }
180 180
             }
@@ -190,17 +190,17 @@  discard block
 block discarded – undo
190 190
     {
191 191
         // check the presence of the generator object
192 192
         // and operate the generator over this object.
193
-        if($this->checkProperties('auto_generators')){
193
+        if ($this->checkProperties('auto_generators')) {
194 194
             $generators = $this->auto_generators;
195 195
         }
196 196
 
197 197
         // check the presence of the generator object
198 198
         // and operate the generator over this object.
199
-        if($this->checkProperties('generators')){
200
-            $generators = array_merge(isset($generators) ? $generators: [],$this->generators);
199
+        if ($this->checkProperties('generators')) {
200
+            $generators = array_merge(isset($generators) ? $generators : [], $this->generators);
201 201
         }
202 202
 
203
-        if(isset($generators)){
203
+        if (isset($generators)) {
204 204
             $this->generatorMethod($generators);
205 205
         }
206 206
     }
@@ -213,30 +213,30 @@  discard block
 block discarded – undo
213 213
     private function generatorMethod($generators)
214 214
     {
215 215
         //generator array object
216
-        foreach ($generators as $generator){
216
+        foreach ($generators as $generator) {
217 217
 
218 218
             //generator method name
219 219
             $generatorMethodName = $generator.'Generator';
220 220
 
221 221
             // if the generator method is present,
222 222
             // the fake value is assigned.
223
-            if(method_exists($this,$generatorMethodName)){
223
+            if (method_exists($this, $generatorMethodName)) {
224 224
 
225 225
                 //fake registration
226
-                if(!isset($this->inputs[$generator])){
226
+                if (!isset($this->inputs[$generator])) {
227 227
                     $this->{$generator} = $this->{$generatorMethodName}();
228 228
                     $this->inputs[$generator] = $this->{$generatorMethodName}();
229 229
                 }
230 230
                 else {
231 231
 
232
-                    if($this->checkProperties('auto_generators_dont_overwrite')
233
-                        && in_array($generator,$this->auto_generators_dont_overwrite)){
232
+                    if ($this->checkProperties('auto_generators_dont_overwrite')
233
+                        && in_array($generator, $this->auto_generators_dont_overwrite)) {
234 234
                         $this->{$generator} = $this->{$generatorMethodName}();
235 235
                         $this->inputs[$generator] = $this->{$generatorMethodName}();
236 236
                     }
237 237
 
238
-                    if($this->checkProperties('generators_dont_overwrite')
239
-                        && in_array($generator,$this->generators_dont_overwrite)){
238
+                    if ($this->checkProperties('generators_dont_overwrite')
239
+                        && in_array($generator, $this->generators_dont_overwrite)) {
240 240
                         $this->{$generator} = $this->{$generatorMethodName}();
241 241
                         $this->inputs[$generator] = $this->{$generatorMethodName}();
242 242
                     }
@@ -265,7 +265,7 @@  discard block
 block discarded – undo
265 265
      */
266 266
     private function getClientObjects()
267 267
     {
268
-        return array_diff_key($this->getObjects(),['inputs'=>[]]);
268
+        return array_diff_key($this->getObjects(), ['inputs'=>[]]);
269 269
     }
270 270
 
271 271
     /**
@@ -311,7 +311,7 @@  discard block
 block discarded – undo
311 311
     {
312 312
         // we use the http method to write
313 313
         // the values to the inputs and origin properties.
314
-        foreach($this->requestHttp->resolve() as $key=>$value){
314
+        foreach ($this->requestHttp->resolve() as $key=>$value) {
315 315
 
316 316
             //inputs and origin properties
317 317
             $this->inputs[$key] = $value;
@@ -327,68 +327,68 @@  discard block
 block discarded – undo
327 327
      *
328 328
      * @throws \ReflectionException
329 329
      */
330
-    private function checkAnnotations($method,$key)
330
+    private function checkAnnotations($method, $key)
331 331
     {
332 332
         $reflection = $this->reflection->reflectionMethodParams($method);
333 333
         $annotation = $reflection->document;
334 334
 
335 335
         $exceptionParamList = [];
336 336
 
337
-        if(preg_match('@exception\((.*?)\)\r\n@is',$annotation,$exception)){
337
+        if (preg_match('@exception\((.*?)\)\r\n@is', $annotation, $exception)) {
338 338
 
339
-            $exceptionSpaceExplode = explode(" ",$exception[1]);
340
-            foreach ($exceptionSpaceExplode as $exceptions){
341
-                $exceptionsDotExplode = explode(":",$exceptions);
339
+            $exceptionSpaceExplode = explode(" ", $exception[1]);
340
+            foreach ($exceptionSpaceExplode as $exceptions) {
341
+                $exceptionsDotExplode = explode(":", $exceptions);
342 342
                 $exceptionParamList[$key][$exceptionsDotExplode[0]] = $exceptionsDotExplode[1];
343 343
             }
344 344
 
345
-            if(isset($exceptionParamList[$key]['params'])){
346
-                $paramsCommaExplode = explode(",",$exceptionParamList[$key]['params']);
345
+            if (isset($exceptionParamList[$key]['params'])) {
346
+                $paramsCommaExplode = explode(",", $exceptionParamList[$key]['params']);
347 347
                 unset($exceptionParamList[$key]['params']);
348
-                foreach ($paramsCommaExplode as $params){
349
-                    $paramsEqualExplode = explode("=",$params);
350
-                    if(isset($paramsEqualExplode[0]) && isset($paramsEqualExplode[1])){
348
+                foreach ($paramsCommaExplode as $params) {
349
+                    $paramsEqualExplode = explode("=", $params);
350
+                    if (isset($paramsEqualExplode[0]) && isset($paramsEqualExplode[1])) {
351 351
                         $exceptionParamList[$key]['params'][$paramsEqualExplode[0]] = $paramsEqualExplode[1];
352 352
                     }
353 353
                 }
354 354
             }
355 355
         }
356 356
 
357
-        if(preg_match('@remove\((.*?)\)\r\n@is',$annotation,$remove)){
358
-            if(isset($this->inputs[$key])){
359
-                if(preg_match('@'.$remove[1].'@is',$this->inputs[$key])){
357
+        if (preg_match('@remove\((.*?)\)\r\n@is', $annotation, $remove)) {
358
+            if (isset($this->inputs[$key])) {
359
+                if (preg_match('@'.$remove[1].'@is', $this->inputs[$key])) {
360 360
                     unset($this->inputs[$key]);
361 361
                 }
362 362
             }
363 363
         }
364 364
 
365
-        if(preg_match('@regex\((.*?)\)\r\n@is',$annotation,$regex)){
366
-            if(isset($this->inputs[$key])){
365
+        if (preg_match('@regex\((.*?)\)\r\n@is', $annotation, $regex)) {
366
+            if (isset($this->inputs[$key])) {
367 367
 
368
-                if(is_array($this->inputs[$key])){
368
+                if (is_array($this->inputs[$key])) {
369 369
 
370
-                    foreach ($this->inputs[$key] as $inputKey=>$inputValue){
370
+                    foreach ($this->inputs[$key] as $inputKey=>$inputValue) {
371 371
 
372
-                        if(!preg_match('@'.$regex[1].'@is',$inputValue)){
373
-                            if(isset($exceptionParamList[$key])){
372
+                        if (!preg_match('@'.$regex[1].'@is', $inputValue)) {
373
+                            if (isset($exceptionParamList[$key])) {
374 374
                                 $keyParams = ($exceptionParamList[$key]['params']) ?? [];
375
-                                exception($exceptionParamList[$key]['name'],$keyParams)->unexpectedValue($key.' input value is not valid as format ('.$regex[1].')');
375
+                                exception($exceptionParamList[$key]['name'], $keyParams)->unexpectedValue($key.' input value is not valid as format ('.$regex[1].')');
376 376
                             }
377
-                            else{
377
+                            else {
378 378
                                 exception()->unexpectedValue($key.' input value is not valid as format ('.$regex[1].')');
379 379
                             }
380 380
                         }
381 381
                     }
382 382
 
383 383
                 }
384
-                else{
384
+                else {
385 385
 
386
-                    if(!preg_match('@'.$regex[1].'@is',$this->inputs[$key])){
387
-                        if(isset($exceptionParamList[$key])){
386
+                    if (!preg_match('@'.$regex[1].'@is', $this->inputs[$key])) {
387
+                        if (isset($exceptionParamList[$key])) {
388 388
                             $keyParams = ($exceptionParamList[$key]['params']) ?? [];
389
-                            exception($exceptionParamList[$key]['name'],$keyParams)->unexpectedValue($key.' input value is not valid as format ('.$regex[1].')');
389
+                            exception($exceptionParamList[$key]['name'], $keyParams)->unexpectedValue($key.' input value is not valid as format ('.$regex[1].')');
390 390
                         }
391
-                        else{
391
+                        else {
392 392
                             exception()->unexpectedValue($key.' input value is not valid as format ('.$regex[1].')');
393 393
                         }
394 394
                     }
@@ -434,9 +434,9 @@  discard block
 block discarded – undo
434 434
 
435 435
         // we update the input values ​​after
436 436
         // we receive and check the saved objects.
437
-        foreach ($clientObjects as $key=>$value){
437
+        foreach ($clientObjects as $key=>$value) {
438 438
 
439
-            if(isset($clientObjects['origin'][$key])){
439
+            if (isset($clientObjects['origin'][$key])) {
440 440
 
441 441
                 $this->{$key} = $clientObjects['origin'][$key];
442 442
                 $this->inputs[$key] = $this->{$key};
@@ -461,11 +461,11 @@  discard block
 block discarded – undo
461 461
 
462 462
         // the request update to be performed using
463 463
         // the method name to be used with the http method.
464
-        $this->setRequestInputs($requestMethod,$key);
464
+        $this->setRequestInputs($requestMethod, $key);
465 465
 
466 466
         // the request update to be performed using
467 467
         // the method name to be used without the http method.
468
-        $this->setRequestInputs($key,$key);
468
+        $this->setRequestInputs($key, $key);
469 469
     }
470 470
 
471 471
     /**
@@ -474,27 +474,27 @@  discard block
 block discarded – undo
474 474
      * @param $method
475 475
      * @param $key
476 476
      */
477
-    private function setRequestInputs($method,$key)
477
+    private function setRequestInputs($method, $key)
478 478
     {
479
-        if(method_exists($this,$method) && $this->reflection->reflectionMethodParams($method)->isProtected){
479
+        if (method_exists($this, $method) && $this->reflection->reflectionMethodParams($method)->isProtected) {
480 480
 
481 481
             //check annotations for method
482
-            $this->checkAnnotations($method,$key);
482
+            $this->checkAnnotations($method, $key);
483 483
 
484
-            if(isset($this->inputs[$key]) && is_array($this->inputs[$key])){
484
+            if (isset($this->inputs[$key]) && is_array($this->inputs[$key])) {
485 485
 
486 486
                 $inputKeys = $this->inputs[$key];
487 487
 
488 488
                 $this->inputs[$key] = [];
489
-                foreach ($inputKeys as $input){
489
+                foreach ($inputKeys as $input) {
490 490
 
491 491
                     $this->{$key}           = $input;
492 492
                     $keyMethod              = $this->{$method}();
493 493
                     $this->inputs[$key][]   = $keyMethod;
494 494
                 }
495 495
             }
496
-            else{
497
-                if(isset($this->inputs[$key])){
496
+            else {
497
+                if (isset($this->inputs[$key])) {
498 498
                     $keyMethod = $this->{$method}();
499 499
                     $this->inputs[$key] = $keyMethod;
500 500
                 }
@@ -510,22 +510,22 @@  discard block
 block discarded – undo
510 510
      */
511 511
     private function validation()
512 512
     {
513
-        if(property_exists($this,'autoObjectValidate') && is_array($this->autoObjectValidate) && count($this->autoObjectValidate)){
513
+        if (property_exists($this, 'autoObjectValidate') && is_array($this->autoObjectValidate) && count($this->autoObjectValidate)) {
514 514
             $this->autoValidate('autoObjectValidate');
515 515
         }
516 516
         // we need to find the rule method
517 517
         // because we can not validate it.
518
-        if(method_exists($this,'rule')){
518
+        if (method_exists($this, 'rule')) {
519 519
             $this->rule();
520 520
         }
521 521
 
522 522
         // if we only want to make a rule of
523 523
         // the specified request object, we will use
524 524
         // the rule method with the prefix of the request object.
525
-        $validName=strtolower(str_replace('Request','',class_basename($this))).'Rule';
525
+        $validName = strtolower(str_replace('Request', '', class_basename($this))).'Rule';
526 526
 
527 527
         //if the specified method exists;
528
-        if(method_exists($this,$validName)){
528
+        if (method_exists($this, $validName)) {
529 529
             $this->{$validName}();
530 530
         }
531 531
     }
Please login to merge, or discard this patch.