Test Setup Failed
Push — master ( 31aacb...2e45d1 )
by Php Easy Api
06:19 queued 02:45
created
src/resta/Client/Client.php 1 patch
Spacing   +81 added lines, -81 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,15 +107,15 @@  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(is_numeric($dataKey) && method_exists($getObjectInstance,$data) && isset($this->origin[$data])){
115
-                    if(!is_array($this->origin[$data])){
114
+                if (is_numeric($dataKey) && method_exists($getObjectInstance, $data) && isset($this->origin[$data])) {
115
+                    if (!is_array($this->origin[$data])) {
116 116
                         $this->origin[$data] = array($this->origin[$data]);
117 117
                     }
118
-                    foreach ($this->origin[$data] as $originData){
118
+                    foreach ($this->origin[$data] as $originData) {
119 119
                         $getObjectInstance->{$data}($originData);
120 120
                     }
121 121
                 }
@@ -131,34 +131,34 @@  discard block
 block discarded – undo
131 131
     private function capsule()
132 132
     {
133 133
         //a process can be added to the capsule array using the method.
134
-        if(method_exists($this,'capsuleMethod')){
135
-            $this->capsule = array_merge($this->capsule,$this->capsuleMethod());
134
+        if (method_exists($this, 'capsuleMethod')) {
135
+            $this->capsule = array_merge($this->capsule, $this->capsuleMethod());
136 136
         }
137 137
 
138 138
         // expected method is executed.
139 139
         // this method is a must for http method values to be found in this property.
140
-        if($this->checkProperties('capsule')){
140
+        if ($this->checkProperties('capsule')) {
141 141
 
142
-            if(property_exists($this,'auto_capsule') && is_array($this->auto_capsule)){
143
-                $this->capsule = array_merge($this->capsule,$this->auto_capsule);
142
+            if (property_exists($this, 'auto_capsule') && is_array($this->auto_capsule)) {
143
+                $this->capsule = array_merge($this->capsule, $this->auto_capsule);
144 144
             }
145 145
 
146
-            if(property_exists($this,'groups')
147
-                && property_exists($this,'capsule') && is_array($this->groups)){
148
-                $this->capsule = array_merge($this->capsule,$this->groups);
146
+            if (property_exists($this, 'groups')
147
+                && property_exists($this, 'capsule') && is_array($this->groups)) {
148
+                $this->capsule = array_merge($this->capsule, $this->groups);
149 149
 
150 150
                 foreach ($this->capsule as $item) {
151
-                    $groupProcess = $this->groupsProcess($item,true);
152
-                    if(is_array($groupProcess)){
153
-                        $this->inputs = array_merge($this->inputs,$groupProcess);
151
+                    $groupProcess = $this->groupsProcess($item, true);
152
+                    if (is_array($groupProcess)) {
153
+                        $this->inputs = array_merge($this->inputs, $groupProcess);
154 154
                     }
155 155
                 }
156 156
             }
157 157
 
158
-            foreach($this->inputs as $input=>$value){
158
+            foreach ($this->inputs as $input=>$value) {
159 159
 
160
-                if($this->checkProperties('capsule') && !in_array($input,$this->capsule)){
161
-                    exception('clientCapsule',['key'=>$input])
160
+                if ($this->checkProperties('capsule') && !in_array($input, $this->capsule)) {
161
+                    exception('clientCapsule', ['key'=>$input])
162 162
                         ->overflow('The '.$input.' value cannot be sent.');
163 163
                 }
164 164
             }
@@ -177,15 +177,15 @@  discard block
 block discarded – undo
177 177
 
178 178
         // Determines which HTTP method
179 179
         // the request object will be exposed to.
180
-        if($this->checkProperties('http')){
180
+        if ($this->checkProperties('http')) {
181 181
 
182 182
             // if the current http method does not exist
183 183
             // in the http object, the exception will be thrown.
184
-            if(!in_array($method,$this->http)){
184
+            if (!in_array($method, $this->http)) {
185 185
 
186 186
                 //exception batMethodCall
187 187
                 exception()->badMethodCall(
188
-                    'Invalid http method process for '.basename($this).'.That is accepted http methods ['.implode(",",$this->http).'] ');
188
+                    'Invalid http method process for '.basename($this).'.That is accepted http methods ['.implode(",", $this->http).'] ');
189 189
             }
190 190
         }
191 191
     }
@@ -200,7 +200,7 @@  discard block
 block discarded – undo
200 200
     {
201 201
         // from the properties of the object properties to
202 202
         // the existing variables, control the array and at least one element.
203
-        return (property_exists($this,$properties)
203
+        return (property_exists($this, $properties)
204 204
             && is_array($this->{$properties}) && count($this->{$properties})) ? true : false;
205 205
     }
206 206
 
@@ -213,7 +213,7 @@  discard block
 block discarded – undo
213 213
     {
214 214
         // we are saving the expected values ​​for the request in container.
215 215
         // this record can be returned in exception information.
216
-        app()->register('requestExpected',$this->expected);
216
+        app()->register('requestExpected', $this->expected);
217 217
     }
218 218
 
219 219
     /**
@@ -225,15 +225,15 @@  discard block
 block discarded – undo
225 225
     public function except($except)
226 226
     {
227 227
         // the except parameter is a callable value.
228
-        if(is_callable($except)){
229
-            $call = call_user_func_array($except,[$this]);
228
+        if (is_callable($except)) {
229
+            $call = call_user_func_array($except, [$this]);
230 230
             $except = $call;
231 231
         }
232 232
 
233 233
         // except with the except exceptions property
234 234
         // and then assigning them to the inputs property.
235
-        $this->except = array_merge($this->except,$except);
236
-        $this->inputs = array_diff_key($this->inputs,array_flip($this->except));
235
+        $this->except = array_merge($this->except, $except);
236
+        $this->inputs = array_diff_key($this->inputs, array_flip($this->except));
237 237
 
238 238
         return $this;
239 239
     }
@@ -247,32 +247,32 @@  discard block
 block discarded – undo
247 247
     {
248 248
         // expected method is executed.
249 249
         // this method is a must for http method values to be found in this property.
250
-        if($this->checkProperties('expected')){
250
+        if ($this->checkProperties('expected')) {
251 251
 
252 252
             // if the expected values are not found in the inputs array,
253 253
             // the exception will be thrown.
254
-            foreach ($this->expected as $expected){
254
+            foreach ($this->expected as $expected) {
255 255
 
256 256
                 $expectedValues = [];
257 257
 
258 258
                 // mandatory expected data for each key can be separated by | operator.
259 259
                 // this is evaluated as "or".
260
-                foreach($expectedData = explode("|",$expected) as $inputs){
260
+                foreach ($expectedData = explode("|", $expected) as $inputs) {
261 261
 
262 262
                     // we should do key control for group format.
263 263
                     // this process will allow us to perform key control for 2D array correctly.
264 264
                     $this->groupsProcess($inputs);
265 265
 
266
-                    if(!isset($this->inputs[$inputs])){
266
+                    if (!isset($this->inputs[$inputs])) {
267 267
                         $expectedValues[$inputs] = $inputs;
268 268
                     }
269 269
                 }
270 270
 
271 271
                 // if the expectedData and expectedValues ​​
272 272
                 // array are numerically equal to the expected key, the exception is thrown.
273
-                if(count($expectedData)===count($expectedValues)){
274
-                    exception('clientExpected',['key'=>$expected])
275
-                        ->unexpectedValue('You absolutely have to send the value '.implode(" or ",$expectedValues).' for request object');
273
+                if (count($expectedData)===count($expectedValues)) {
274
+                    exception('clientExpected', ['key'=>$expected])
275
+                        ->unexpectedValue('You absolutely have to send the value '.implode(" or ", $expectedValues).' for request object');
276 276
                 }
277 277
             }
278 278
         }
@@ -287,17 +287,17 @@  discard block
 block discarded – undo
287 287
     {
288 288
         // check the presence of the generator object
289 289
         // and operate the generator over this object.
290
-        if($this->checkProperties('auto_generators')){
290
+        if ($this->checkProperties('auto_generators')) {
291 291
             $generators = $this->getAutoGenerators();
292 292
         }
293 293
 
294 294
         // check the presence of the generator object
295 295
         // and operate the generator over this object.
296
-        if($this->checkProperties('generators')){
297
-            $generators = array_merge(isset($generators) ? $generators: [],$this->getGenerators());
296
+        if ($this->checkProperties('generators')) {
297
+            $generators = array_merge(isset($generators) ? $generators : [], $this->getGenerators());
298 298
         }
299 299
 
300
-        if(isset($generators)){
300
+        if (isset($generators)) {
301 301
             $this->generatorMethod($generators);
302 302
         }
303 303
     }
@@ -312,21 +312,21 @@  discard block
 block discarded – undo
312 312
     private function generatorMethod($generators)
313 313
     {
314 314
         //generator array object
315
-        foreach ($generators as $generator){
315
+        foreach ($generators as $generator) {
316 316
 
317 317
             //generator method name
318 318
             $generatorMethodName = $generator.'Generator';
319 319
 
320 320
             // if the generator method is present,
321 321
             // the fake value is assigned.
322
-            if(method_exists($this,$generatorMethodName)){
322
+            if (method_exists($this, $generatorMethodName)) {
323 323
 
324 324
                 //fake registration
325
-                if(!isset($this->inputs[$generator])){
325
+                if (!isset($this->inputs[$generator])) {
326 326
 
327 327
                     $generatorMethodNameResult = $this->{$generatorMethodName}();
328 328
 
329
-                    if(!is_null($generatorMethodNameResult)){
329
+                    if (!is_null($generatorMethodNameResult)) {
330 330
                         $this->{$generator} = $this->{$generatorMethodName}();
331 331
                         $this->inputs[$generator] = $this->{$generatorMethodName}();
332 332
                         $this->generatorList[] = $generator;
@@ -334,15 +334,15 @@  discard block
 block discarded – undo
334 334
                 }
335 335
                 else {
336 336
 
337
-                    if($this->checkProperties('auto_generators_dont_overwrite')
338
-                        && in_array($generator,$this->getAutoGeneratorsDontOverwrite())){
337
+                    if ($this->checkProperties('auto_generators_dont_overwrite')
338
+                        && in_array($generator, $this->getAutoGeneratorsDontOverwrite())) {
339 339
                         $this->{$generator} = $this->{$generatorMethodName}();
340 340
                         $this->inputs[$generator] = $this->{$generatorMethodName}();
341 341
                         $this->generatorList[] = $generator;
342 342
                     }
343 343
 
344
-                    if($this->checkProperties('generators_dont_overwrite')
345
-                        && in_array($generator,$this->getGeneratorsDontOverwrite())){
344
+                    if ($this->checkProperties('generators_dont_overwrite')
345
+                        && in_array($generator, $this->getGeneratorsDontOverwrite())) {
346 346
                         $this->{$generator} = $this->{$generatorMethodName}();
347 347
                         $this->inputs[$generator] = $this->{$generatorMethodName}();
348 348
                         $this->generatorList[] = $generator;
@@ -373,27 +373,27 @@  discard block
 block discarded – undo
373 373
      * @param null $callback
374 374
      * @return mixed|void
375 375
      */
376
-    public function groupsProcess($key=null,$callback=null)
376
+    public function groupsProcess($key = null, $callback = null)
377 377
     {
378
-        if(property_exists($this,'groups') && is_array($this->groups)){
378
+        if (property_exists($this, 'groups') && is_array($this->groups)) {
379 379
 
380 380
             $clientObjects = $this->getClientObjects();
381 381
 
382
-            foreach ($this->groups as $group){
382
+            foreach ($this->groups as $group) {
383 383
 
384
-                if(true === $callback){
385
-                    if(isset($clientObjects['origin'][$key])){
384
+                if (true===$callback) {
385
+                    if (isset($clientObjects['origin'][$key])) {
386 386
                         return $clientObjects['origin'][$key];
387 387
                     }
388 388
                 }
389 389
 
390
-                if(isset($clientObjects['origin'][$group][$key])){
390
+                if (isset($clientObjects['origin'][$group][$key])) {
391 391
 
392 392
                     $this->{$key} = $clientObjects['origin'][$group][$key];
393 393
                     $this->inputs[$key] = $this->{$key};
394 394
 
395
-                    if(is_callable($callback)){
396
-                        call_user_func_array($callback,[$key]);
395
+                    if (is_callable($callback)) {
396
+                        call_user_func_array($callback, [$key]);
397 397
                     }
398 398
                 }
399 399
             }
@@ -456,7 +456,7 @@  discard block
 block discarded – undo
456 456
     {
457 457
         // we use the http method to write
458 458
         // the values to the inputs and origin properties.
459
-        foreach($this->clientData as $key=>$value){
459
+        foreach ($this->clientData as $key=>$value) {
460 460
 
461 461
             //inputs and origin properties
462 462
             $this->inputs[$key] = $value;
@@ -472,9 +472,9 @@  discard block
 block discarded – undo
472 472
      */
473 473
     private function requestExcept()
474 474
     {
475
-        if(property_exists($this,'requestExcept') && is_array($this->requestExcept)){
476
-            foreach ($this->requestExcept as $item){
477
-                if(isset($this->inputs[$item])){
475
+        if (property_exists($this, 'requestExcept') && is_array($this->requestExcept)) {
476
+            foreach ($this->requestExcept as $item) {
477
+                if (isset($this->inputs[$item])) {
478 478
                     unset($this->inputs[$item]);
479 479
                 }
480 480
             }
@@ -487,16 +487,16 @@  discard block
 block discarded – undo
487 487
      * @param null|string $clientName
488 488
      * @return void|mixed
489 489
      */
490
-    public function setClientName($clientName=null)
490
+    public function setClientName($clientName = null)
491 491
     {
492
-        if(!is_null($clientName) && is_string($clientName)){
492
+        if (!is_null($clientName) && is_string($clientName)) {
493 493
             return $this->clientName = $clientName;
494 494
         }
495 495
 
496
-        if(!is_null(Utils::trace(0)) && isset(Utils::trace(0)['object'])){
496
+        if (!is_null(Utils::trace(0)) && isset(Utils::trace(0)['object'])) {
497 497
             $backTrace = Utils::trace(0)['object'];
498 498
 
499
-            if(property_exists($backTrace,'clientName')){
499
+            if (property_exists($backTrace, 'clientName')) {
500 500
                 $this->clientName = $backTrace->clientName;
501 501
             }
502 502
         }
@@ -513,16 +513,16 @@  discard block
 block discarded – undo
513 513
 
514 514
         // we update the input values ​​after
515 515
         // we receive and check the saved objects.
516
-        foreach ($clientObjects as $key=>$value){
516
+        foreach ($clientObjects as $key=>$value) {
517 517
 
518 518
             // we should do key control for group format.
519 519
             // this process will allow us to perform key control for 2D array correctly.
520
-            $this->groupsProcess($key,function($key){
520
+            $this->groupsProcess($key, function($key) {
521 521
                 $this->registerRequestInputs($key);
522 522
                 unset($this->inputs[$key]);
523 523
             });
524 524
 
525
-            if(!in_array($key,$this->generatorList) && isset($clientObjects['origin'][$key])){
525
+            if (!in_array($key, $this->generatorList) && isset($clientObjects['origin'][$key])) {
526 526
 
527 527
                 $this->{$key} = $clientObjects['origin'][$key];
528 528
                 $this->inputs[$key] = $this->{$key};
@@ -550,11 +550,11 @@  discard block
 block discarded – undo
550 550
 
551 551
         // the request update to be performed using
552 552
         // the method name to be used with the http method.
553
-        $this->setRequestInputs($requestMethod,$key);
553
+        $this->setRequestInputs($requestMethod, $key);
554 554
 
555 555
         // the request update to be performed using
556 556
         // the method name to be used without the http method.
557
-        $this->setRequestInputs($key,$key);
557
+        $this->setRequestInputs($key, $key);
558 558
     }
559 559
 
560 560
     /**
@@ -565,28 +565,28 @@  discard block
 block discarded – undo
565 565
      *
566 566
      * @throws ReflectionExceptionAlias
567 567
      */
568
-    private function setRequestInputs($method,$key)
568
+    private function setRequestInputs($method, $key)
569 569
     {
570
-        if(!in_array($key,$this->generatorList) && method_exists($this,$method) && $this->reflection->reflectionMethodParams($method)->isProtected){
570
+        if (!in_array($key, $this->generatorList) && method_exists($this, $method) && $this->reflection->reflectionMethodParams($method)->isProtected) {
571 571
 
572 572
             //check annotations for method
573
-            $annotation = app()->resolve(ClientAnnotationManager::class,['request'=>$this]);
574
-            $annotation->annotation($method,$key);
573
+            $annotation = app()->resolve(ClientAnnotationManager::class, ['request'=>$this]);
574
+            $annotation->annotation($method, $key);
575 575
 
576
-            if(isset($this->inputs[$key]) && is_array($this->inputs[$key])){
576
+            if (isset($this->inputs[$key]) && is_array($this->inputs[$key])) {
577 577
 
578 578
                 $inputKeys = $this->inputs[$key];
579 579
 
580 580
                 $this->inputs[$key] = [];
581
-                foreach ($inputKeys as $input){
581
+                foreach ($inputKeys as $input) {
582 582
 
583 583
                     $this->{$key}               = $input;
584 584
                     $keyMethod                  = $this->{$method}();
585 585
                     $this->inputs[$key][]       = $keyMethod;
586 586
                 }
587 587
             }
588
-            else{
589
-                if(isset($this->inputs[$key])){
588
+            else {
589
+                if (isset($this->inputs[$key])) {
590 590
                     $keyMethod = $this->{$method}();
591 591
                     $this->inputs[$key] = $keyMethod;
592 592
                 }
@@ -605,8 +605,8 @@  discard block
 block discarded – undo
605 605
         // the auto object validate property is the property
606 606
         // where all of your request values ​​are automatically validated.
607 607
         /** @noinspection PhpParamsInspection */
608
-        if(property_exists($this,'autoObjectValidate')
609
-            && is_array($this->autoObjectValidate) && count($this->autoObjectValidate)){
608
+        if (property_exists($this, 'autoObjectValidate')
609
+            && is_array($this->autoObjectValidate) && count($this->autoObjectValidate)) {
610 610
             $this->autoValidate('autoObjectValidate');
611 611
         }
612 612
     }
Please login to merge, or discard this patch.