Skip to content

Commit

Permalink
readonly classes that return a new instance can't never be pure
Browse files Browse the repository at this point in the history
  • Loading branch information
Slamdunk committed Jan 29, 2025
1 parent 67c26c7 commit 145a0ef
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 77 deletions.
20 changes: 10 additions & 10 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,16 @@
"psr/clock": "^1.0"
},
"require-dev": {
"infection/infection": "^0.29",
"lcobucci/clock": "^3.2",
"lcobucci/coding-standard": "^11.0",
"phpbench/phpbench": "^1.2",
"phpstan/extension-installer": "^1.2",
"phpstan/phpstan": "^2.0.0",
"phpstan/phpstan-deprecation-rules": "^2.0.0",
"phpstan/phpstan-phpunit": "^2.0.0",
"phpstan/phpstan-strict-rules": "^2.0.0",
"phpunit/phpunit": "^11.1"
"infection/infection": "^0.29.10",
"lcobucci/clock": "^3.3.1",
"lcobucci/coding-standard": "^11.1",
"phpbench/phpbench": "^1.4",
"phpstan/extension-installer": "^1.4.3",
"phpstan/phpstan": "^2.1.2",
"phpstan/phpstan-deprecation-rules": "^2.0.1",
"phpstan/phpstan-phpunit": "^2.0.4",
"phpstan/phpstan-strict-rules": "^2.0.3",
"phpunit/phpunit": "^11.5.4"
},
"suggest": {
"lcobucci/clock": ">= 3.2"
Expand Down
67 changes: 38 additions & 29 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/Signer/Key/InMemory.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public static function plainText(
#[SensitiveParameter]
string $passphrase = '',
): self {
self::guardAgainstEmptyKey($contents);
self::guardAgainstEmptyKey($contents); // @phpstan-ignore staticMethod.alreadyNarrowedType

return new self($contents, $passphrase);
}
Expand All @@ -48,7 +48,7 @@ public static function base64Encoded(
SodiumBase64Polyfill::SODIUM_BASE64_VARIANT_ORIGINAL,
);

self::guardAgainstEmptyKey($decoded);
self::guardAgainstEmptyKey($decoded); // @phpstan-ignore staticMethod.alreadyNarrowedType

return new self($decoded, $passphrase);
}
Expand Down
36 changes: 0 additions & 36 deletions src/Token/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,6 @@ public static function new(Encoder $encoder, ClaimsFormatter $claimFormatter): s
return new self($encoder, $claimFormatter);
}

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

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

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

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

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

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

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

/**
* @inheritDoc
* @pure
*/
public function withHeader(string $name, mixed $value): BuilderInterface
{
$headers = $this->headers;
Expand All @@ -119,10 +87,6 @@ public function withHeader(string $name, mixed $value): BuilderInterface
);
}

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

0 comments on commit 145a0ef

Please sign in to comment.