Skip to content

Commit d37ba2a

Browse files
authored
Merge pull request #1141 from Slamdunk/no_discard
Add `#[\NoDiscard]` attribute
2 parents de1116f + 3136b45 commit d37ba2a

24 files changed

+110
-53
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"symbol-whitelist" : [
3+
"NoDiscard"
4+
],
5+
"php-core-extensions" : [
6+
"Core",
7+
"date",
8+
"json",
9+
"hash",
10+
"SPL",
11+
"standard"
12+
]
13+
}

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
/.gitattributes export-ignore
44
/.github export-ignore
55
/.gitignore export-ignore
6+
/.composer-require-checker.config.json export-ignore
67
/*.yml export-ignore
78
/CONTRIBUTING.md export-ignore
89
/*.dist export-ignore

.github/workflows/composer-json-lint.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ jobs:
4343
run: "composer-normalize --dry-run"
4444

4545
- name: "Check composer.json explicit dependencies"
46-
run: "composer-require-checker check"
46+
run: "composer-require-checker check --config-file=.composer-require-checker.config.json"
4747

4848
# - name: "Check composer.json unused dependencies"
4949
# run: "composer-unused"

src/Builder.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Lcobucci\JWT\Signer\InvalidKeyProvided;
1111
use Lcobucci\JWT\Signer\Key;
1212
use Lcobucci\JWT\Token\RegisteredClaimGiven;
13+
use NoDiscard;
1314

1415
/** @immutable */
1516
interface Builder
@@ -19,49 +20,57 @@ interface Builder
1920
*
2021
* @param non-empty-string ...$audiences
2122
*/
23+
#[NoDiscard]
2224
public function permittedFor(string ...$audiences): Builder;
2325

2426
/**
2527
* Configures the expiration time
2628
*/
29+
#[NoDiscard]
2730
public function expiresAt(DateTimeImmutable $expiration): Builder;
2831

2932
/**
3033
* Configures the token id
3134
*
3235
* @param non-empty-string $id
3336
*/
37+
#[NoDiscard]
3438
public function identifiedBy(string $id): Builder;
3539

3640
/**
3741
* Configures the time that the token was issued
3842
*/
43+
#[NoDiscard]
3944
public function issuedAt(DateTimeImmutable $issuedAt): Builder;
4045

4146
/**
4247
* Configures the issuer
4348
*
4449
* @param non-empty-string $issuer
4550
*/
51+
#[NoDiscard]
4652
public function issuedBy(string $issuer): Builder;
4753

4854
/**
4955
* Configures the time before which the token cannot be accepted
5056
*/
57+
#[NoDiscard]
5158
public function canOnlyBeUsedAfter(DateTimeImmutable $notBefore): Builder;
5259

5360
/**
5461
* Configures the subject
5562
*
5663
* @param non-empty-string $subject
5764
*/
65+
#[NoDiscard]
5866
public function relatedTo(string $subject): Builder;
5967

6068
/**
6169
* Configures a header item
6270
*
6371
* @param non-empty-string $name
6472
*/
73+
#[NoDiscard]
6574
public function withHeader(string $name, mixed $value): Builder;
6675

6776
/**
@@ -71,6 +80,7 @@ public function withHeader(string $name, mixed $value): Builder;
7180
*
7281
* @throws RegisteredClaimGiven When trying to set a registered claim.
7382
*/
83+
#[NoDiscard]
7484
public function withClaim(string $name, mixed $value): Builder;
7585

7686
/**
@@ -81,5 +91,6 @@ public function withClaim(string $name, mixed $value): Builder;
8191
* @throws InvalidKeyProvided When issue key is invalid/incompatible.
8292
* @throws ConversionFailed When signature could not be converted.
8393
*/
94+
#[NoDiscard]
8495
public function getToken(Signer $signer, Key $key): UnencryptedToken;
8596
}

src/ClaimsFormatter.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,15 @@
33

44
namespace Lcobucci\JWT;
55

6+
use NoDiscard;
7+
68
interface ClaimsFormatter
79
{
810
/**
911
* @param array<non-empty-string, mixed> $claims
1012
*
1113
* @return array<non-empty-string, mixed>
1214
*/
15+
#[NoDiscard]
1316
public function formatClaims(array $claims): array;
1417
}

src/Configuration.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Lcobucci\JWT\Encoding\JoseEncoder;
99
use Lcobucci\JWT\Signer\Key;
1010
use Lcobucci\JWT\Validation\Constraint;
11+
use NoDiscard;
1112

1213
/**
1314
* Configuration container for the JWT Builder and Parser
@@ -49,6 +50,7 @@ private function __construct(
4950
$this->validationConstraints = $validationConstraints;
5051
}
5152

53+
#[NoDiscard]
5254
public static function forAsymmetricSigner(
5355
Signer $signer,
5456
Key $signingKey,
@@ -68,6 +70,7 @@ public static function forAsymmetricSigner(
6870
);
6971
}
7072

73+
#[NoDiscard]
7174
public static function forSymmetricSigner(
7275
Signer $signer,
7376
Key $key,
@@ -87,6 +90,7 @@ public static function forSymmetricSigner(
8790
}
8891

8992
/** @param callable(ClaimsFormatter): Builder $builderFactory */
93+
#[NoDiscard]
9094
public function withBuilderFactory(callable $builderFactory): self
9195
{
9296
return new self(
@@ -112,6 +116,7 @@ public function parser(): Parser
112116
return $this->parser;
113117
}
114118

119+
#[NoDiscard]
115120
public function withParser(Parser $parser): self
116121
{
117122
return new self(
@@ -147,6 +152,7 @@ public function validator(): Validator
147152
return $this->validator;
148153
}
149154

155+
#[NoDiscard]
150156
public function withValidator(Validator $validator): self
151157
{
152158
return new self(
@@ -168,6 +174,7 @@ public function validationConstraints(): array
168174
return $this->validationConstraints;
169175
}
170176

177+
#[NoDiscard]
171178
public function withValidationConstraints(Constraint ...$validationConstraints): self
172179
{
173180
return new self(

src/Decoder.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
namespace Lcobucci\JWT;
55

66
use Lcobucci\JWT\Encoding\CannotDecodeContent;
7+
use NoDiscard;
78

89
interface Decoder
910
{
@@ -14,6 +15,7 @@ interface Decoder
1415
*
1516
* @throws CannotDecodeContent When something goes wrong while decoding.
1617
*/
18+
#[NoDiscard]
1719
public function jsonDecode(string $json): mixed;
1820

1921
/**
@@ -25,5 +27,6 @@ public function jsonDecode(string $json): mixed;
2527
*
2628
* @throws CannotDecodeContent When something goes wrong while decoding.
2729
*/
30+
#[NoDiscard]
2831
public function base64UrlDecode(string $data): string;
2932
}

src/Encoder.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
namespace Lcobucci\JWT;
55

66
use Lcobucci\JWT\Encoding\CannotEncodeContent;
7+
use NoDiscard;
78

89
interface Encoder
910
{
@@ -14,6 +15,7 @@ interface Encoder
1415
*
1516
* @throws CannotEncodeContent When something goes wrong while encoding.
1617
*/
18+
#[NoDiscard]
1719
public function jsonEncode(mixed $data): string;
1820

1921
/**
@@ -23,5 +25,6 @@ public function jsonEncode(mixed $data): string;
2325
*
2426
* @return ($data is non-empty-string ? non-empty-string : string)
2527
*/
28+
#[NoDiscard]
2629
public function base64UrlEncode(string $data): string;
2730
}

src/JwtFacade.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Lcobucci\JWT\Validation\SignedWith;
1313
use Lcobucci\JWT\Validation\ValidAt;
1414
use Lcobucci\JWT\Validation\Validator;
15+
use NoDiscard;
1516
use Psr\Clock\ClockInterface as Clock;
1617

1718
use function assert;
@@ -33,6 +34,7 @@ public function now(): DateTimeImmutable
3334
}
3435

3536
/** @param Closure(Builder, DateTimeImmutable):Builder $customiseBuilder */
37+
#[NoDiscard]
3638
public function issue(
3739
Signer $signer,
3840
Key $signingKey,
@@ -50,6 +52,7 @@ public function issue(
5052
}
5153

5254
/** @param non-empty-string $jwt */
55+
#[NoDiscard]
5356
public function parse(
5457
string $jwt,
5558
SignedWith $signedWith,

src/Parser.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Lcobucci\JWT\Encoding\CannotDecodeContent;
77
use Lcobucci\JWT\Token\InvalidTokenStructure;
88
use Lcobucci\JWT\Token\UnsupportedHeaderFound;
9+
use NoDiscard;
910

1011
interface Parser
1112
{
@@ -18,5 +19,6 @@ interface Parser
1819
* @throws InvalidTokenStructure When token string structure is invalid.
1920
* @throws UnsupportedHeaderFound When parsed token has an unsupported header.
2021
*/
22+
#[NoDiscard]
2123
public function parse(string $jwt): Token;
2224
}

0 commit comments

Comments
 (0)