Skip to content

Commit

Permalink
Merge pull request #1076 from b1rdex/pure-builder
Browse files Browse the repository at this point in the history
Mark Builder methods as pure
  • Loading branch information
lcobucci authored Nov 6, 2024
2 parents aac4fd5 + 5012bc4 commit 848815d
Showing 1 changed file with 36 additions and 0 deletions.
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

0 comments on commit 848815d

Please sign in to comment.