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