Skip to content

Commit

Permalink
qa: ensure that immutability is given and/or possible mutations are s…
Browse files Browse the repository at this point in the history
…uppressed

Signed-off-by: Maximilian Bösing <[email protected]>
  • Loading branch information
boesing committed Apr 6, 2023
1 parent 9626bab commit dafe22c
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/Uri.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ public function __toString(): string
return $this->uriString;
}

/** @psalm-suppress ImpureMethodCall, InaccessibleProperty */
$this->uriString = static::createUriString(
$this->scheme,
$this->getAuthority(),
Expand Down Expand Up @@ -443,6 +444,9 @@ public function withFragment($fragment): UriInterface

/**
* Parse a URI into its parts, and set the properties
*
* @psalm-suppress InaccessibleProperty Method is only called in {@see Uri::__construct} and thus immutability is
* still given.
*/
private function parseUri(string $uri): void
{
Expand Down Expand Up @@ -553,8 +557,12 @@ private function filterUserInfoPart(string $part): string
{
$part = $this->filterInvalidUtf8($part);

// Note the addition of `%` to initial charset; this allows `|` portion
// to match and thus prevent double-encoding.
/**
* @psalm-suppress ImpureFunctionCall Even tho the callback targets this immutable class,
* psalm reports an issue here.
* Note the addition of `%` to initial charset; this allows `|` portion
* to match and thus prevent double-encoding.
*/
return preg_replace_callback(
'/(?:[^%' . self::CHAR_UNRESERVED . self::CHAR_SUB_DELIMS . ']+|%(?![A-Fa-f0-9]{2}))/u',
[$this, 'urlEncodeChar'],
Expand All @@ -569,6 +577,10 @@ private function filterPath(string $path): string
{
$path = $this->filterInvalidUtf8($path);

/**
* @psalm-suppress ImpureFunctionCall Even tho the callback targets this immutable class,
* psalm reports an issue here.
*/
return preg_replace_callback(
'/(?:[^' . self::CHAR_UNRESERVED . ')(:@&=\+\$,\/;%]+|%(?![A-Fa-f0-9]{2}))/u',
[$this, 'urlEncodeChar'],
Expand Down Expand Up @@ -657,6 +669,10 @@ private function filterQueryOrFragment(string $value): string
{
$value = $this->filterInvalidUtf8($value);

/**
* @psalm-suppress ImpureFunctionCall Even tho the callback targets this immutable class,
* psalm reports an issue here.
*/
return preg_replace_callback(
'/(?:[^' . self::CHAR_UNRESERVED . self::CHAR_SUB_DELIMS . '%:@\/\?]+|%(?![A-Fa-f0-9]{2}))/u',
[$this, 'urlEncodeChar'],
Expand Down

0 comments on commit dafe22c

Please sign in to comment.