Test Setup Failed
Push — master ( 92050c...514983 )
by Php Easy Api
04:20
created
src/resta/Client/Client.php 1 patch
Spacing   +73 added lines, -73 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,22 +131,22 @@  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
-            foreach($this->inputs as $input=>$value){
146
+            foreach ($this->inputs as $input=>$value) {
147 147
 
148
-                if($this->checkProperties('capsule') && !in_array($input,$this->capsule)){
149
-                    exception('clientCapsule',['key'=>$input])
148
+                if ($this->checkProperties('capsule') && !in_array($input, $this->capsule)) {
149
+                    exception('clientCapsule', ['key'=>$input])
150 150
                         ->overflow('The '.$input.' value cannot be sent.');
151 151
                 }
152 152
             }
@@ -165,15 +165,15 @@  discard block
 block discarded – undo
165 165
 
166 166
         // Determines which HTTP method
167 167
         // the request object will be exposed to.
168
-        if($this->checkProperties('http')){
168
+        if ($this->checkProperties('http')) {
169 169
 
170 170
             // if the current http method does not exist
171 171
             // in the http object, the exception will be thrown.
172
-            if(!in_array($method,$this->http)){
172
+            if (!in_array($method, $this->http)) {
173 173
 
174 174
                 //exception batMethodCall
175 175
                 exception()->badMethodCall(
176
-                    'Invalid http method process for '.basename($this).'.That is accepted http methods ['.implode(",",$this->http).'] ');
176
+                    'Invalid http method process for '.basename($this).'.That is accepted http methods ['.implode(",", $this->http).'] ');
177 177
             }
178 178
         }
179 179
     }
@@ -188,7 +188,7 @@  discard block
 block discarded – undo
188 188
     {
189 189
         // from the properties of the object properties to
190 190
         // the existing variables, control the array and at least one element.
191
-        return (property_exists($this,$properties)
191
+        return (property_exists($this, $properties)
192 192
             && is_array($this->{$properties}) && count($this->{$properties})) ? true : false;
193 193
     }
194 194
 
@@ -201,7 +201,7 @@  discard block
 block discarded – undo
201 201
     {
202 202
         // we are saving the expected values ​​for the request in container.
203 203
         // this record can be returned in exception information.
204
-        app()->register('requestExpected',$this->expected);
204
+        app()->register('requestExpected', $this->expected);
205 205
     }
206 206
 
207 207
     /**
@@ -213,15 +213,15 @@  discard block
 block discarded – undo
213 213
     public function except($except)
214 214
     {
215 215
         // the except parameter is a callable value.
216
-        if(is_callable($except)){
217
-            $call = call_user_func_array($except,[$this]);
216
+        if (is_callable($except)) {
217
+            $call = call_user_func_array($except, [$this]);
218 218
             $except = $call;
219 219
         }
220 220
 
221 221
         // except with the except exceptions property
222 222
         // and then assigning them to the inputs property.
223
-        $this->except = array_merge($this->except,$except);
224
-        $this->inputs = array_diff_key($this->inputs,array_flip($this->except));
223
+        $this->except = array_merge($this->except, $except);
224
+        $this->inputs = array_diff_key($this->inputs, array_flip($this->except));
225 225
 
226 226
         return $this;
227 227
     }
@@ -235,32 +235,32 @@  discard block
 block discarded – undo
235 235
     {
236 236
         // expected method is executed.
237 237
         // this method is a must for http method values to be found in this property.
238
-        if($this->checkProperties('expected')){
238
+        if ($this->checkProperties('expected')) {
239 239
 
240 240
             // if the expected values are not found in the inputs array,
241 241
             // the exception will be thrown.
242
-            foreach ($this->expected as $expected){
242
+            foreach ($this->expected as $expected) {
243 243
 
244 244
                 $expectedValues = [];
245 245
 
246 246
                 // mandatory expected data for each key can be separated by | operator.
247 247
                 // this is evaluated as "or".
248
-                foreach($expectedData = explode("|",$expected) as $inputs){
248
+                foreach ($expectedData = explode("|", $expected) as $inputs) {
249 249
 
250 250
                     // we should do key control for group format.
251 251
                     // this process will allow us to perform key control for 2D array correctly.
252 252
                     $this->groupsProcess($inputs);
253 253
 
254
-                    if(!isset($this->inputs[$inputs])){
254
+                    if (!isset($this->inputs[$inputs])) {
255 255
                         $expectedValues[$inputs] = $inputs;
256 256
                     }
257 257
                 }
258 258
 
259 259
                 // if the expectedData and expectedValues ​​
260 260
                 // array are numerically equal to the expected key, the exception is thrown.
261
-                if(count($expectedData)===count($expectedValues)){
262
-                    exception('clientExpected',['key'=>$expected])
263
-                        ->unexpectedValue('You absolutely have to send the value '.implode(" or ",$expectedValues).' for request object');
261
+                if (count($expectedData)===count($expectedValues)) {
262
+                    exception('clientExpected', ['key'=>$expected])
263
+                        ->unexpectedValue('You absolutely have to send the value '.implode(" or ", $expectedValues).' for request object');
264 264
                 }
265 265
             }
266 266
         }
@@ -275,17 +275,17 @@  discard block
 block discarded – undo
275 275
     {
276 276
         // check the presence of the generator object
277 277
         // and operate the generator over this object.
278
-        if($this->checkProperties('auto_generators')){
278
+        if ($this->checkProperties('auto_generators')) {
279 279
             $generators = $this->getAutoGenerators();
280 280
         }
281 281
 
282 282
         // check the presence of the generator object
283 283
         // and operate the generator over this object.
284
-        if($this->checkProperties('generators')){
285
-            $generators = array_merge(isset($generators) ? $generators: [],$this->getGenerators());
284
+        if ($this->checkProperties('generators')) {
285
+            $generators = array_merge(isset($generators) ? $generators : [], $this->getGenerators());
286 286
         }
287 287
 
288
-        if(isset($generators)){
288
+        if (isset($generators)) {
289 289
             $this->generatorMethod($generators);
290 290
         }
291 291
     }
@@ -300,21 +300,21 @@  discard block
 block discarded – undo
300 300
     private function generatorMethod($generators)
301 301
     {
302 302
         //generator array object
303
-        foreach ($generators as $generator){
303
+        foreach ($generators as $generator) {
304 304
 
305 305
             //generator method name
306 306
             $generatorMethodName = $generator.'Generator';
307 307
 
308 308
             // if the generator method is present,
309 309
             // the fake value is assigned.
310
-            if(method_exists($this,$generatorMethodName)){
310
+            if (method_exists($this, $generatorMethodName)) {
311 311
 
312 312
                 //fake registration
313
-                if(!isset($this->inputs[$generator])){
313
+                if (!isset($this->inputs[$generator])) {
314 314
 
315 315
                     $generatorMethodNameResult = $this->{$generatorMethodName}();
316 316
 
317
-                    if(!is_null($generatorMethodNameResult)){
317
+                    if (!is_null($generatorMethodNameResult)) {
318 318
                         $this->{$generator} = $this->{$generatorMethodName}();
319 319
                         $this->inputs[$generator] = $this->{$generatorMethodName}();
320 320
                         $this->generatorList[] = $generator;
@@ -322,15 +322,15 @@  discard block
 block discarded – undo
322 322
                 }
323 323
                 else {
324 324
 
325
-                    if($this->checkProperties('auto_generators_dont_overwrite')
326
-                        && in_array($generator,$this->getAutoGeneratorsDontOverwrite())){
325
+                    if ($this->checkProperties('auto_generators_dont_overwrite')
326
+                        && in_array($generator, $this->getAutoGeneratorsDontOverwrite())) {
327 327
                         $this->{$generator} = $this->{$generatorMethodName}();
328 328
                         $this->inputs[$generator] = $this->{$generatorMethodName}();
329 329
                         $this->generatorList[] = $generator;
330 330
                     }
331 331
 
332
-                    if($this->checkProperties('generators_dont_overwrite')
333
-                        && in_array($generator,$this->getGeneratorsDontOverwrite())){
332
+                    if ($this->checkProperties('generators_dont_overwrite')
333
+                        && in_array($generator, $this->getGeneratorsDontOverwrite())) {
334 334
                         $this->{$generator} = $this->{$generatorMethodName}();
335 335
                         $this->inputs[$generator] = $this->{$generatorMethodName}();
336 336
                         $this->generatorList[] = $generator;
@@ -360,19 +360,19 @@  discard block
 block discarded – undo
360 360
      * @param null $key
361 361
      * @param null $callback
362 362
      */
363
-    public function groupsProcess($key=null,$callback=null)
363
+    public function groupsProcess($key = null, $callback = null)
364 364
     {
365
-        if(property_exists($this,'groups') && is_array($this->groups)){
365
+        if (property_exists($this, 'groups') && is_array($this->groups)) {
366 366
 
367 367
             $clientObjects = $this->getClientObjects();
368 368
 
369
-            foreach ($this->groups as $group){
370
-                if(isset($clientObjects['origin'][$group][$key])){
369
+            foreach ($this->groups as $group) {
370
+                if (isset($clientObjects['origin'][$group][$key])) {
371 371
                     $this->{$key} = $clientObjects['origin'][$group][$key];
372 372
                     $this->inputs[$key] = $this->{$key};
373 373
 
374
-                    if(is_callable($callback)){
375
-                        call_user_func_array($callback,[$key]);
374
+                    if (is_callable($callback)) {
375
+                        call_user_func_array($callback, [$key]);
376 376
                     }
377 377
                 }
378 378
             }
@@ -433,7 +433,7 @@  discard block
 block discarded – undo
433 433
     {
434 434
         // we use the http method to write
435 435
         // the values to the inputs and origin properties.
436
-        foreach($this->clientData as $key=>$value){
436
+        foreach ($this->clientData as $key=>$value) {
437 437
 
438 438
             //inputs and origin properties
439 439
             $this->inputs[$key] = $value;
@@ -449,9 +449,9 @@  discard block
 block discarded – undo
449 449
      */
450 450
     private function requestExcept()
451 451
     {
452
-        if(property_exists($this,'requestExcept') && is_array($this->requestExcept)){
453
-            foreach ($this->requestExcept as $item){
454
-                if(isset($this->inputs[$item])){
452
+        if (property_exists($this, 'requestExcept') && is_array($this->requestExcept)) {
453
+            foreach ($this->requestExcept as $item) {
454
+                if (isset($this->inputs[$item])) {
455 455
                     unset($this->inputs[$item]);
456 456
                 }
457 457
             }
@@ -464,16 +464,16 @@  discard block
 block discarded – undo
464 464
      * @param null|string $clientName
465 465
      * @return void|mixed
466 466
      */
467
-    public function setClientName($clientName=null)
467
+    public function setClientName($clientName = null)
468 468
     {
469
-        if(!is_null($clientName) && is_string($clientName)){
469
+        if (!is_null($clientName) && is_string($clientName)) {
470 470
             return $this->clientName = $clientName;
471 471
         }
472 472
 
473
-        if(!is_null(Utils::trace(0)) && isset(Utils::trace(0)['object'])){
473
+        if (!is_null(Utils::trace(0)) && isset(Utils::trace(0)['object'])) {
474 474
             $backTrace = Utils::trace(0)['object'];
475 475
 
476
-            if(property_exists($backTrace,'clientName')){
476
+            if (property_exists($backTrace, 'clientName')) {
477 477
                 $this->clientName = $backTrace->clientName;
478 478
             }
479 479
         }
@@ -490,16 +490,16 @@  discard block
 block discarded – undo
490 490
 
491 491
         // we update the input values ​​after
492 492
         // we receive and check the saved objects.
493
-        foreach ($clientObjects as $key=>$value){
493
+        foreach ($clientObjects as $key=>$value) {
494 494
 
495 495
             // we should do key control for group format.
496 496
             // this process will allow us to perform key control for 2D array correctly.
497
-            $this->groupsProcess($key,function($key){
497
+            $this->groupsProcess($key, function($key) {
498 498
                 $this->registerRequestInputs($key);
499 499
                 unset($this->inputs[$key]);
500 500
             });
501 501
 
502
-            if(!in_array($key,$this->generatorList) && isset($clientObjects['origin'][$key])){
502
+            if (!in_array($key, $this->generatorList) && isset($clientObjects['origin'][$key])) {
503 503
 
504 504
                 $this->{$key} = $clientObjects['origin'][$key];
505 505
                 $this->inputs[$key] = $this->{$key};
@@ -527,11 +527,11 @@  discard block
 block discarded – undo
527 527
 
528 528
         // the request update to be performed using
529 529
         // the method name to be used with the http method.
530
-        $this->setRequestInputs($requestMethod,$key);
530
+        $this->setRequestInputs($requestMethod, $key);
531 531
 
532 532
         // the request update to be performed using
533 533
         // the method name to be used without the http method.
534
-        $this->setRequestInputs($key,$key);
534
+        $this->setRequestInputs($key, $key);
535 535
     }
536 536
 
537 537
     /**
@@ -542,28 +542,28 @@  discard block
 block discarded – undo
542 542
      *
543 543
      * @throws ReflectionExceptionAlias
544 544
      */
545
-    private function setRequestInputs($method,$key)
545
+    private function setRequestInputs($method, $key)
546 546
     {
547
-        if(!in_array($key,$this->generatorList) && method_exists($this,$method) && $this->reflection->reflectionMethodParams($method)->isProtected){
547
+        if (!in_array($key, $this->generatorList) && method_exists($this, $method) && $this->reflection->reflectionMethodParams($method)->isProtected) {
548 548
 
549 549
             //check annotations for method
550
-            $annotation = app()->resolve(ClientAnnotationManager::class,['request'=>$this]);
551
-            $annotation->annotation($method,$key);
550
+            $annotation = app()->resolve(ClientAnnotationManager::class, ['request'=>$this]);
551
+            $annotation->annotation($method, $key);
552 552
 
553
-            if(isset($this->inputs[$key]) && is_array($this->inputs[$key])){
553
+            if (isset($this->inputs[$key]) && is_array($this->inputs[$key])) {
554 554
 
555 555
                 $inputKeys = $this->inputs[$key];
556 556
 
557 557
                 $this->inputs[$key] = [];
558
-                foreach ($inputKeys as $input){
558
+                foreach ($inputKeys as $input) {
559 559
 
560 560
                     $this->{$key}               = $input;
561 561
                     $keyMethod                  = $this->{$method}();
562 562
                     $this->inputs[$key][]       = $keyMethod;
563 563
                 }
564 564
             }
565
-            else{
566
-                if(isset($this->inputs[$key])){
565
+            else {
566
+                if (isset($this->inputs[$key])) {
567 567
                     $keyMethod = $this->{$method}();
568 568
                     $this->inputs[$key] = $keyMethod;
569 569
                 }
@@ -582,8 +582,8 @@  discard block
 block discarded – undo
582 582
         // the auto object validate property is the property
583 583
         // where all of your request values ​​are automatically validated.
584 584
         /** @noinspection PhpParamsInspection */
585
-        if(property_exists($this,'autoObjectValidate')
586
-            && is_array($this->autoObjectValidate) && count($this->autoObjectValidate)){
585
+        if (property_exists($this, 'autoObjectValidate')
586
+            && is_array($this->autoObjectValidate) && count($this->autoObjectValidate)) {
587 587
             $this->autoValidate('autoObjectValidate');
588 588
         }
589 589
     }
Please login to merge, or discard this patch.