| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | /* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  |  * hirak/prestissimo | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * @author Hiraku NAKANO | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * @license MIT https://github.com/hirak/prestissimo | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | namespace Hirak\Prestissimo\Aspects; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | use Composer\IO; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | use Composer\Composer; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | use Composer\Config as CConfig; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | use Composer\Downloader; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |  * Simple Container for http-get request | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  | class HttpGetRequest | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |     public $origin; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |     public $scheme = 'http'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |     public $host = 'example.com'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |     public $port = 80; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |     public $path = '/'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |     public $query = array(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |     public $headers = array(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |     public $curlOpts = array(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |     public $username = null; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |     public $password = null; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |     public $maybePublic = false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |     public $verbose = false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |     /** @var CConfig */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |     protected $config; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |     /** @internal */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |     const TOKEN_LABEL = 'access_token'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |      * normalize url and authentication info | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |      * @param string $origin domain text | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |      * @param string $url | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |      * @param IO\IOInterface $io | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 | 35 |  |     public function __construct($origin, $url, IO\IOInterface $io) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 | 35 |  |         $this->origin = $origin; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 | 35 |  |         $this->importURL($url); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 | 35 |  |         if ($this->username && $this->password) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 | 3 |  |             $io->setAuthentication($origin, $this->username, $this->password); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 | 33 |  |         } elseif ($io->hasAuthentication($origin)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 | 2 |  |             $auth = $io->getAuthentication($origin); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 | 2 |  |             $this->username = $auth['username']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 | 2 |  |             $this->password = $auth['password']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 | 35 |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |      * @param string $url | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 | 35 |  |     public function importURL($url) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 | 35 |  |         $struct = parse_url($url); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |         // @codeCoverageIgnoreStart | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |         if (!$struct) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |             throw new \InvalidArgumentException("$url is not valid URL"); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |         // @codeCoverageIgnoreEnd | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 | 35 |  |         $this->scheme = self::setOr($struct, 'scheme'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 | 35 |  |         $this->host = self::setOr($struct, 'host'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 | 35 |  |         $this->port = self::setOr($struct, 'port'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 | 35 |  |         $this->path = self::setOr($struct, 'path'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 | 35 |  |         $this->username = self::setOr($struct, 'user'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 | 35 |  |         $this->password = self::setOr($struct, 'pass'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 | 35 |  |         if (!empty($struct['query'])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 | 9 |  |             parse_str($struct['query'], $this->query); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 | 35 |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |      * @param array $struct | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |      * @param string $key | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |      * @param string $default | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |      * @return mixed | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 | 35 |  |     private static function setOr(array $struct, $key, $default = null) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 | 35 |  |         if (!empty($struct[$key])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 | 35 |  |             return $struct[$key]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 | 35 |  |         return $default; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |      * process option for RemortFileSystem | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |      * @param array $options | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |      * @return void | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 | 8 |  |     public function processRFSOption(array $options) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 | 8 |  |         if (isset($options[static::TOKEN_LABEL])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 | 2 |  |             $this->query['access_token'] = $options[static::TOKEN_LABEL]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 | 8 |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  |      * @return array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 | 10 |  |     public function getCurlOpts() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 | 10 |  |         $headers = $this->headers; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 | 10 |  |         if ($this->username && $this->password) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 | 1 |  |             foreach ($headers as $i => $header) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 |  |  |                 if (0 === strpos($header, 'Authentication:')) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 |  |  |                     unset($headers[$i]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 |  |  |                 } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 | 1 |  |             $headers[] = 'Authentication: Basic ' . base64_encode("$this->username:$this->password"); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 129 | 10 |  |         $curlOpts = $this->curlOpts + array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 130 | 10 |  |             CURLOPT_HTTPGET => true, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 131 | 10 |  |             CURLOPT_FOLLOWLOCATION => true, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 132 | 10 |  |             CURLOPT_MAXREDIRS => 20, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 133 | 10 |  |             CURLOPT_ENCODING => 'gzip', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 134 | 10 |  |             CURLOPT_HTTPHEADER => $headers, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 135 | 10 |  |             CURLOPT_USERAGENT => $this->genUA(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 136 | 10 |  |             CURLOPT_VERBOSE => (bool)$this->verbose, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 137 | 10 |  |             CURLOPT_URL => $this->getUrl(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 138 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 139 | 10 |  |         unset($curlOpts[CURLOPT_USERPWD]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 140 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 141 | 10 |  |         if ($ciphers = $this->nssCiphers()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 142 |  |  |             $curlOpts[CURLOPT_SSL_CIPHER_LIST] = $ciphers; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 143 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 144 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 145 | 10 |  |         return $curlOpts; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 146 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 147 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 148 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 149 |  |  |      * enable ECC cipher suites in cURL/NSS | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 150 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 151 | 10 |  |     public function nssCiphers() | 
            
                                                                        
                            
            
                                    
            
            
                | 152 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 153 | 10 |  |         static $cache; | 
            
                                                                        
                            
            
                                    
            
            
                | 154 | 10 |  |         if (isset($cache)) { | 
            
                                                                        
                            
            
                                    
            
            
                | 155 | 9 |  |             return $cache; | 
            
                                                                        
                            
            
                                    
            
            
                | 156 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 157 | 2 |  |         $ver = curl_version(); | 
            
                                                                        
                            
            
                                    
            
            
                | 158 | 2 |  |         if (preg_match('/^NSS.*Basic ECC$/', $ver['ssl_version'])) { | 
            
                                                                        
                            
            
                                    
            
            
                | 159 |  |  |             $ciphers = array(); | 
            
                                                                        
                            
            
                                    
            
            
                | 160 |  |  |             foreach (new \SplFileObject(__DIR__ . '/../../res/nss_ciphers.txt') as $line) { | 
            
                                                                        
                            
            
                                    
            
            
                | 161 |  |  |                 $line = trim($line); | 
            
                                                                        
                            
            
                                    
            
            
                | 162 |  |  |                 if ($line) { | 
            
                                                                        
                            
            
                                    
            
            
                | 163 |  |  |                     $ciphers[] = $line; | 
            
                                                                        
                            
            
                                    
            
            
                | 164 |  |  |                 } | 
            
                                                                        
                            
            
                                    
            
            
                | 165 |  |  |             } | 
            
                                                                        
                            
            
                                    
            
            
                | 166 |  |  |             return $cache = implode(',', $ciphers); | 
            
                                                                        
                            
            
                                    
            
            
                | 167 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 168 | 2 |  |         return $cache = false; | 
            
                                                                        
                            
            
                                    
            
            
                | 169 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 170 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 171 | 18 |  |     public function getURL() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 172 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 173 | 18 |  |         $url = ''; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 174 | 18 |  |         if ($this->scheme) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 175 | 18 |  |             $url .= "$this->scheme://"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 176 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 177 | 18 |  |         $url .= $this->host; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 178 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 179 | 18 |  |         if ($this->port) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 180 | 9 |  |             $url .= ":$this->port"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 181 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 182 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 183 | 18 |  |         $url .= $this->path; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 184 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 185 | 18 |  |         if ($this->query) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 186 | 9 |  |             $url .= '?' . http_build_query($this->query); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 187 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 188 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 189 | 18 |  |         return $url; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 190 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 191 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 192 | 5 |  |     public function setConfig(CConfig $config) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 193 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 194 | 5 |  |         $this->config = $config; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 195 | 5 |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 196 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 197 | 6 |  |     public function promptAuth(HttpGetResponse $res, IO\IOInterface $io) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 198 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 199 | 6 |  |         $httpCode = $res->info['http_code']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 200 |  |  |         // 404s are only handled for github | 
            
                                                                                                            
                            
            
                                    
            
            
                | 201 | 6 |  |         if (404 === $httpCode) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 202 | 1 |  |             return false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 203 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 204 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 205 |  |  |         // fail if the console is not interactive | 
            
                                                                                                            
                            
            
                                    
            
            
                | 206 | 5 |  |         if (!$io->isInteractive() && ($httpCode === 401 || $httpCode === 403)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 207 | 3 |  |             $message = "The '{$this->getURL()}' URL required authentication.\nYou must be using the interactive console to authenticate"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 208 | 3 |  |             throw new Downloader\TransportException($message, $httpCode); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 209 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 210 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 211 |  |  |         // fail if we already have auth | 
            
                                                                                                            
                            
            
                                    
            
            
                | 212 | 2 |  |         if ($io->hasAuthentication($this->origin)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 213 | 1 |  |             throw new Downloader\TransportException("Invalid credentials for '{$this->getURL()}', aborting.", $httpCode); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 214 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 215 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 216 | 1 |  |         $io->overwrite("    Authentication required (<info>$this->host</info>):"); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 217 | 1 |  |         $username = $io->ask('      Username: '); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 218 | 1 |  |         $password = $io->askAndHideAnswer('      Password: '); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 219 | 1 |  |         $io->setAuthentication($this->origin, $username, $password); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 220 | 1 |  |         return true; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 221 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 222 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 223 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 224 |  |  |      * @internal | 
            
                                                                                                            
                            
            
                                    
            
            
                | 225 |  |  |      * @param int $privateCode 404|403 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 226 |  |  |      * @param Composer\Util\GitHub|Composer\Util\GitLab $util | 
            
                                                                                                            
                            
            
                                    
            
            
                | 227 |  |  |      * @param HttpGetResponse $res | 
            
                                                                                                            
                            
            
                                    
            
            
                | 228 |  |  |      * @param IO\IOInterface $io | 
            
                                                                                                            
                            
            
                                    
            
            
                | 229 |  |  |      * @throws Composer\Downloader\TransportException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 230 |  |  |      * @return bool | 
            
                                                                                                            
                            
            
                                    
            
            
                | 231 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 232 | 2 |  |     public function promptAuthWithUtil($privateCode, $util, HttpGetResponse $res, IO\IOInterface $io) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 233 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 234 | 2 |  |         $httpCode = $res->info['http_code']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 235 | 2 |  |         $message = "\nCould not fetch {$this->getURL()}, enter your $this->origin credentials "; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 236 | 2 |  |         if ($privateCode === $httpCode) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 237 | 1 |  |             $message .= 'to access private repos'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 238 |  |  |         } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 239 | 1 |  |             $message .= 'to go over the API rate limit'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 240 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 241 | 2 |  |         if ($util->authorizeOAuth($this->origin)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 242 | 1 |  |             return true; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 243 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 244 | 2 |  |         if ($io->isInteractive() && | 
            
                                                                                                            
                            
            
                                    
            
            
                | 245 | 2 |  |             $util->authorizeOAuthInteractively($this->origin, $message)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 246 | 1 |  |             return true; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 247 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 248 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 249 | 1 |  |         throw new Downloader\TransportException("Could not authenticate against $this->origin", $httpCode); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 250 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 251 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 252 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 253 |  |  |      * @return string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 254 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 255 | 10 |  |     public static function genUA() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 256 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 257 | 10 |  |         static $ua; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 258 | 10 |  |         if ($ua) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 259 | 9 |  |             return $ua; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 260 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 261 | 2 |  |         $phpVersion = defined('HHVM_VERSION') ? 'HHVM ' . HHVM_VERSION : 'PHP ' . PHP_VERSION; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 262 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 263 | 2 |  |         return $ua = sprintf( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 264 | 2 |  |             'Composer/%s (%s; %s; %s)', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 265 | 2 |  |             str_replace('@package_version@', 'source', Composer::VERSION), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 266 | 2 |  |             php_uname('s'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 267 | 2 |  |             php_uname('r'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 268 |  |  |             $phpVersion | 
            
                                                                                                            
                            
            
                                    
            
            
                | 269 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 270 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 271 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 272 |  |  |  | 
            
                        
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)or! empty(...)instead.