original_string: private static function mergeQueryString(?string $queryString, array $queryArray, bool $replace): ?string
      {
          if (!$queryArray) {
              return $queryString;
          }
  
          $query = [];
  
          if (null !== $queryString) {
              foreach (explode('&', $queryString) as $v) {
                  if ('' !== $v) {
                      $k = urldecode(explode('=', $v, 2)[0]);
                      $query[$k] = (isset($query[$k]) ? $query[$k].'&' : '').$v;
                  }
              }
          }
  
          foreach ($queryArray as $k => $v) {
              if (is_scalar($v)) {
                  $queryArray[$k] = rawurlencode($k).'='.rawurlencode($v);
              } elseif (null === $v) {
                  unset($queryArray[$k]);
  
                  if ($replace) {
                      unset($query[$k]);
                  }
              } else {
                  throw new InvalidArgumentException(sprintf('Unsupported value for query parameter "%s": scalar or null expected, %s given.', $k, \gettype($v)));
              }
          }
  
          return implode('&', $replace ? array_replace($query, $queryArray) : ($query + $queryArray));
      }
code: private static function mergeQueryString(?string $queryString, array $queryArray, bool $replace): ?string
      {
          if (!$queryArray) {
              return $queryString;
          }
  
          $query = [];
  
          if (null !== $queryString) {
              foreach (explode('&', $queryString) as $v) {
                  if ('' !== $v) {
                      $k = urldecode(explode('=', $v, 2)[0]);
                      $query[$k] = (isset($query[$k]) ? $query[$k].'&' : '').$v;
                  }
              }
          }
  
          foreach ($queryArray as $k => $v) {
              if (is_scalar($v)) {
                  $queryArray[$k] = rawurlencode($k).'='.rawurlencode($v);
              } elseif (null === $v) {
                  unset($queryArray[$k]);
  
                  if ($replace) {
                      unset($query[$k]);
                  }
              } else {
                  throw new InvalidArgumentException(sprintf('Unsupported value for query parameter "%s": scalar or null expected, %s given.', $k, \gettype($v)));
              }
          }
  
          return implode('&', $replace ? array_replace($query, $queryArray) : ($query + $queryArray));
      }
code_tokens: private static function mergeQueryString ( ? string $ queryString , array $ queryArray , bool $ replace ) : ? string { if ( ! $ queryArray ) { return $ queryString ; } $ query = [ ] ; if ( null !== $ queryString ) { foreach ( explode ( '&' , $ queryString ) as $ v ) { if ( '' !== $ v ) { $ k = urldecode ( explode ( '=' , $ v , 2 ) [ 0 ] ) ; $ query [ $ k ] = ( isset ( $ query [ $ k ] ) ? $ query [ $ k ] . '&' : '' ) . $ v ; } } } foreach ( $ queryArray as $ k => $ v ) { if ( is_scalar ( $ v ) ) { $ queryArray [ $ k ] = rawurlencode ( $ k ) . '=' . rawurlencode ( $ v ) ; } elseif ( null === $ v ) { unset ( $ queryArray [ $ k ] ) ; if ( $ replace ) { unset ( $ query [ $ k ] ) ; } } else { throw new InvalidArgumentException ( sprintf ( 'Unsupported value for query parameter "%s": scalar or null expected, %s given.' , $ k , \ gettype ( $ v ) ) ) ; } } return implode ( '&' , $ replace ? array_replace ( $ query , $ queryArray ) : ( $ query + $ queryArray ) ) ; }
docstring: Merges and encodes a query array with a query string.
  
  @throws InvalidArgumentException When an invalid query-string value is passed
docstring_tokens: Merges and encodes a query array with a query string .