Skip to content

Commit

Permalink
Merge pull request #11 from ergebnis/feature/string
Browse files Browse the repository at this point in the history
Enhancement: Use raw `string` value internally
  • Loading branch information
localheinz authored Jan 29, 2022
2 parents e13def2 + c70d8fe commit 2e205ed
Showing 1 changed file with 22 additions and 22 deletions.
44 changes: 22 additions & 22 deletions src/ReferenceToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand All @@ -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;
}
}

0 comments on commit 2e205ed

Please sign in to comment.