Skip to content

Commit

Permalink
Remove the Exceptions namspaces from the package
Browse files Browse the repository at this point in the history
  • Loading branch information
nyamsprod committed Jun 30, 2023
1 parent b8ae19f commit 3050cb4
Show file tree
Hide file tree
Showing 10 changed files with 21 additions and 32 deletions.
33 changes: 13 additions & 20 deletions BaseUri.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,23 +157,22 @@ private static function reducer(array $carry, string $segment): array
private function resolvePathAndQuery(Psr7UriInterface|UriInterface $uri): array
{
$targetPath = $uri->getPath();
$targetQuery = $uri->getQuery();
$null = $uri instanceof Psr7UriInterface ? '' : null;
$baseNull = $this->value instanceof Psr7UriInterface ? '' : null;

if (str_starts_with($targetPath, '/')) {
return [$targetPath, $targetQuery];
return [$targetPath, $uri->getQuery()];
}

if ('' === $targetPath) {
$targetQuery = $uri->getQuery();
if ($null === $targetQuery) {
$targetQuery = $this->value->getQuery();
}

$targetPath = $this->value->getPath();
//@codeCoverageIgnoreStart
//because some PSR-7 Uri implementations allow this RFC3986 forbidden construction
if ($baseNull !== $this->value->getAuthority() && !str_starts_with($targetPath, '/')) {
if (null !== $this->value->getAuthority() && !str_starts_with($targetPath, '/')) {
$targetPath = '/'.$targetPath;
}
//@codeCoverageIgnoreEnd
Expand All @@ -182,7 +181,7 @@ private function resolvePathAndQuery(Psr7UriInterface|UriInterface $uri): array
}

$basePath = $this->value->getPath();
if ($baseNull !== $this->value->getAuthority() && '' === $basePath) {
if (null !== $this->value->getAuthority() && '' === $basePath) {
$targetPath = '/'.$targetPath;
}

Expand All @@ -194,14 +193,14 @@ private function resolvePathAndQuery(Psr7UriInterface|UriInterface $uri): array
}
}

return [$targetPath, $targetQuery];
return [$targetPath, $uri->getQuery()];
}

/**
* Relativizes a URI according to a base URI.
* Relativize a URI according to a base URI.
*
* This method MUST retain the state of the submitted URI instance, and return
* an URI instance of the same type that contains the applied modifications.
* a URI instance of the same type that contains the applied modifications.
*
* This method MUST be transparent when dealing with error and exceptions.
* It MUST not alter of silence them apart from validating its own parameters.
Expand All @@ -217,19 +216,13 @@ public function relativize(Stringable|string $uri): Psr7UriInterface|UriInterfac
$uri = $uri->withScheme($null)->withPort(null)->withUserInfo($null)->withHost($null);
$targetPath = $uri->getPath();
$basePath = $this->value->getPath();
if ($targetPath !== $basePath) {
return $uri->withPath(self::relativizePath($targetPath, $basePath));
}

if (self::componentEquals('query', $uri)) {
return $uri->withPath('')->withQuery($null);
}

if ($null === $uri->getQuery()) {
return $uri->withPath(self::formatPathWithEmptyBaseQuery($targetPath));
}

return $uri->withPath('');
return match (true) {
$targetPath !== $basePath => $uri->withPath(self::relativizePath($targetPath, $basePath)),
self::componentEquals('query', $uri) => $uri->withPath('')->withQuery($null),
$null === $uri->getQuery() => $uri->withPath(self::formatPathWithEmptyBaseQuery($targetPath)),
default => $uri->withPath(''),
};
}

/**
Expand Down
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ All Notable changes to `League\Uri` will be documented in this file
- `League\Uri\Http::fromTemplate`
- `League\Uri\UriTemplate::expandOrFail`
- `League\Uri\UriTemplate\Template::expandOrFail`
- `League\Uri\UriTemplate\TemplateCanNotBeExpanded`
- `League\Uri\UriString::parseAuthority`
- `League\Uri\UriString::buildAuthority`
- `League\Uri\BaseUri`
Expand Down Expand Up @@ -53,7 +54,7 @@ All Notable changes to `League\Uri` will be documented in this file

- Support for `__set_state`
- `League\Uri\UriTemplate\VariableBag::all`
- Support for `PSR-7` v1
- `League\Uri\Exceptions\TemplateCanNotBeExpanded` use `League\Uri\UriTemplate\TemplateCanNotBeExpanded` instead

## [6.8.0](https://github.com/thephpleague/uri/compare/6.7.2...6.8.0) - 2022-09-13

Expand Down
6 changes: 3 additions & 3 deletions UriTemplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
use League\Uri\Contracts\UriException;
use League\Uri\Contracts\UriInterface;
use League\Uri\Exceptions\SyntaxError;
use League\Uri\Exceptions\TemplateCanNotBeExpanded;
use League\Uri\UriTemplate\Template;
use League\Uri\UriTemplate\TemplateCanNotBeExpanded;
use League\Uri\UriTemplate\VariableBag;
use Stringable;
use function array_fill_keys;
Expand All @@ -37,8 +37,8 @@ final class UriTemplate
public readonly VariableBag $defaultVariables;

/**
* @throws SyntaxError if the template syntax is invalid
* @throws TemplateCanNotBeExpanded if the template or the variables are invalid
* @throws SyntaxError if the template syntax is invalid
* @throws \League\Uri\UriTemplate\TemplateCanNotBeExpanded if the template or the variables are invalid
*/
public function __construct(Template|Stringable|string $template, iterable $defaultVariables = [])
{
Expand Down
1 change: 0 additions & 1 deletion UriTemplate/ExpressionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
namespace League\Uri\UriTemplate;

use League\Uri\Exceptions\SyntaxError;
use League\Uri\Exceptions\TemplateCanNotBeExpanded;
use PHPUnit\Framework\TestCase;

/**
Expand Down
1 change: 0 additions & 1 deletion UriTemplate/Operator.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
namespace League\Uri\UriTemplate;

use League\Uri\Exceptions\SyntaxError;
use League\Uri\Exceptions\TemplateCanNotBeExpanded;
use Stringable;
use function implode;
use function is_array;
Expand Down
1 change: 0 additions & 1 deletion UriTemplate/Template.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
namespace League\Uri\UriTemplate;

use League\Uri\Exceptions\SyntaxError;
use League\Uri\Exceptions\TemplateCanNotBeExpanded;
use Stringable;
use function array_fill_keys;
use function array_filter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

declare(strict_types=1);

namespace League\Uri\Exceptions;
namespace League\Uri\UriTemplate;

use InvalidArgumentException;
use League\Uri\Contracts\UriException;
Expand Down
1 change: 0 additions & 1 deletion UriTemplate/VariableBag.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
use Closure;
use Countable;
use IteratorAggregate;
use League\Uri\Exceptions\TemplateCanNotBeExpanded;
use Stringable;
use Traversable;
use function array_filter;
Expand Down
1 change: 0 additions & 1 deletion UriTemplate/VariableBagTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
namespace League\Uri\UriTemplate;

use ArrayIterator;
use League\Uri\Exceptions\TemplateCanNotBeExpanded;
use PHPUnit\Framework\TestCase;
use stdClass;
use TypeError;
Expand Down
4 changes: 2 additions & 2 deletions UriTemplateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
namespace League\Uri;

use League\Uri\Exceptions\SyntaxError;
use League\Uri\Exceptions\TemplateCanNotBeExpanded;
use League\Uri\UriTemplate\TemplateCanNotBeExpanded;
use PHPUnit\Framework\TestCase;

/**
Expand Down Expand Up @@ -356,7 +356,7 @@ public function testExpansionWithMultipleSameExpression(): void

public function testExpandOrFailIfVariablesAreMissing(): void
{
$this->expectException(TemplateCanNotBeExpanded::class);
$this->expectException(UriTemplate\TemplateCanNotBeExpanded::class);

(new UriTemplate('{var}'))->expandOrFail([]);
}
Expand Down

0 comments on commit 3050cb4

Please sign in to comment.