Test Failed
Push — master ( 550bd1...54b313 )
by Php Easy Api
12:02
created
src/resta/Client/Client.php 1 patch
Spacing   +96 added lines, -96 removed lines patch added patch discarded remove patch
@@ -70,7 +70,7 @@  discard block
 block discarded – undo
70 70
      *
71 71
      * @throws ReflectionExceptionAlias
72 72
      */
73
-    public function __construct($clientData=null)
73
+    public function __construct($clientData = null)
74 74
     {
75 75
         //reflection process
76 76
         $this->reflection = app()['reflection']($this);
@@ -79,7 +79,7 @@  discard block
 block discarded – undo
79 79
         $this->setClientName();
80 80
 
81 81
         //get http method via request http manager class
82
-        $this->requestHttp = app()->resolve(ClientHttpManager::class,['client'=>$this]);
82
+        $this->requestHttp = app()->resolve(ClientHttpManager::class, ['client'=>$this]);
83 83
 
84 84
         //get request client data
85 85
         $this->clientData = ($clientData===null) ? $this->requestHttp->resolve() : $clientData;
@@ -96,9 +96,9 @@  discard block
 block discarded – undo
96 96
     private function autoValidate($validate)
97 97
     {
98 98
         //we get the values ​​to auto-validate.
99
-        foreach ($this->{$validate} as $object=>$datas){
99
+        foreach ($this->{$validate} as $object=>$datas) {
100 100
 
101
-            if(false===Utils::isNamespaceExists($object)){
101
+            if (false===Utils::isNamespaceExists($object)) {
102 102
                 return;
103 103
             }
104 104
 
@@ -108,30 +108,30 @@  discard block
 block discarded – undo
108 108
 
109 109
             // we get the index values,
110 110
             // which are called methods of the auto-validate value that represents the class.
111
-            foreach ($datas as $dataKey=>$data){
111
+            foreach ($datas as $dataKey=>$data) {
112 112
 
113 113
                 // if the methods of the auto-validate class resolved by the container resolve method apply,
114 114
                 // the process of auto-validate automatic implementation will be completed.
115
-                if(method_exists($getObjectInstance,$dataKey) && is_array($data)){
116
-                    foreach ($data as $dataItem){
117
-                        if(isset($this->origin[$dataItem])){
118
-                            $getObjectInstance->{$dataKey}($this->origin[$dataItem],$this,$dataItem);
115
+                if (method_exists($getObjectInstance, $dataKey) && is_array($data)) {
116
+                    foreach ($data as $dataItem) {
117
+                        if (isset($this->origin[$dataItem])) {
118
+                            $getObjectInstance->{$dataKey}($this->origin[$dataItem], $this, $dataItem);
119 119
                         }
120 120
 
121
-                        if(method_exists($this,$afterMethod = 'after'.ucfirst($dataKey))){
122
-                            $this->{$afterMethod}($this,$dataItem);
121
+                        if (method_exists($this, $afterMethod = 'after'.ucfirst($dataKey))) {
122
+                            $this->{$afterMethod}($this, $dataItem);
123 123
                         }
124 124
                     }
125 125
                 }
126 126
 
127 127
                 // if the methods of the auto-validate class resolved by the container resolve method apply,
128 128
                 // the process of auto-validate automatic implementation will be completed.
129
-                if(is_numeric($dataKey) && method_exists($getObjectInstance,$data) && isset($this->origin[$data])){
130
-                    if(!is_array($this->origin[$data])){
129
+                if (is_numeric($dataKey) && method_exists($getObjectInstance, $data) && isset($this->origin[$data])) {
130
+                    if (!is_array($this->origin[$data])) {
131 131
                         $this->origin[$data] = array($this->origin[$data]);
132 132
                     }
133
-                    foreach ($this->origin[$data] as $originData){
134
-                        $getObjectInstance->{$data}($originData,$this,$data);
133
+                    foreach ($this->origin[$data] as $originData) {
134
+                        $getObjectInstance->{$data}($originData, $this, $data);
135 135
                     }
136 136
                 }
137 137
             }
@@ -146,39 +146,39 @@  discard block
 block discarded – undo
146 146
     private function capsule()
147 147
     {
148 148
         //a process can be added to the capsule array using the method.
149
-        if(method_exists($this,'capsuleMethod')){
150
-            $this->capsule = array_merge($this->capsule,$this->capsuleMethod());
149
+        if (method_exists($this, 'capsuleMethod')) {
150
+            $this->capsule = array_merge($this->capsule, $this->capsuleMethod());
151 151
         }
152 152
 
153 153
         // expected method is executed.
154 154
         // this method is a must for http method values to be found in this property.
155
-        if($this->checkProperties('capsule')){
155
+        if ($this->checkProperties('capsule')) {
156 156
 
157
-            if(property_exists($this,'auto_capsule') && is_array($this->auto_capsule)){
158
-                $this->capsule = array_merge($this->capsule,$this->auto_capsule);
157
+            if (property_exists($this, 'auto_capsule') && is_array($this->auto_capsule)) {
158
+                $this->capsule = array_merge($this->capsule, $this->auto_capsule);
159 159
             }
160 160
 
161
-            if($this->checkProperties('groups')){
162
-                $this->capsule = array_merge($this->capsule,$this->groups);
161
+            if ($this->checkProperties('groups')) {
162
+                $this->capsule = array_merge($this->capsule, $this->groups);
163 163
 
164 164
                 foreach ($this->capsule as $item) {
165
-                    $groupProcess = $this->groupsProcess($item,true);
166
-                    if(is_array($groupProcess)){
165
+                    $groupProcess = $this->groupsProcess($item, true);
166
+                    if (is_array($groupProcess)) {
167 167
                         $defaultInputs = $this->inputs;
168
-                        $this->inputs = array_merge($this->inputs,$groupProcess);
168
+                        $this->inputs = array_merge($this->inputs, $groupProcess);
169 169
                     }
170 170
                 }
171 171
             }
172 172
 
173
-            foreach($this->inputs as $input=>$value){
173
+            foreach ($this->inputs as $input=>$value) {
174 174
 
175
-                if($this->checkProperties('capsule') && !in_array($input,$this->capsule)){
176
-                    exception('clientCapsule',['key'=>$input])
175
+                if ($this->checkProperties('capsule') && !in_array($input, $this->capsule)) {
176
+                    exception('clientCapsule', ['key'=>$input])
177 177
                         ->overflow('The '.$input.' value cannot be sent.');
178 178
                 }
179 179
             }
180 180
 
181
-            if(isset($defaultInputs)){
181
+            if (isset($defaultInputs)) {
182 182
                 $this->inputs = $defaultInputs;
183 183
             }
184 184
         }
@@ -196,15 +196,15 @@  discard block
 block discarded – undo
196 196
 
197 197
         // Determines which HTTP method
198 198
         // the request object will be exposed to.
199
-        if($this->checkProperties('http')){
199
+        if ($this->checkProperties('http')) {
200 200
 
201 201
             // if the current http method does not exist
202 202
             // in the http object, the exception will be thrown.
203
-            if(!in_array($method,$this->http)){
203
+            if (!in_array($method, $this->http)) {
204 204
 
205 205
                 //exception batMethodCall
206 206
                 exception()->badMethodCall(
207
-                    'Invalid http method process for '.basename($this).'.That is accepted http methods ['.implode(",",$this->http).'] ');
207
+                    'Invalid http method process for '.basename($this).'.That is accepted http methods ['.implode(",", $this->http).'] ');
208 208
             }
209 209
         }
210 210
     }
@@ -219,7 +219,7 @@  discard block
 block discarded – undo
219 219
     {
220 220
         // from the properties of the object properties to
221 221
         // the existing variables, control the array and at least one element.
222
-        return (property_exists($this,$properties)
222
+        return (property_exists($this, $properties)
223 223
             && is_array($this->{$properties}) && count($this->{$properties})) ? true : false;
224 224
     }
225 225
 
@@ -232,7 +232,7 @@  discard block
 block discarded – undo
232 232
     {
233 233
         // we are saving the expected values ​​for the request in container.
234 234
         // this record can be returned in exception information.
235
-        app()->register('requestExpected',$this->expected);
235
+        app()->register('requestExpected', $this->expected);
236 236
     }
237 237
 
238 238
     /**
@@ -244,15 +244,15 @@  discard block
 block discarded – undo
244 244
     public function except($except)
245 245
     {
246 246
         // the except parameter is a callable value.
247
-        if(is_callable($except)){
248
-            $call = call_user_func_array($except,[$this]);
247
+        if (is_callable($except)) {
248
+            $call = call_user_func_array($except, [$this]);
249 249
             $except = $call;
250 250
         }
251 251
 
252 252
         // except with the except exceptions property
253 253
         // and then assigning them to the inputs property.
254
-        $this->except = array_merge($this->except,$except);
255
-        $this->inputs = array_diff_key($this->inputs,array_flip($this->except));
254
+        $this->except = array_merge($this->except, $except);
255
+        $this->inputs = array_diff_key($this->inputs, array_flip($this->except));
256 256
 
257 257
         return $this;
258 258
     }
@@ -266,32 +266,32 @@  discard block
 block discarded – undo
266 266
     {
267 267
         // expected method is executed.
268 268
         // this method is a must for http method values to be found in this property.
269
-        if($this->checkProperties('expected')){
269
+        if ($this->checkProperties('expected')) {
270 270
 
271 271
             // if the expected values are not found in the inputs array,
272 272
             // the exception will be thrown.
273
-            foreach ($this->expected as $expected){
273
+            foreach ($this->expected as $expected) {
274 274
 
275 275
                 $expectedValues = [];
276 276
 
277 277
                 // mandatory expected data for each key can be separated by | operator.
278 278
                 // this is evaluated as "or".
279
-                foreach($expectedData = explode("|",$expected) as $inputs){
279
+                foreach ($expectedData = explode("|", $expected) as $inputs) {
280 280
 
281 281
                     // we should do key control for group format.
282 282
                     // this process will allow us to perform key control for 2D array correctly.
283 283
                     $this->groupsProcess($inputs);
284 284
 
285
-                    if(!isset($this->inputs[$inputs])){
285
+                    if (!isset($this->inputs[$inputs])) {
286 286
                         $expectedValues[$inputs] = $inputs;
287 287
                     }
288 288
                 }
289 289
 
290 290
                 // if the expectedData and expectedValues ​​
291 291
                 // array are numerically equal to the expected key, the exception is thrown.
292
-                if(count($expectedData)===count($expectedValues)){
293
-                    exception('clientExpected',['key'=>$expected])
294
-                        ->unexpectedValue('You absolutely have to send the value '.implode(" or ",$expectedValues).' for request object');
292
+                if (count($expectedData)===count($expectedValues)) {
293
+                    exception('clientExpected', ['key'=>$expected])
294
+                        ->unexpectedValue('You absolutely have to send the value '.implode(" or ", $expectedValues).' for request object');
295 295
                 }
296 296
             }
297 297
         }
@@ -306,17 +306,17 @@  discard block
 block discarded – undo
306 306
     {
307 307
         // check the presence of the generator object
308 308
         // and operate the generator over this object.
309
-        if($this->checkProperties('auto_generators')){
309
+        if ($this->checkProperties('auto_generators')) {
310 310
             $generators = $this->getAutoGenerators();
311 311
         }
312 312
 
313 313
         // check the presence of the generator object
314 314
         // and operate the generator over this object.
315
-        if($this->checkProperties('generators')){
316
-            $generators = array_merge(isset($generators) ? $generators: [],$this->getGenerators());
315
+        if ($this->checkProperties('generators')) {
316
+            $generators = array_merge(isset($generators) ? $generators : [], $this->getGenerators());
317 317
         }
318 318
 
319
-        if(isset($generators)){
319
+        if (isset($generators)) {
320 320
             $this->generatorMethod($generators);
321 321
         }
322 322
     }
@@ -331,21 +331,21 @@  discard block
 block discarded – undo
331 331
     private function generatorMethod($generators)
332 332
     {
333 333
         //generator array object
334
-        foreach ($generators as $generator){
334
+        foreach ($generators as $generator) {
335 335
 
336 336
             //generator method name
337 337
             $generatorMethodName = $generator.'Generator';
338 338
 
339 339
             // if the generator method is present,
340 340
             // the fake value is assigned.
341
-            if(method_exists($this,$generatorMethodName)){
341
+            if (method_exists($this, $generatorMethodName)) {
342 342
 
343 343
                 //fake registration
344
-                if(!isset($this->inputs[$generator])){
344
+                if (!isset($this->inputs[$generator])) {
345 345
 
346 346
                     $generatorMethodNameResult = $this->{$generatorMethodName}();
347 347
 
348
-                    if(!is_null($generatorMethodNameResult)){
348
+                    if (!is_null($generatorMethodNameResult)) {
349 349
                         $this->{$generator} = $this->{$generatorMethodName}();
350 350
                         $this->inputs[$generator] = $this->{$generatorMethodName}();
351 351
                         $this->generatorList[] = $generator;
@@ -353,15 +353,15 @@  discard block
 block discarded – undo
353 353
                 }
354 354
                 else {
355 355
 
356
-                    if($this->checkProperties('auto_generators_dont_overwrite')
357
-                        && in_array($generator,$this->getAutoGeneratorsDontOverwrite())){
356
+                    if ($this->checkProperties('auto_generators_dont_overwrite')
357
+                        && in_array($generator, $this->getAutoGeneratorsDontOverwrite())) {
358 358
                         $this->{$generator} = $this->{$generatorMethodName}();
359 359
                         $this->inputs[$generator] = $this->{$generatorMethodName}();
360 360
                         $this->generatorList[] = $generator;
361 361
                     }
362 362
 
363
-                    if($this->checkProperties('generators_dont_overwrite')
364
-                        && in_array($generator,$this->getGeneratorsDontOverwrite())){
363
+                    if ($this->checkProperties('generators_dont_overwrite')
364
+                        && in_array($generator, $this->getGeneratorsDontOverwrite())) {
365 365
                         $this->{$generator} = $this->{$generatorMethodName}();
366 366
                         $this->inputs[$generator] = $this->{$generatorMethodName}();
367 367
                         $this->generatorList[] = $generator;
@@ -392,28 +392,28 @@  discard block
 block discarded – undo
392 392
      * @param null $callback
393 393
      * @return mixed|void
394 394
      */
395
-    public function groupsProcess($key=null,$callback=null)
395
+    public function groupsProcess($key = null, $callback = null)
396 396
     {
397
-        if(property_exists($this,'groups') && is_array($this->groups)){
397
+        if (property_exists($this, 'groups') && is_array($this->groups)) {
398 398
 
399 399
             $clientObjects = $this->getClientObjects();
400 400
 
401
-            foreach ($this->groups as $group){
401
+            foreach ($this->groups as $group) {
402 402
 
403
-                if(true === $callback){
404
-                    if(isset($clientObjects['origin'][$key])){
403
+                if (true===$callback) {
404
+                    if (isset($clientObjects['origin'][$key])) {
405 405
                         return $clientObjects['origin'][$key];
406 406
                     }
407 407
                     return [];
408 408
                 }
409 409
 
410
-                if(isset($clientObjects['origin'][$group][$key])){
410
+                if (isset($clientObjects['origin'][$group][$key])) {
411 411
 
412 412
                     $this->{$key} = $clientObjects['origin'][$group][$key];
413 413
                     $this->inputs[$key] = $this->{$key};
414 414
 
415
-                    if(is_callable($callback)){
416
-                        call_user_func_array($callback,[$key]);
415
+                    if (is_callable($callback)) {
416
+                        call_user_func_array($callback, [$key]);
417 417
                     }
418 418
                 }
419 419
             }
@@ -438,7 +438,7 @@  discard block
 block discarded – undo
438 438
         //that coming with the post.
439 439
         $this->initClient();
440 440
         
441
-        if(method_exists($this,'eventBefore')){
441
+        if (method_exists($this, 'eventBefore')) {
442 442
             $this->eventBefore();
443 443
         }
444 444
 
@@ -474,11 +474,11 @@  discard block
 block discarded – undo
474 474
         // are subtracted from all input values.
475 475
         $this->requestExcept();
476 476
 
477
-        if(app()->has('clientRequestInputs')){
477
+        if (app()->has('clientRequestInputs')) {
478 478
             app()->terminate('clientRequestInputs');
479 479
         }
480 480
 
481
-        app()->register('clientRequestInputs',$this->inputs);
481
+        app()->register('clientRequestInputs', $this->inputs);
482 482
     }
483 483
 
484 484
     /**
@@ -489,18 +489,18 @@  discard block
 block discarded – undo
489 489
     private function unity()
490 490
     {
491 491
         // unity method is executed.
492
-        if($this->checkProperties('unity')){
492
+        if ($this->checkProperties('unity')) {
493 493
 
494 494
             $list = [];
495 495
 
496
-            foreach ($this->unity as $unity){
497
-                if(isset($this->inputs[$unity])){
496
+            foreach ($this->unity as $unity) {
497
+                if (isset($this->inputs[$unity])) {
498 498
                     $list[] = $unity;
499 499
                 }
500 500
             }
501 501
 
502
-            if(count($list)>1){
503
-                exception('clientUnityExpected',['key'=>implode(',',$this->unity)])
502
+            if (count($list)>1) {
503
+                exception('clientUnityExpected', ['key'=>implode(',', $this->unity)])
504 504
                     ->invalidArgument('clientUnityExpected');
505 505
             }
506 506
         }
@@ -515,7 +515,7 @@  discard block
 block discarded – undo
515 515
     {
516 516
         // we use the http method to write
517 517
         // the values to the inputs and origin properties.
518
-        foreach($this->clientData as $key=>$value){
518
+        foreach ($this->clientData as $key=>$value) {
519 519
 
520 520
             //inputs and origin properties
521 521
             $this->inputs[$key] = $value;
@@ -531,9 +531,9 @@  discard block
 block discarded – undo
531 531
      */
532 532
     private function requestExcept()
533 533
     {
534
-        if(property_exists($this,'requestExcept') && is_array($this->requestExcept)){
535
-            foreach ($this->requestExcept as $item){
536
-                if(isset($this->inputs[$item])){
534
+        if (property_exists($this, 'requestExcept') && is_array($this->requestExcept)) {
535
+            foreach ($this->requestExcept as $item) {
536
+                if (isset($this->inputs[$item])) {
537 537
                     unset($this->inputs[$item]);
538 538
                 }
539 539
             }
@@ -546,16 +546,16 @@  discard block
 block discarded – undo
546 546
      * @param null|string $clientName
547 547
      * @return void|mixed
548 548
      */
549
-    public function setClientName($clientName=null)
549
+    public function setClientName($clientName = null)
550 550
     {
551
-        if(!is_null($clientName) && is_string($clientName)){
551
+        if (!is_null($clientName) && is_string($clientName)) {
552 552
             return $this->clientName = $clientName;
553 553
         }
554 554
 
555
-        if(!is_null(Utils::trace(0)) && isset(Utils::trace(0)['object'])){
555
+        if (!is_null(Utils::trace(0)) && isset(Utils::trace(0)['object'])) {
556 556
             $backTrace = Utils::trace(0)['object'];
557 557
 
558
-            if(property_exists($backTrace,'clientName')){
558
+            if (property_exists($backTrace, 'clientName')) {
559 559
                 $this->clientName = $backTrace->clientName;
560 560
             }
561 561
         }
@@ -572,16 +572,16 @@  discard block
 block discarded – undo
572 572
 
573 573
         // we update the input values ​​after
574 574
         // we receive and check the saved objects.
575
-        foreach ($clientObjects as $key=>$value){
575
+        foreach ($clientObjects as $key=>$value) {
576 576
 
577 577
             // we should do key control for group format.
578 578
             // this process will allow us to perform key control for 2D array correctly.
579
-            $this->groupsProcess($key,function($key){
579
+            $this->groupsProcess($key, function($key) {
580 580
                 $this->registerRequestInputs($key);
581 581
                 unset($this->inputs[$key]);
582 582
             });
583 583
 
584
-            if(!in_array($key,$this->generatorList) && isset($clientObjects['origin'][$key])){
584
+            if (!in_array($key, $this->generatorList) && isset($clientObjects['origin'][$key])) {
585 585
 
586 586
                 $this->{$key} = $clientObjects['origin'][$key];
587 587
                 $this->inputs[$key] = $this->{$key};
@@ -609,11 +609,11 @@  discard block
 block discarded – undo
609 609
 
610 610
         // the request update to be performed using
611 611
         // the method name to be used with the http method.
612
-        $this->setRequestInputs($requestMethod,$key);
612
+        $this->setRequestInputs($requestMethod, $key);
613 613
 
614 614
         // the request update to be performed using
615 615
         // the method name to be used without the http method.
616
-        $this->setRequestInputs($key,$key);
616
+        $this->setRequestInputs($key, $key);
617 617
     }
618 618
 
619 619
     /**
@@ -624,28 +624,28 @@  discard block
 block discarded – undo
624 624
      *
625 625
      * @throws ReflectionExceptionAlias
626 626
      */
627
-    private function setRequestInputs($method,$key)
627
+    private function setRequestInputs($method, $key)
628 628
     {
629
-        if(!in_array($key,$this->generatorList) && method_exists($this,$method) && $this->reflection->reflectionMethodParams($method)->isProtected){
629
+        if (!in_array($key, $this->generatorList) && method_exists($this, $method) && $this->reflection->reflectionMethodParams($method)->isProtected) {
630 630
 
631 631
             //check annotations for method
632
-            $annotation = app()->resolve(ClientAnnotationManager::class,['request'=>$this]);
633
-            $annotation->annotation($method,$key);
632
+            $annotation = app()->resolve(ClientAnnotationManager::class, ['request'=>$this]);
633
+            $annotation->annotation($method, $key);
634 634
 
635
-            if(isset($this->inputs[$key]) && is_array($this->inputs[$key])){
635
+            if (isset($this->inputs[$key]) && is_array($this->inputs[$key])) {
636 636
 
637 637
                 $inputKeys = $this->inputs[$key];
638 638
 
639 639
                 $this->inputs[$key] = [];
640
-                foreach ($inputKeys as $ikey=>$input){
640
+                foreach ($inputKeys as $ikey=>$input) {
641 641
 
642 642
                     $this->{$key}[$ikey]        = $input;
643 643
                     $keyMethod                  = $this->{$method}();
644 644
                     $this->inputs[$key]         = $keyMethod;
645 645
                 }
646 646
             }
647
-            else{
648
-                if(isset($this->inputs[$key])){
647
+            else {
648
+                if (isset($this->inputs[$key])) {
649 649
                     $keyMethod = $this->{$method}();
650 650
                     $this->inputs[$key] = $keyMethod;
651 651
                 }
@@ -664,8 +664,8 @@  discard block
 block discarded – undo
664 664
         // the auto object validate property is the property
665 665
         // where all of your request values ​​are automatically validated.
666 666
         /** @noinspection PhpParamsInspection */
667
-        if(property_exists($this,'autoObjectValidate')
668
-            && is_array($this->autoObjectValidate) && count($this->autoObjectValidate)){
667
+        if (property_exists($this, 'autoObjectValidate')
668
+            && is_array($this->autoObjectValidate) && count($this->autoObjectValidate)) {
669 669
             $this->autoValidate('autoObjectValidate');
670 670
         }
671 671
     }
Please login to merge, or discard this patch.