Currently the Token Builder is confusing:
|
public function withClaim(string $name, mixed $value): BuilderInterface |
|
{ |
|
if (in_array($name, RegisteredClaims::ALL, true)) { |
|
throw RegisteredClaimGiven::forClaim($name); |
|
} |
|
|
|
return $this->setClaim($name, $value); |
|
} |
|
|
|
/** @param non-empty-string $name */ |
|
private function setClaim(string $name, mixed $value): BuilderInterface |
|
{ |
|
$this->claims[$name] = $value; |
|
|
|
return $this; |
|
} |
The name of the method resemble an immutable object, but under the hood it's a fluent interface.
All my colleagues get confused too by reading a method like:
class User
{
public function fillJwtToken(JwtBuilder $jwtBuilder): void
{
$jwtBuilder->withClaim('user-id', $this->id);
}
}
Did the developer forget to return the new object?
Or its more a setClaim rather than a withClaim?
Can we take a direction and forget the other one?
Currently the Token Builder is confusing:
jwt/src/Token/Builder.php
Lines 76 to 91 in 602856e
The name of the method resemble an immutable object, but under the hood it's a fluent interface.
All my colleagues get confused too by reading a method like:
Did the developer forget to return the new object?
Or its more a
setClaimrather than awithClaim?Can we take a direction and forget the other one?