Skip to content

Commit 047f3e8

Browse files
committed
Lint
1 parent 31b85ed commit 047f3e8

File tree

73 files changed

+489
-627
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+489
-627
lines changed

src/Did/DidKeyJwkResolver.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,11 @@ public function createJwkFromRawJson(string $rawJsonBytes): array
416416

417417
return $jwk;
418418
} catch (\JsonException $jsonException) {
419-
throw new DidException('Failed to parse JWK JSON: ' . $jsonException->getMessage());
419+
throw new DidException(
420+
'Failed to parse JWK JSON: ' . $jsonException->getMessage(),
421+
$jsonException->getCode(),
422+
$jsonException,
423+
);
420424
}
421425
}
422426
}

src/Federation/TrustChainResolver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ public function for(string $entityId, array $validTrustAnchorIds): TrustChainBag
298298
} catch (Throwable $throwable) {
299299
$message = 'Error building Trust Chain Bag: ' . $throwable->getMessage();
300300
$this->logger?->error($message, $debugStartInfo);
301-
throw new TrustChainException($message);
301+
throw new TrustChainException($message, $throwable->getCode(), $throwable);
302302
}
303303

304304
return $trustChainBag;

src/Federation/TrustMarkValidator.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -708,7 +708,7 @@ public function validateTrustChainForTrustMarkIssuer(
708708
);
709709

710710
$this->logger?->error($error);
711-
throw new TrustMarkException($error);
711+
throw new TrustMarkException($error, $throwable->getCode(), $throwable);
712712
}
713713

714714
$this->logger?->debug(
@@ -747,7 +747,7 @@ public function validateTrustMarkSignature(
747747
$error,
748748
['trustMarkIssuerJwks' => $trustMarkIssuerEntityConfiguration->getJwks()],
749749
);
750-
throw new TrustMarkException($error);
750+
throw new TrustMarkException($error, $throwable->getCode(), $throwable);
751751
}
752752

753753
$this->logger?->debug('Trust Mark signature validated.');
@@ -838,7 +838,7 @@ public function validateTrustMarkDelegation(
838838
$error,
839839
['trustMarkOwnersJwks' => $trustMarkOwnersClaimValue->getJwks()->getValue()],
840840
);
841-
throw new TrustMarkException($error);
841+
throw new TrustMarkException($error, $throwable->getCode(), $throwable);
842842
}
843843

844844
$this->logger?->debug('Trust Mark Delegation signature validated.');
@@ -966,7 +966,7 @@ public function validateUsingTrustMarkStatusEndpoint(
966966
'error' => $throwable->getMessage(),
967967
]);
968968

969-
throw new TrustMarkException($message);
969+
throw new TrustMarkException($message, $throwable->getCode(), $throwable);
970970
}
971971

972972
$this->logger?->debug(

src/Jwks/JwksFetcher.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ protected function decodeJwksJson(string $jwksJson): array
4747
$message,
4848
['jwksJson' => $jwksJson],
4949
);
50-
throw new JwksException($message);
50+
throw new JwksException($message, $jsonException->getCode(), $jsonException);
5151
}
5252

5353
return $this->claimFactory->buildJwks($jwks)->getValue();

src/VerifiableCredentials/VcDataModel/JwtVcJson.php

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,11 @@ public function getVcIssuanceDate(): DateTimeImmutable
261261
try {
262262
return $this->vcIssuanceDate = $this->helpers->dateTime()->fromTimestamp($nbf);
263263
} catch (Exception $e) {
264-
throw new VcDataModelException('Error parsing Not Before claim: ' . $e->getMessage());
264+
throw new VcDataModelException(
265+
'Error parsing Not Before claim: ' . $e->getMessage(),
266+
$e->getCode(),
267+
$e,
268+
);
265269
}
266270
}
267271

@@ -274,7 +278,11 @@ public function getVcIssuanceDate(): DateTimeImmutable
274278
try {
275279
return $this->vcIssuanceDate = $this->helpers->dateTime()->fromXsDateTime($issuanceDate);
276280
} catch (Exception $exception) {
277-
throw new VcDataModelException('Error parsing VC Issuance Date claim: ' . $exception->getMessage());
281+
throw new VcDataModelException(
282+
'Error parsing VC Issuance Date claim: ' . $exception->getMessage(),
283+
$exception->getCode(),
284+
$exception,
285+
);
278286
}
279287
}
280288

@@ -332,7 +340,11 @@ public function getVcExpirationDate(): ?DateTimeImmutable
332340
try {
333341
return $this->vcExpirationDate = $this->helpers->dateTime()->fromTimestamp($exp);
334342
} catch (Exception $e) {
335-
throw new VcDataModelException('Error parsing Expiration Time date claim: ' . $e->getMessage());
343+
throw new VcDataModelException(
344+
'Error parsing Expiration Time date claim: ' . $e->getMessage(),
345+
$e->getCode(),
346+
$e,
347+
);
336348
}
337349
}
338350

@@ -348,7 +360,11 @@ public function getVcExpirationDate(): ?DateTimeImmutable
348360
try {
349361
return $this->vcExpirationDate = $this->helpers->dateTime()->fromXsDateTime($expirationDate);
350362
} catch (Exception $exception) {
351-
throw new VcDataModelException('Error parsing VC Expiration Date claim: ' . $exception->getMessage());
363+
throw new VcDataModelException(
364+
'Error parsing VC Expiration Date claim: ' . $exception->getMessage(),
365+
$exception->getCode(),
366+
$exception,
367+
);
352368
}
353369
}
354370

tests/src/Core/ClientAssertionTest.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,19 @@ final class ClientAssertionTest extends TestCase
2626
{
2727
protected MockObject $jwsDecoratorMock;
2828

29-
protected MockObject $jwsVerifierDecoratorMock;
29+
protected \PHPUnit\Framework\MockObject\Stub $jwsVerifierDecoratorMock;
3030

31-
protected MockObject $jwksDecoratorFactoryMock;
31+
protected \PHPUnit\Framework\MockObject\Stub $jwksDecoratorFactoryMock;
3232

33-
protected MockObject $jwsSerializerManagerDecoratorMock;
33+
protected \PHPUnit\Framework\MockObject\Stub $jwsSerializerManagerDecoratorMock;
3434

35-
protected MockObject $dateIntervalDecoratorMock;
35+
protected \PHPUnit\Framework\MockObject\Stub $dateIntervalDecoratorMock;
3636

3737
protected MockObject $helpersMock;
3838

3939
protected MockObject $jsonHelperMock;
4040

41-
protected MockObject $claimFactoryMock;
41+
protected \PHPUnit\Framework\MockObject\Stub $claimFactoryMock;
4242

4343
protected array $expiredPayload = [
4444
'iat' => 1730820687,
@@ -66,10 +66,10 @@ protected function setUp(): void
6666
$this->jwsDecoratorMock = $this->createMock(JwsDecorator::class);
6767
$this->jwsDecoratorMock->method('jws')->willReturn($jwsMock);
6868

69-
$this->jwsVerifierDecoratorMock = $this->createMock(JwsVerifierDecorator::class);
70-
$this->jwksDecoratorFactoryMock = $this->createMock(JwksDecoratorFactory::class);
71-
$this->jwsSerializerManagerDecoratorMock = $this->createMock(JwsSerializerManagerDecorator::class);
72-
$this->dateIntervalDecoratorMock = $this->createMock(DateIntervalDecorator::class);
69+
$this->jwsVerifierDecoratorMock = $this->createStub(JwsVerifierDecorator::class);
70+
$this->jwksDecoratorFactoryMock = $this->createStub(JwksDecoratorFactory::class);
71+
$this->jwsSerializerManagerDecoratorMock = $this->createStub(JwsSerializerManagerDecorator::class);
72+
$this->dateIntervalDecoratorMock = $this->createStub(DateIntervalDecorator::class);
7373

7474
$this->helpersMock = $this->createMock(Helpers::class);
7575
$this->jsonHelperMock = $this->createMock(Helpers\Json::class);
@@ -80,7 +80,7 @@ protected function setUp(): void
8080
$typeHelperMock->method('ensureNonEmptyString')->willReturnArgument(0);
8181
$typeHelperMock->method('ensureInt')->willReturnArgument(0);
8282

83-
$this->claimFactoryMock = $this->createMock(ClaimFactory::class);
83+
$this->claimFactoryMock = $this->createStub(ClaimFactory::class);
8484

8585
$this->validPayload = $this->expiredPayload;
8686
$this->validPayload['exp'] = time() + 3600;

tests/src/Core/Factories/ClientAssertionFactoryTest.php

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
use SimpleSAML\OpenID\Decorators\DateIntervalDecorator;
1616
use SimpleSAML\OpenID\Factories\ClaimFactory;
1717
use SimpleSAML\OpenID\Helpers;
18-
use SimpleSAML\OpenID\Jwk\JwkDecorator;
1918
use SimpleSAML\OpenID\Jwks\Factories\JwksDecoratorFactory;
2019
use SimpleSAML\OpenID\Jws\Factories\ParsedJwsFactory;
2120
use SimpleSAML\OpenID\Jws\JwsDecorator;
@@ -32,19 +31,19 @@ final class ClientAssertionFactoryTest extends TestCase
3231
{
3332
protected MockObject $jwsDecoratorBuilderMock;
3433

35-
protected MockObject $jwsVerifierDecoratorMock;
34+
protected \PHPUnit\Framework\MockObject\Stub $jwsVerifierDecoratorMock;
3635

37-
protected MockObject $jwksDecoratorFactoryMock;
36+
protected \PHPUnit\Framework\MockObject\Stub $jwksDecoratorFactoryMock;
3837

39-
protected MockObject $jwsSerializerManagerDecoratorMock;
38+
protected \PHPUnit\Framework\MockObject\Stub $jwsSerializerManagerDecoratorMock;
4039

41-
protected MockObject $dateIntervalDecoratorMock;
40+
protected \PHPUnit\Framework\MockObject\Stub $dateIntervalDecoratorMock;
4241

4342
protected MockObject $helpersMock;
4443

4544
protected MockObject $jsonHelperMock;
4645

47-
protected MockObject $claimFactoryMock;
46+
protected \PHPUnit\Framework\MockObject\Stub $claimFactoryMock;
4847

4948
protected array $expiredPayload = [
5049
'iat' => 1730820687,
@@ -62,8 +61,6 @@ final class ClientAssertionFactoryTest extends TestCase
6261

6362
protected array $validPayload;
6463

65-
protected MockObject $jwkDecoratorMock;
66-
6764

6865
protected function setUp(): void
6966
{
@@ -78,10 +75,10 @@ protected function setUp(): void
7875
$this->jwsDecoratorBuilderMock->method('fromToken')->willReturn($jwsDecoratorMock);
7976
$this->jwsDecoratorBuilderMock->method('fromData')->willReturn($jwsDecoratorMock);
8077

81-
$this->jwsVerifierDecoratorMock = $this->createMock(JwsVerifierDecorator::class);
82-
$this->jwksDecoratorFactoryMock = $this->createMock(JwksDecoratorFactory::class);
83-
$this->jwsSerializerManagerDecoratorMock = $this->createMock(JwsSerializerManagerDecorator::class);
84-
$this->dateIntervalDecoratorMock = $this->createMock(DateIntervalDecorator::class);
78+
$this->jwsVerifierDecoratorMock = $this->createStub(JwsVerifierDecorator::class);
79+
$this->jwksDecoratorFactoryMock = $this->createStub(JwksDecoratorFactory::class);
80+
$this->jwsSerializerManagerDecoratorMock = $this->createStub(JwsSerializerManagerDecorator::class);
81+
$this->dateIntervalDecoratorMock = $this->createStub(DateIntervalDecorator::class);
8582

8683
$this->helpersMock = $this->createMock(Helpers::class);
8784
$this->jsonHelperMock = $this->createMock(Helpers\Json::class);
@@ -92,12 +89,10 @@ protected function setUp(): void
9289
$typeHelperMock->method('ensureNonEmptyString')->willReturnArgument(0);
9390
$typeHelperMock->method('ensureInt')->willReturnArgument(0);
9491

95-
$this->claimFactoryMock = $this->createMock(ClaimFactory::class);
92+
$this->claimFactoryMock = $this->createStub(ClaimFactory::class);
9693

9794
$this->validPayload = $this->expiredPayload;
9895
$this->validPayload['exp'] = time() + 3600;
99-
100-
$this->jwkDecoratorMock = $this->createMock(JwkDecorator::class);
10196
}
10297

10398

@@ -154,7 +149,7 @@ public function testCanBuildFromData(): void
154149
$this->assertInstanceOf(
155150
ClientAssertion::class,
156151
$this->sut()->fromData(
157-
$this->jwkDecoratorMock,
152+
$this->createStub(\SimpleSAML\OpenID\Jwk\JwkDecorator::class),
158153
SignatureAlgorithmEnum::ES256,
159154
$this->validPayload,
160155
[],

tests/src/Core/Factories/IdTokenFactoryTest.php

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
use SimpleSAML\OpenID\Decorators\DateIntervalDecorator;
1616
use SimpleSAML\OpenID\Factories\ClaimFactory;
1717
use SimpleSAML\OpenID\Helpers;
18-
use SimpleSAML\OpenID\Jwk\JwkDecorator;
1918
use SimpleSAML\OpenID\Jwks\Factories\JwksDecoratorFactory;
2019
use SimpleSAML\OpenID\Jws\Factories\ParsedJwsFactory;
2120
use SimpleSAML\OpenID\Jws\JwsDecorator;
@@ -32,19 +31,19 @@ final class IdTokenFactoryTest extends TestCase
3231
{
3332
protected MockObject $jwsDecoratorBuilderMock;
3433

35-
protected MockObject $jwsVerifierDecoratorMock;
34+
protected \PHPUnit\Framework\MockObject\Stub $jwsVerifierDecoratorMock;
3635

37-
protected MockObject $jwksDecoratorFactoryMock;
36+
protected \PHPUnit\Framework\MockObject\Stub $jwksDecoratorFactoryMock;
3837

39-
protected MockObject $jwsSerializerManagerDecoratorMock;
38+
protected \PHPUnit\Framework\MockObject\Stub $jwsSerializerManagerDecoratorMock;
4039

41-
protected MockObject $dateIntervalDecoratorMock;
40+
protected \PHPUnit\Framework\MockObject\Stub $dateIntervalDecoratorMock;
4241

4342
protected MockObject $helpersMock;
4443

4544
protected MockObject $jsonHelperMock;
4645

47-
protected MockObject $claimFactoryMock;
46+
protected \PHPUnit\Framework\MockObject\Stub $claimFactoryMock;
4847

4948
protected array $expiredPayload = [
5049
'iss' => 'https://server.example.com',
@@ -60,8 +59,6 @@ final class IdTokenFactoryTest extends TestCase
6059

6160
protected array $validPayload;
6261

63-
protected MockObject $jwkDecoratorMock;
64-
6562

6663
protected function setUp(): void
6764
{
@@ -76,10 +73,10 @@ protected function setUp(): void
7673
$this->jwsDecoratorBuilderMock->method('fromToken')->willReturn($jwsDecoratorMock);
7774
$this->jwsDecoratorBuilderMock->method('fromData')->willReturn($jwsDecoratorMock);
7875

79-
$this->jwsVerifierDecoratorMock = $this->createMock(JwsVerifierDecorator::class);
80-
$this->jwksDecoratorFactoryMock = $this->createMock(JwksDecoratorFactory::class);
81-
$this->jwsSerializerManagerDecoratorMock = $this->createMock(JwsSerializerManagerDecorator::class);
82-
$this->dateIntervalDecoratorMock = $this->createMock(DateIntervalDecorator::class);
76+
$this->jwsVerifierDecoratorMock = $this->createStub(JwsVerifierDecorator::class);
77+
$this->jwksDecoratorFactoryMock = $this->createStub(JwksDecoratorFactory::class);
78+
$this->jwsSerializerManagerDecoratorMock = $this->createStub(JwsSerializerManagerDecorator::class);
79+
$this->dateIntervalDecoratorMock = $this->createStub(DateIntervalDecorator::class);
8380

8481
$this->helpersMock = $this->createMock(Helpers::class);
8582
$this->jsonHelperMock = $this->createMock(Helpers\Json::class);
@@ -94,12 +91,10 @@ protected function setUp(): void
9491
$typeHelperMock->method('ensureArrayWithKeysAndValuesAsNonEmptyStrings')
9592
->willReturnArgument(0);
9693

97-
$this->claimFactoryMock = $this->createMock(ClaimFactory::class);
94+
$this->claimFactoryMock = $this->createStub(ClaimFactory::class);
9895

9996
$this->validPayload = $this->expiredPayload;
10097
$this->validPayload['exp'] = time() + 3600;
101-
102-
$this->jwkDecoratorMock = $this->createMock(JwkDecorator::class);
10398
}
10499

105100

@@ -156,7 +151,7 @@ public function testCanBuildFromData(): void
156151
$this->assertInstanceOf(
157152
IdToken::class,
158153
$this->sut()->fromData(
159-
$this->jwkDecoratorMock,
154+
$this->createStub(\SimpleSAML\OpenID\Jwk\JwkDecorator::class),
160155
SignatureAlgorithmEnum::ES256,
161156
$this->validPayload,
162157
[],

0 commit comments

Comments
 (0)