From 0e782b55e5a62ac6a7e6dd9e662ba70f10ed597d Mon Sep 17 00:00:00 2001 From: Ignace Nyamagana Butera Date: Thu, 8 Dec 2016 16:27:59 +0100 Subject: [PATCH] Replace ParserException by Exception --- CHANGELOG.md | 14 ++++++++------ src/{ParserException.php => Exception.php} | 22 +++++++++++----------- src/HostValidation.php | 4 ++-- src/Parser.php | 20 ++++++++++---------- test/ParserTest.php | 4 ++-- 5 files changed, 33 insertions(+), 31 deletions(-) rename src/{ParserException.php => Exception.php} (72%) diff --git a/CHANGELOG.md b/CHANGELOG.md index 97a11f7..e63bfc7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,9 +6,10 @@ All Notable changes to `league-uri-parser` will be documented in this file ### Added -- `Parser::isValidHost` method -- `ParserException::createFromInvalidScheme` replaces `ParserException::createFromInvalidState` usage -- `ParserException::createFromInvalidPath` replaces `ParserException::createFromInvalidState` usage +- `League\Uri\Exception` replaces `League\Uri\ParserException` +- `League\Uri\Parser::isValidHost` method +- `League\Uri\Exception::createFromInvalidScheme` replaces `ParserException::createFromInvalidState` usage +- `League\Uri\Exception::createFromInvalidPath` replaces `ParserException::createFromInvalidState` usage ### Fixed @@ -20,14 +21,15 @@ All Notable changes to `league-uri-parser` will be documented in this file ### Removed -- `ParserException::createFromInvalidState` +- `League\Uri\ParserException` replaced by `Exception` +- `League\Uri\ParserException::createFromInvalidState` ## 0.2.0 - 2016-11-02 ### Added -- `ParserException` class which extends SPL `InvalidArgumentException` -- `HostValidation` trait to ease Host validation without the parser +- `League\Uri\ParserException` class which extends SPL `InvalidArgumentException` +- `League\Uri\HostValidation` trait to ease Host validation without the parser ### Fixed diff --git a/src/ParserException.php b/src/Exception.php similarity index 72% rename from src/ParserException.php rename to src/Exception.php index affae58..6a3e8e1 100644 --- a/src/ParserException.php +++ b/src/Exception.php @@ -22,18 +22,18 @@ * @author Ignace Nyamagana Butera * @since 0.2.0 */ -class ParserException extends InvalidArgumentException +class Exception extends InvalidArgumentException { /** * Returns a new Instance from an error in URI characters * * @param string $uri * - * @return self + * @return static */ public static function createFromInvalidCharacters($uri) { - return new self(sprintf('The submitted uri `%s` contains invalid characters', $uri)); + return new static(sprintf('The submitted uri `%s` contains invalid characters', $uri)); } /** @@ -41,11 +41,11 @@ public static function createFromInvalidCharacters($uri) * * @param string $uri * - * @return self + * @return static */ public static function createFromInvalidScheme($uri) { - return new self(sprintf('The submitted uri `%s` contains an invalid scheme', $uri)); + return new static(sprintf('The submitted uri `%s` contains an invalid scheme', $uri)); } /** @@ -53,11 +53,11 @@ public static function createFromInvalidScheme($uri) * * @param string $host * - * @return self + * @return static */ public static function createFromInvalidHost($host) { - return new self(sprintf('The submitted host `%s` is invalid', $host)); + return new static(sprintf('The submitted host `%s` is invalid', $host)); } /** @@ -65,11 +65,11 @@ public static function createFromInvalidHost($host) * * @param string $port * - * @return self + * @return static */ public static function createFromInvalidPort($port) { - return new self(sprintf('The submitted port `%s` is invalid', $port)); + return new static(sprintf('The submitted port `%s` is invalid', $port)); } /** @@ -77,10 +77,10 @@ public static function createFromInvalidPort($port) * * @param string $uri * - * @return self + * @return static */ public static function createFromInvalidPath($uri) { - return new self(sprintf('The submitted uri `%s` contains an invalid path', $uri)); + return new static(sprintf('The submitted uri `%s` contains an invalid path', $uri)); } } diff --git a/src/HostValidation.php b/src/HostValidation.php index 9dbb548..910e483 100644 --- a/src/HostValidation.php +++ b/src/HostValidation.php @@ -31,7 +31,7 @@ trait HostValidation * * @param string $host * - * @throws ParserException If the host component is invalid + * @throws Exception If the host component is invalid * * @return string */ @@ -41,7 +41,7 @@ protected function filterHost($host) return $host; } - throw ParserException::createFromInvalidHost($host); + throw Exception::createFromInvalidHost($host); } /** diff --git a/src/Parser.php b/src/Parser.php index e3588b8..242b40c 100644 --- a/src/Parser.php +++ b/src/Parser.php @@ -79,7 +79,7 @@ final class Parser * * @param string $uri * - * @throws ParserException if the URI contains invalid characters + * @throws Exception if the URI contains invalid characters * * @return array */ @@ -103,7 +103,7 @@ public function __invoke($uri) } if (strlen($uri) !== strcspn($uri, self::INVALID_URI_CHARS)) { - throw ParserException::createFromInvalidCharacters($uri); + throw Exception::createFromInvalidCharacters($uri); } //if the first characters is a known URI delimiter parsing @@ -162,7 +162,7 @@ public function __invoke($uri) * * @param string $uri * - * @throws ParserException If the port is invalid + * @throws Exception If the port is invalid * * @return array */ @@ -229,7 +229,7 @@ private function parseUriWithoutScheme($uri) } if (':' !== $hostname[$port_delimiter_index]) { - throw ParserException::createFromInvalidPort(substr($hostname, $port_delimiter_index)); + throw Exception::createFromInvalidPort(substr($hostname, $port_delimiter_index)); } $final['port'] = $this->filterPort(substr($hostname, $port_delimiter_index + 1)); @@ -263,7 +263,7 @@ private function parseUriWithoutScheme($uri) * * @param string $uri * - * @throws ParserException If the path component is invalid + * @throws Exception If the path component is invalid * * @return array */ @@ -272,7 +272,7 @@ private function parseUriWithoutSchemeAndAuthority($uri) //No scheme is present so we ensure that if presence of a path-noscheme //RFC3986 is respected if (false !== ($pos = strpos($uri, ':')) && false === strpos(substr($uri, 0, $pos), '/')) { - throw ParserException::createFromInvalidPath($uri); + throw Exception::createFromInvalidPath($uri); } //Parsing is done from the right upmost part to the left @@ -297,7 +297,7 @@ private function parseUriWithoutSchemeAndAuthority($uri) * * @param mixed $port the port number * - * @throws ParserException If the port number is invalid. + * @throws Exception If the port number is invalid. * * @return null|int */ @@ -316,7 +316,7 @@ private function filterPort($port) return $formatted_port; } - throw ParserException::createFromInvalidPort($port); + throw Exception::createFromInvalidPort($port); } /** @@ -345,7 +345,7 @@ private function filterPort($port) * * @param string $uri * - * @throws ParserException If the URI scheme component is empty + * @throws Exception If the URI scheme component is empty * * @return array */ @@ -358,7 +358,7 @@ private function parseUriWithColonCharacter($uri) //1.1 - a scheme can not be empty (ie a URI can not start with a colon) if ('' === $scheme) { - throw ParserException::createFromInvalidScheme($uri); + throw Exception::createFromInvalidScheme($uri); } //2 - depending on the scheme presence and validity we will differ the diff --git a/test/ParserTest.php b/test/ParserTest.php index 69be7ca..a608680 100644 --- a/test/ParserTest.php +++ b/test/ParserTest.php @@ -2,8 +2,8 @@ namespace LeagueTest\Uri; +use League\Uri\Exception; use League\Uri\Parser; -use League\Uri\ParserException; use PHPUnit\Framework\TestCase; /** @@ -590,7 +590,7 @@ public function testValidURI() */ public function testParseFailed($uri) { - $this->setExpectedException(ParserException::class); + $this->setExpectedException(Exception::class); $this->parser->__invoke($uri); }