| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | /* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * This file is part of the Ivory Http Adapter package. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  * (c) Eric GELOEN <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  * For the full copyright and license information, please read the LICENSE | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  * file that was distributed with this source code. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | namespace Ivory\HttpAdapter; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | use Ivory\HttpAdapter\Message\InternalRequestInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | use Ivory\HttpAdapter\Normalizer\BodyNormalizer; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |  * @author GeLo <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |  */ | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 20 |  | View Code Duplication | class Zend1HttpAdapter extends AbstractHttpAdapter | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |     /** @var \Zend_Http_Client */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |     private $client; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |      * @param \Zend_Http_Client|null      $client | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |      * @param ConfigurationInterface|null $configuration | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 28 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 29 | 2254 |  |     public function __construct(\Zend_Http_Client $client = null, ConfigurationInterface $configuration = null) | 
            
                                                                        
                            
            
                                    
            
            
                | 30 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 31 | 2254 |  |         parent::__construct($configuration); | 
            
                                                                        
                            
            
                                    
            
            
                | 32 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 33 | 2254 |  |         $this->client = $client ?: new \Zend_Http_Client(); | 
            
                                                                        
                            
            
                                    
            
            
                | 34 | 2254 |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |      * {@inheritdoc} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 | 130 |  |     public function getName() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 | 130 |  |         return 'zend1'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |      * {@inheritdoc} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 | 2184 |  |     protected function sendInternalRequest(InternalRequestInterface $internalRequest) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 | 2184 |  |         $this->client | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 | 2184 |  |             ->resetParameters(true) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 | 2184 |  |             ->setConfig([ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 | 2184 |  |                 'httpversion'     => $internalRequest->getProtocolVersion(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 | 2184 |  |                 'timeout'         => $this->getConfiguration()->getTimeout(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 | 2184 |  |                 'request_timeout' => $this->getConfiguration()->getTimeout(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 | 2184 |  |                 'maxredirects'    => 0, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 | 1680 |  |             ]) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 | 2184 |  |             ->setUri($uri = (string) $internalRequest->getUri()) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 | 2184 |  |             ->setMethod($internalRequest->getMethod()) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 | 2184 |  |             ->setHeaders($this->prepareHeaders($internalRequest)) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 | 2184 |  |             ->setRawData($this->prepareBody($internalRequest)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |         try { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 | 2184 |  |             $response = $this->client->request(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 | 1704 |  |         } catch (\Exception $e) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 | 104 |  |             throw HttpAdapterException::cannotFetchUri($uri, $this->getName(), $e->getMessage()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 | 2106 |  |         return $this->getConfiguration()->getMessageFactory()->createResponse( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 | 2106 |  |             $response->getStatus(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 | 2106 |  |             $response->getVersion(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 | 2106 |  |             $response->getHeaders(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 | 2106 |  |             BodyNormalizer::normalize( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 | 2166 |  |                 function () use ($response) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 | 450 |  |                     return $response instanceof \Zend_Http_Response_Stream | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 | 1680 |  |                         ? $response->getStream() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 | 1950 |  |                         : $response->getBody(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 | 2106 |  |                 }, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 | 2106 |  |                 $internalRequest->getMethod() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 | 1620 |  |             ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 | 1620 |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 82 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 83 |  |  |  | 
            
                        
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.