Skip to content

Commit

Permalink
Improve package namespaces
Browse files Browse the repository at this point in the history
  • Loading branch information
nyamsprod committed Aug 3, 2023
1 parent 1a377b1 commit 09be537
Show file tree
Hide file tree
Showing 22 changed files with 107 additions and 115 deletions.
6 changes: 3 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ All Notable changes to `League\Uri\Interfaces` will be documented in this file
- New method to `UserInfoInterface::withPass`
- New method to `UriInterface::toString`
- New method to `UriInterface::toComponents`
- `League\Uri\IPv4Converter` class
- `League\Uri\Idna\IdnaError` class
- `League\Uri\Idna\IdnaOption` class
- `League\Uri\IPv4\Converter` class
- `League\Uri\Idna\Error` class
- `League\Uri\Idna\Option` class
- `League\Uri\UriString` class
- `League\Uri\QueryString` class

Expand Down
12 changes: 6 additions & 6 deletions Contracts/AuthorityInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@

namespace League\Uri\Contracts;

use League\Uri\Exceptions\IdnSupportMissing;
use League\Uri\Exceptions\SyntaxError;
use League\Uri\Idna\MissingSupport;
use Stringable;

interface AuthorityInterface extends UriComponentInterface
Expand Down Expand Up @@ -54,11 +54,11 @@ public function components(): array;
* A null value provided for the host is equivalent to removing the host
* information.
*
* @throws SyntaxError for invalid component or transformations
* that would result in an object in invalid state.
* @throws IdnSupportMissing for component or transformations
* requiring IDN support when IDN support is not present
* or misconfigured.
* @throws SyntaxError for invalid component or transformations
* that would result in an object in invalid state.
* @throws MissingSupport for component or transformations
* requiring IDN support when IDN support is not present
* or misconfigured.
*/
public function withHost(Stringable|string|null $host): self;

Expand Down
4 changes: 1 addition & 3 deletions Contracts/HostInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@

namespace League\Uri\Contracts;

use League\Uri\IPv4\IPv4Calculator;

interface HostInterface extends UriComponentInterface
{
/**
Expand All @@ -33,7 +31,7 @@ public function toUnicode(): ?string;
*
* @see https://url.spec.whatwg.org/#concept-ipv4-parser
*/
public function toIPv4(?IPv4Calculator $calculator = null): ?string;
public function toIPv4(): ?string;

/**
* Returns the IP version.
Expand Down
12 changes: 6 additions & 6 deletions Contracts/UriInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
namespace League\Uri\Contracts;

use JsonSerializable;
use League\Uri\Exceptions\IdnSupportMissing;
use League\Uri\Exceptions\SyntaxError;
use League\Uri\Idna\MissingSupport;
use League\Uri\UriString;
use Stringable;

Expand Down Expand Up @@ -234,11 +234,11 @@ public function withUserInfo(Stringable|string|null $user, Stringable|string|nul
* A null value provided for the host is equivalent to removing the host
* information.
*
* @throws SyntaxError for invalid component or transformations
* that would result in an object in invalid state.
* @throws IdnSupportMissing for component or transformations
* requiring IDN support when IDN support is not present
* or misconfigured.
* @throws SyntaxError for invalid component or transformations
* that would result in an object in invalid state.
* @throws MissingSupport for component or transformations
* requiring IDN support when IDN support is not present
* or misconfigured.
*/
public function withHost(Stringable|string|null $host): self;

Expand Down
2 changes: 1 addition & 1 deletion IPv4/BCMathCalculator.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
use function bcsub;
use function str_split;

final class BCMathCalculator implements IPv4Calculator
final class BCMathCalculator implements Calculator
{
private const SCALE = 0;
private const CONVERSION_TABLE = [
Expand Down
10 changes: 5 additions & 5 deletions IPv4/IPv4Calculator.php → IPv4/Calculator.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

namespace League\Uri\IPv4;

interface IPv4Calculator
interface Calculator
{
/**
* Add numbers.
Expand All @@ -28,8 +28,8 @@ public function add(mixed $value1, mixed $value2);
/**
* Subtract one number from another.
*
* @param mixed $value1 a number that will be substracted of $value2
* @param mixed $value2 a number that will be substracted to $value1
* @param mixed $value1 a number that will be subtracted of $value2
* @param mixed $value2 a number that will be subtracted to $value1
*
* @return mixed the subtraction result
*/
Expand All @@ -38,8 +38,8 @@ public function sub(mixed $value1, mixed $value2);
/**
* Multiply numbers.
*
* @param mixed $value1 a number that will be multiply by $value2
* @param mixed $value2 a number that will be multiply by $value1
* @param mixed $value1 a number that will be multiplied by $value2
* @param mixed $value2 a number that will be multiplied by $value1
*
* @return mixed the multiplication result
*/
Expand Down
11 changes: 5 additions & 6 deletions IPv4/IPv4Converter.php → IPv4/Converter.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
use function substr;
use const PHP_INT_SIZE;

final class IPv4Converter
final class Converter
{
private const REGEXP_IPV4_HOST = '/
(?(DEFINE) # . is missing as it is used to separate labels
Expand All @@ -45,7 +45,7 @@ final class IPv4Converter
private readonly mixed $maxIpv4Number;

public function __construct(
private readonly IPv4Calculator $calculator
private readonly Calculator $calculator
) {
$this->maxIpv4Number = $calculator->sub($calculator->pow(2, 32), 1);
}
Expand Down Expand Up @@ -77,8 +77,7 @@ public static function fromNative(): self
/**
* Returns an instance using a detected calculator depending on the PHP environment.
*
* @throws MissingIPv4Calculator If no IPv4Calculator implementing object can be used
* on the platform
* @throws MissingCalculator If no Calculator implementing object can be used on the platform
*
* @codeCoverageIgnore
*/
Expand All @@ -88,9 +87,9 @@ public static function fromEnvironment(): self
extension_loaded('gmp') => self::fromGMP(),
extension_loaded('bcmath') => self::fromBCMath(),
4 < PHP_INT_SIZE => self::fromNative(),
default => throw new MissingIPv4Calculator(sprintf(
default => throw new MissingCalculator(sprintf(
'No %s found. Use a x.64 PHP build or install the GMP or the BCMath extension.',
IPv4Calculator::class
Calculator::class
))
};
}
Expand Down
12 changes: 6 additions & 6 deletions IPv4/IPv4ConverterTest.php → IPv4/ConverterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
use const PHP_INT_SIZE;

/**
* @coversDefaultClass \League\Uri\IPv4\IPv4Converter
* @coversDefaultClass \League\Uri\IPv4\Converter
*/
final class IPv4ConverterTest extends TestCase
final class ConverterTest extends TestCase
{
/**
* @dataProvider providerHost
Expand All @@ -33,7 +33,7 @@ public function testParseWithAutoDetectCalculator(?string $input, ?string $expec
self::markTestSkipped('The PHP must be compile for a x64 OS or loads the GMP or the BCmath extension.');
}

self::assertEquals($expected, IPv4Converter::fromEnvironment()($input) ?? $input);
self::assertEquals($expected, Converter::fromEnvironment()($input) ?? $input);
}

/**
Expand All @@ -47,7 +47,7 @@ public function testParseWithGMPCalculator(?string $input, ?string $expected): v
self::markTestSkipped('The GMP extension is needed to execute this test.');
}

self::assertEquals($expected, IPv4Converter::fromGMP()($input) ?? $input);
self::assertEquals($expected, Converter::fromGMP()($input) ?? $input);
}

/**
Expand All @@ -61,7 +61,7 @@ public function testParseWithNativeCalculator(?string $input, ?string $expected)
self::markTestSkipped('The PHP must be compile for a x64 OS.');
}

self::assertEquals($expected, IPv4Converter::fromNative()($input) ?? $input);
self::assertEquals($expected, Converter::fromNative()($input) ?? $input);
}

/**
Expand All @@ -75,7 +75,7 @@ public function testParseWithBCMathCalculator(?string $input, ?string $expected)
self::markTestSkipped('The PHP must be compile with Bcmath extension enabled.');
}

self::assertEquals($expected, IPv4Converter::fromBCMath()($input) ?? $input);
self::assertEquals($expected, Converter::fromBCMath()($input) ?? $input);
}

public static function providerHost(): array
Expand Down
2 changes: 1 addition & 1 deletion IPv4/GMPCalculator.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
use function gmp_sub;
use const GMP_ROUND_MINUSINF;

final class GMPCalculator implements IPv4Calculator
final class GMPCalculator implements Calculator
{
public function baseConvert(mixed $value, int $base): GMP
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@
use InvalidArgumentException;
use League\Uri\Contracts\UriException;

class MissingIPv4Calculator extends InvalidArgumentException implements UriException
class MissingCalculator extends InvalidArgumentException implements UriException
{
}
2 changes: 1 addition & 1 deletion IPv4/NativeCalculator.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
use function floor;
use function intval;

final class NativeCalculator implements IPv4Calculator
final class NativeCalculator implements Calculator
{
public function baseConvert(mixed $value, int $base): int
{
Expand Down
19 changes: 9 additions & 10 deletions Exceptions/IdnaConversionFailed.php → Idna/ConversionFailed.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,24 @@

declare(strict_types=1);

namespace League\Uri\Exceptions;
namespace League\Uri\Idna;

use League\Uri\Idna\IdnaError;
use League\Uri\Idna\IdnaInfo;
use League\Uri\Exceptions\SyntaxError;

final class IdnaConversionFailed extends SyntaxError
final class ConversionFailed extends SyntaxError
{
private function __construct(string $message, private readonly ?IdnaInfo $idnaInfo = null)
private function __construct(string $message, private readonly ?Result $result = null)
{
parent::__construct($message);
}

public static function dueToIDNAError(string $domain, IdnaInfo $idnaInfo): self
public static function dueToError(string $domain, Result $result): self
{
$info = array_map(fn (IdnaError $error): string => $error->description(), $idnaInfo->errors());
$info = array_map(fn (Error $error): string => $error->description(), $result->errors());

return new self(
'The host `'.$domain.'` is invalid : '.implode(', ', $info).' .',
$idnaInfo
$result
);
}

Expand All @@ -38,8 +37,8 @@ public static function dueToInvalidHost(string $domain): self
return new self('The host `'.$domain.'` is not a valid IDN host');
}

public function idnaInfo(): ?IdnaInfo
public function result(): ?Result
{
return $this->idnaInfo;
return $this->result;
}
}
2 changes: 1 addition & 1 deletion Idna/IdnaError.php → Idna/Error.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace League\Uri\Idna;

enum IdnaError: int
enum Error: int
{
case NONE = 0;
case EMPTY_LABEL = 1;
Expand Down
Loading

0 comments on commit 09be537

Please sign in to comment.