Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mark Builder methods as pure #1076

Merged
merged 2 commits into from
Nov 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions src/Token/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ public function __construct(private readonly Encoder $encoder, private readonly
{
}

/**
* @inheritDoc
* @pure
*/
public function permittedFor(string ...$audiences): BuilderInterface
{
$configured = $this->claims[RegisteredClaims::AUDIENCE] ?? [];
Expand All @@ -37,36 +41,64 @@ public function permittedFor(string ...$audiences): BuilderInterface
return $this->setClaim(RegisteredClaims::AUDIENCE, array_merge($configured, $toAppend));
}

/**
* @inheritDoc
* @pure
*/
public function expiresAt(DateTimeImmutable $expiration): BuilderInterface
{
return $this->setClaim(RegisteredClaims::EXPIRATION_TIME, $expiration);
}

/**
* @inheritDoc
* @pure
*/
public function identifiedBy(string $id): BuilderInterface
{
return $this->setClaim(RegisteredClaims::ID, $id);
}

/**
* @inheritDoc
* @pure
*/
public function issuedAt(DateTimeImmutable $issuedAt): BuilderInterface
{
return $this->setClaim(RegisteredClaims::ISSUED_AT, $issuedAt);
}

/**
* @inheritDoc
* @pure
*/
public function issuedBy(string $issuer): BuilderInterface
{
return $this->setClaim(RegisteredClaims::ISSUER, $issuer);
}

/**
* @inheritDoc
* @pure
*/
public function canOnlyBeUsedAfter(DateTimeImmutable $notBefore): BuilderInterface
{
return $this->setClaim(RegisteredClaims::NOT_BEFORE, $notBefore);
}

/**
* @inheritDoc
* @pure
*/
public function relatedTo(string $subject): BuilderInterface
{
return $this->setClaim(RegisteredClaims::SUBJECT, $subject);
}

/**
* @inheritDoc
* @pure
*/
public function withHeader(string $name, mixed $value): BuilderInterface
{
$new = clone $this;
Expand All @@ -75,6 +107,10 @@ public function withHeader(string $name, mixed $value): BuilderInterface
return $new;
}

/**
* @inheritDoc
* @pure
*/
public function withClaim(string $name, mixed $value): BuilderInterface
{
if (in_array($name, RegisteredClaims::ALL, true)) {
Expand Down