Passed
Push — master ( 6255ce...a1a81a )
by Php Easy Api
02:56
created
src/resta/Request/Request.php 1 patch
Spacing   +52 added lines, -52 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,26 +169,26 @@  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){
176
+            foreach ($this->expected as $expected) {
177 177
 
178 178
                 $expectedValues = [];
179 179
 
180 180
                 // mandatory expected data for each key | can be separated by.
181 181
                 // this is evaluated as "or".
182
-                foreach($expectedData = explode("|",$expected) as $inputs){
183
-                    if(!isset($this->inputs[$inputs])){
182
+                foreach ($expectedData = explode("|", $expected) as $inputs) {
183
+                    if (!isset($this->inputs[$inputs])) {
184 184
                         $expectedValues[] = $inputs;
185 185
                     }
186 186
                 }
187 187
 
188 188
                 // if the expectedData and expectedValues ​​
189 189
                 // array are numerically equal to the expected key, the exception is thrown.
190
-                if(count($expectedData)===count($expectedValues)){
191
-                    exception()->unexpectedValue('You absolutely have to send the value '.implode(" or ",$expectedValues).' for request object');
190
+                if (count($expectedData)===count($expectedValues)) {
191
+                    exception()->unexpectedValue('You absolutely have to send the value '.implode(" or ", $expectedValues).' for request object');
192 192
                 }
193 193
             }
194 194
         }
@@ -203,17 +203,17 @@  discard block
 block discarded – undo
203 203
     {
204 204
         // check the presence of the generator object
205 205
         // and operate the generator over this object.
206
-        if($this->checkProperties('auto_generators')){
206
+        if ($this->checkProperties('auto_generators')) {
207 207
             $generators = $this->auto_generators;
208 208
         }
209 209
 
210 210
         // check the presence of the generator object
211 211
         // and operate the generator over this object.
212
-        if($this->checkProperties('generators')){
213
-            $generators = array_merge(isset($generators) ? $generators: [],$this->generators);
212
+        if ($this->checkProperties('generators')) {
213
+            $generators = array_merge(isset($generators) ? $generators : [], $this->generators);
214 214
         }
215 215
 
216
-        if(isset($generators)){
216
+        if (isset($generators)) {
217 217
             $this->generatorMethod($generators);
218 218
         }
219 219
     }
@@ -226,30 +226,30 @@  discard block
 block discarded – undo
226 226
     private function generatorMethod($generators)
227 227
     {
228 228
         //generator array object
229
-        foreach ($generators as $generator){
229
+        foreach ($generators as $generator) {
230 230
 
231 231
             //generator method name
232 232
             $generatorMethodName = $generator.'Generator';
233 233
 
234 234
             // if the generator method is present,
235 235
             // the fake value is assigned.
236
-            if(method_exists($this,$generatorMethodName)){
236
+            if (method_exists($this, $generatorMethodName)) {
237 237
 
238 238
                 //fake registration
239
-                if(!isset($this->inputs[$generator])){
239
+                if (!isset($this->inputs[$generator])) {
240 240
                     $this->{$generator} = $this->{$generatorMethodName}();
241 241
                     $this->inputs[$generator] = $this->{$generatorMethodName}();
242 242
                 }
243 243
                 else {
244 244
 
245
-                    if($this->checkProperties('auto_generators_dont_overwrite')
246
-                        && in_array($generator,$this->auto_generators_dont_overwrite)){
245
+                    if ($this->checkProperties('auto_generators_dont_overwrite')
246
+                        && in_array($generator, $this->auto_generators_dont_overwrite)) {
247 247
                         $this->{$generator} = $this->{$generatorMethodName}();
248 248
                         $this->inputs[$generator] = $this->{$generatorMethodName}();
249 249
                     }
250 250
 
251
-                    if($this->checkProperties('generators_dont_overwrite')
252
-                        && in_array($generator,$this->generators_dont_overwrite)){
251
+                    if ($this->checkProperties('generators_dont_overwrite')
252
+                        && in_array($generator, $this->generators_dont_overwrite)) {
253 253
                         $this->{$generator} = $this->{$generatorMethodName}();
254 254
                         $this->inputs[$generator] = $this->{$generatorMethodName}();
255 255
                     }
@@ -278,7 +278,7 @@  discard block
 block discarded – undo
278 278
      */
279 279
     private function getClientObjects()
280 280
     {
281
-        return array_diff_key($this->getObjects(),['inputs'=>[]]);
281
+        return array_diff_key($this->getObjects(), ['inputs'=>[]]);
282 282
     }
283 283
 
284 284
     /**
@@ -324,7 +324,7 @@  discard block
 block discarded – undo
324 324
     {
325 325
         // we use the http method to write
326 326
         // the values to the inputs and origin properties.
327
-        foreach($this->requestHttp->resolve() as $key=>$value){
327
+        foreach ($this->requestHttp->resolve() as $key=>$value) {
328 328
 
329 329
             //inputs and origin properties
330 330
             $this->inputs[$key] = $value;
@@ -368,9 +368,9 @@  discard block
 block discarded – undo
368 368
 
369 369
         // we update the input values ​​after
370 370
         // we receive and check the saved objects.
371
-        foreach ($clientObjects as $key=>$value){
371
+        foreach ($clientObjects as $key=>$value) {
372 372
 
373
-            if(isset($clientObjects['origin'][$key])){
373
+            if (isset($clientObjects['origin'][$key])) {
374 374
 
375 375
                 $this->{$key} = $clientObjects['origin'][$key];
376 376
                 $this->inputs[$key] = $this->{$key};
@@ -395,11 +395,11 @@  discard block
 block discarded – undo
395 395
 
396 396
         // the request update to be performed using
397 397
         // the method name to be used with the http method.
398
-        $this->setRequestInputs($requestMethod,$key);
398
+        $this->setRequestInputs($requestMethod, $key);
399 399
 
400 400
         // the request update to be performed using
401 401
         // the method name to be used without the http method.
402
-        $this->setRequestInputs($key,$key);
402
+        $this->setRequestInputs($key, $key);
403 403
     }
404 404
 
405 405
     /**
@@ -408,28 +408,28 @@  discard block
 block discarded – undo
408 408
      * @param $method
409 409
      * @param $key
410 410
      */
411
-    private function setRequestInputs($method,$key)
411
+    private function setRequestInputs($method, $key)
412 412
     {
413
-        if(method_exists($this,$method) && $this->reflection->reflectionMethodParams($method)->isProtected){
413
+        if (method_exists($this, $method) && $this->reflection->reflectionMethodParams($method)->isProtected) {
414 414
 
415 415
             //check annotations for method
416
-            $annotation = app()->resolve(RequestAnnotationManager::class,['request'=>$this]);
417
-            $annotation->annotation($method,$key);
416
+            $annotation = app()->resolve(RequestAnnotationManager::class, ['request'=>$this]);
417
+            $annotation->annotation($method, $key);
418 418
 
419
-            if(isset($this->inputs[$key]) && is_array($this->inputs[$key])){
419
+            if (isset($this->inputs[$key]) && is_array($this->inputs[$key])) {
420 420
 
421 421
                 $inputKeys = $this->inputs[$key];
422 422
 
423 423
                 $this->inputs[$key] = [];
424
-                foreach ($inputKeys as $input){
424
+                foreach ($inputKeys as $input) {
425 425
 
426 426
                     $this->{$key}           = $input;
427 427
                     $keyMethod              = $this->{$method}();
428 428
                     $this->inputs[$key][]   = $keyMethod;
429 429
                 }
430 430
             }
431
-            else{
432
-                if(isset($this->inputs[$key])){
431
+            else {
432
+                if (isset($this->inputs[$key])) {
433 433
                     $keyMethod = $this->{$method}();
434 434
                     $this->inputs[$key] = $keyMethod;
435 435
                 }
@@ -445,22 +445,22 @@  discard block
 block discarded – undo
445 445
      */
446 446
     private function validation()
447 447
     {
448
-        if(property_exists($this,'autoObjectValidate') && is_array($this->autoObjectValidate) && count($this->autoObjectValidate)){
448
+        if (property_exists($this, 'autoObjectValidate') && is_array($this->autoObjectValidate) && count($this->autoObjectValidate)) {
449 449
             $this->autoValidate('autoObjectValidate');
450 450
         }
451 451
         // we need to find the rule method
452 452
         // because we can not validate it.
453
-        if(method_exists($this,'rule')){
453
+        if (method_exists($this, 'rule')) {
454 454
             $this->rule();
455 455
         }
456 456
 
457 457
         // if we only want to make a rule of
458 458
         // the specified request object, we will use
459 459
         // the rule method with the prefix of the request object.
460
-        $validName=strtolower(str_replace('Request','',class_basename($this))).'Rule';
460
+        $validName = strtolower(str_replace('Request', '', class_basename($this))).'Rule';
461 461
 
462 462
         //if the specified method exists;
463
-        if(method_exists($this,$validName)){
463
+        if (method_exists($this, $validName)) {
464 464
             $this->{$validName}();
465 465
         }
466 466
     }
Please login to merge, or discard this patch.