| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | declare(strict_types=1); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * Gateway Client Class | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  * @category    Ticaje | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  * @author      Max Demian <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | namespace Ticaje\AConnector\Gateway\Implementations\Client\Rest; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | use Psr\Http\Message\ResponseInterface; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | use RuntimeException; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | use Ticaje\AConnector\Interfaces\Implementors\Client\Rest\RestClientImplementorInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | use Ticaje\AConnector\Interfaces\Protocol\RestClientInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  | use Ticaje\Contract\Patterns\Interfaces\Decorator\ResponderInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |  * Class Guzzle | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |  * @package Ticaje\AConnector\Gateway\Implementations\Client\Rest | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  | class Guzzle implements RestClientImplementorInterface, RestClientInterface | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |     private $client; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |      * @inheritDoc | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |     public function setClient($client) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |         $this->client = $client; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |      * @inheritDoc | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |     public function requestAsync($verb, $endpoint, array $headers = [], array $params) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |         $result = []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |         try { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |             $promise = $this->client->requestAsync( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |                 $verb, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |                 $endpoint, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |                 [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |                     'headers' => $this->generateHeaders($headers), | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |                     $this->getFormRequestKey($verb, $headers) => $params | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |                 ] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |             ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |             $promise->then( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |                 function (ResponseInterface $response) use (&$result) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |                     $result[ResponderInterface::CONTENT_KEY] = $response->getBody()->getContents(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |                     $result[ResponderInterface::SUCCESS_KEY] = true; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |                     $result[ResponderInterface::MESSAGE_KEY] = 'Response correctly received'; // Perhaps normalize this message | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |                     return $result; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |                 }, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |                 function (RuntimeException $exception) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |                     // Missing implementation | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |                 } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |             ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |             $promise->wait(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |         } catch (\Exception $exception) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |             $result[ResponderInterface::CONTENT_KEY] = null; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |             $result[ResponderInterface::SUCCESS_KEY] = false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |             $result[ResponderInterface::MESSAGE_KEY] = $exception->getMessage(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |         return $result; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |      * @inheritDoc | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 71 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 72 |  |  |     public function request($verb, $endpoint, array $headers = [], array $params = []) | 
            
                                                                        
                            
            
                                    
            
            
                | 73 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 74 |  |  |         $result = []; | 
            
                                                                        
                            
            
                                    
            
            
                | 75 |  |  |         try { | 
            
                                                                        
                            
            
                                    
            
            
                | 76 |  |  |             $result[ResponderInterface::CONTENT_KEY] = $this->client->request( | 
            
                                                                        
                            
            
                                    
            
            
                | 77 |  |  |                 $verb, | 
            
                                                                        
                            
            
                                    
            
            
                | 78 |  |  |                 $endpoint, | 
            
                                                                        
                            
            
                                    
            
            
                | 79 |  |  |                 [ | 
            
                                                                        
                            
            
                                    
            
            
                | 80 |  |  |                     'headers' => $headers, | 
            
                                                                        
                            
            
                                    
            
            
                | 81 |  |  |                     $this->getFormRequestKey($verb, $headers) => $params | 
            
                                                                        
                            
            
                                    
            
            
                | 82 |  |  |                 ] | 
            
                                                                        
                            
            
                                    
            
            
                | 83 |  |  |             )->getBody()->getContents(); | 
            
                                                                        
                            
            
                                    
            
            
                | 84 |  |  |             $result[ResponderInterface::SUCCESS_KEY] = true; | 
            
                                                                        
                            
            
                                    
            
            
                | 85 |  |  |             $result[ResponderInterface::MESSAGE_KEY] = 'Response correctly received'; // Perhaps normalize this message | 
            
                                                                        
                            
            
                                    
            
            
                | 86 |  |  |         } catch (\Exception $exception) { | 
            
                                                                        
                            
            
                                    
            
            
                | 87 |  |  |             $result[ResponderInterface::CONTENT_KEY] = null; | 
            
                                                                        
                            
            
                                    
            
            
                | 88 |  |  |             $result[ResponderInterface::SUCCESS_KEY] = false; | 
            
                                                                        
                            
            
                                    
            
            
                | 89 |  |  |             $result[ResponderInterface::MESSAGE_KEY] = $exception->getMessage(); | 
            
                                                                        
                            
            
                                    
            
            
                | 90 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 91 |  |  |         return $result; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |      * @param $verb | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |      * @param $headers | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |      * @return string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |     private function getFormRequestKey($verb, $headers) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |         // The values should also be constantized | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |         $key = $verb ? 'query' : 'form_params'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |         $key = $headers[RestClientInterface::CONTENT_TYPE_KEY] == RestClientInterface::CONTENT_TYPE_JSON ? 'json' : $key; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |         return $key; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 106 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 107 |  |  |  | 
            
                        
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths