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