From c70d8fe2aec1ef53667275dcb5a175a476481322 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Sat, 29 Jan 2022 10:09:37 +0100 Subject: [PATCH] Enhancement: Use raw string value internally --- src/ReferenceToken.php | 44 +++++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/src/ReferenceToken.php b/src/ReferenceToken.php index 82c2aec8..b3541152 100644 --- a/src/ReferenceToken.php +++ b/src/ReferenceToken.php @@ -20,11 +20,11 @@ */ final class ReferenceToken { - private string $jsonStringValue; + private string $value; - private function __construct(string $jsonStringValue) + private function __construct(string $value) { - $this->jsonStringValue = $jsonStringValue; + $this->value = $value; } /** @@ -50,46 +50,46 @@ public static function fromJsonString(string $value): self throw Exception\InvalidReferenceToken::fromJsonString($value); } - return new self($value); - } - - public static function fromString(string $value): self - { - return self::fromJsonString(\str_replace( + return new self(\str_replace( [ - '~', - '/', + '~1', + '~0', ], [ - '~0', - '~1', + '/', + '~', ], $value, )); } - public function toJsonString(): string + public static function fromString(string $value): self { - return $this->jsonStringValue; + return new self($value); } - public function toString(): string + public function toJsonString(): string { return \str_replace( [ - '~1', - '~0', + '~', + '/', ], [ - '/', - '~', + '~0', + '~1', ], - $this->jsonStringValue, + $this->value, ); } + public function toString(): string + { + return $this->value; + } + public function equals(self $other): bool { - return $this->jsonStringValue === $other->jsonStringValue; + return $this->value === $other->value; } }