original_string: public function buildUrl($url, $query = [], $options = [])
      {
          if (empty($options) && empty($query)) {
              return $url;
          }
          if ($query) {
              $q = (strpos($url, '?') === false) ? '?' : '&';
              $url .= $q;
              $url .= is_string($query) ? $query : http_build_query($query);
          }
          $defaults = [
              'host' => null,
              'port' => null,
              'scheme' => 'http',
              'protocolRelative' => false
          ];
          $options += $defaults;
  
          if ($options['protocolRelative'] && preg_match('#^//#', $url)) {
              $url = $options['scheme'] . ':' . $url;
          }
          if (preg_match('#^https?://#', $url)) {
              return $url;
          }
  
          $defaultPorts = [
              'http' => 80,
              'https' => 443
          ];
          $out = $options['scheme'] . '://' . $options['host'];
          if ($options['port'] && $options['port'] != $defaultPorts[$options['scheme']]) {
              $out .= ':' . $options['port'];
          }
          $out .= '/' . ltrim($url, '/');
  
          return $out;
      }
code: public function buildUrl($url, $query = [], $options = [])
      {
          if (empty($options) && empty($query)) {
              return $url;
          }
          if ($query) {
              $q = (strpos($url, '?') === false) ? '?' : '&';
              $url .= $q;
              $url .= is_string($query) ? $query : http_build_query($query);
          }
          $defaults = [
              'host' => null,
              'port' => null,
              'scheme' => 'http',
              'protocolRelative' => false
          ];
          $options += $defaults;
  
          if ($options['protocolRelative'] && preg_match('#^//#', $url)) {
              $url = $options['scheme'] . ':' . $url;
          }
          if (preg_match('#^https?://#', $url)) {
              return $url;
          }
  
          $defaultPorts = [
              'http' => 80,
              'https' => 443
          ];
          $out = $options['scheme'] . '://' . $options['host'];
          if ($options['port'] && $options['port'] != $defaultPorts[$options['scheme']]) {
              $out .= ':' . $options['port'];
          }
          $out .= '/' . ltrim($url, '/');
  
          return $out;
      }
code_tokens: public function buildUrl ( $ url , $ query = [ ] , $ options = [ ] ) { if ( empty ( $ options ) && empty ( $ query ) ) { return $ url ; } if ( $ query ) { $ q = ( strpos ( $ url , '?' ) === false ) ? '?' : '&' ; $ url .= $ q ; $ url .= is_string ( $ query ) ? $ query : http_build_query ( $ query ) ; } $ defaults = [ 'host' => null , 'port' => null , 'scheme' => 'http' , 'protocolRelative' => false ] ; $ options += $ defaults ; if ( $ options [ 'protocolRelative' ] && preg_match ( '#^//#' , $ url ) ) { $ url = $ options [ 'scheme' ] . ':' . $ url ; } if ( preg_match ( '#^https?://#' , $ url ) ) { return $ url ; } $ defaultPorts = [ 'http' => 80 , 'https' => 443 ] ; $ out = $ options [ 'scheme' ] . '://' . $ options [ 'host' ] ; if ( $ options [ 'port' ] && $ options [ 'port' ] != $ defaultPorts [ $ options [ 'scheme' ] ] ) { $ out .= ':' . $ options [ 'port' ] ; } $ out .= '/' . ltrim ( $ url , '/' ) ; return $ out ; }
docstring: Generate a URL based on the scoped client options.
  
  @param string $url Either a full URL or just the path.
  @param string|array $query The query data for the URL.
  @param array $options The config options stored with Client::config()
  @return string A complete url with scheme, port, host, and path.
docstring_tokens: Generate a URL based on the scoped client options .