Skip to content

Commit

Permalink
Rename class to make it clearer
Browse files Browse the repository at this point in the history
  • Loading branch information
TRowbotham committed Jun 6, 2024
1 parent 9e163bc commit c1b7ec7
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/ParserErrorType.php → src/APIParserErrorType.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Rowbot\URL;

enum ParserErrorType
enum APIParserErrorType
{
case NONE;

Expand Down
4 changes: 2 additions & 2 deletions src/APIParserResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ final class APIParserResult
{
public readonly ?URLRecord $url;

public readonly ParserErrorType $error;
public readonly APIParserErrorType $error;

public function __construct(?URLRecord $urlRecord, ParserErrorType $error)
public function __construct(?URLRecord $urlRecord, APIParserErrorType $error)
{
$this->url = $urlRecord;
$this->error = $error;
Expand Down
14 changes: 7 additions & 7 deletions src/URL.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public function __construct(string|Stringable $url, string|Stringable|null $base
// 1. Let parsedURL be the result of running the API URL parser on url with base, if given.
$parsedURL = self::parseURL($url, $base, $this->logger);

if ($parsedURL->error === ParserErrorType::NONE) {
if ($parsedURL->error === APIParserErrorType::NONE) {
// 3. Initialize this with parsedURL.
assert($parsedURL->url !== null);
self::initializeURL($this, $parsedURL->url);
Expand All @@ -83,8 +83,8 @@ public function __construct(string|Stringable $url, string|Stringable|null $base

// 2. If parsedURL is failure, then throw a TypeError.
$message = match ($parsedURL->error) {
ParserErrorType::BASE => 'Invalid base URL',
ParserErrorType::URL => 'Invalid URL'
APIParserErrorType::BASE => 'Invalid base URL',
APIParserErrorType::URL => 'Invalid URL'
};

throw new TypeError($message);
Expand All @@ -109,7 +109,7 @@ public static function canParse(string|Stringable $url, string|Stringable|null $
{
$parsedURL = self::parseURL($url, $base);

return $parsedURL->error === ParserErrorType::NONE;
return $parsedURL->error === APIParserErrorType::NONE;
}

public function toString(): string
Expand Down Expand Up @@ -161,7 +161,7 @@ private static function parseURL(

// 2.2. If parsedBase is failure, then return failure.
if ($parsedBase === false) {
return new APIParserResult(null, ParserErrorType::BASE);
return new APIParserResult(null, APIParserErrorType::BASE);
}
}

Expand All @@ -170,10 +170,10 @@ private static function parseURL(
$parsedURL = $parser->parse(Utf8String::fromUnsafe($stringURL), $parsedBase);

if ($parsedURL === false) {
return new APIParserResult(null, ParserErrorType::URL);
return new APIParserResult(null, APIParserErrorType::URL);
}

return new APIParserResult($parsedURL, ParserErrorType::NONE);
return new APIParserResult($parsedURL, APIParserErrorType::NONE);
}

/**
Expand Down

0 comments on commit c1b7ec7

Please sign in to comment.