Skip to content

Commit

Permalink
Apply initial rector suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
cicnavi committed Jan 14, 2025
1 parent 6fae8d1 commit fed07f3
Show file tree
Hide file tree
Showing 10 changed files with 48 additions and 42 deletions.
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@
},
"require-dev": {
"phpunit/phpunit": "^10",
"rector/rector": "^2.0",
"simplesamlphp/simplesamlphp-test-framework": "^1",
"squizlabs/php_codesniffer": "^3",
"vimeo/psalm": "^5",
"rector/rector": "^1 || ^2",
"simplesamlphp/simplesamlphp-test-framework": "^1"
"vimeo/psalm": "^5"
},
"config": {
"sort-packages": true,
Expand Down
17 changes: 17 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

declare(strict_types=1);

use Rector\Config\RectorConfig;

return RectorConfig::configure()
->withPaths([
__DIR__ . '/src',
__DIR__ . '/tests',
])
// uncomment to reach your current PHP version
->withPhpSets()
->withTypeCoverageLevel(0)
->withDeadCodeLevel(0)
->withCodeQualityLevel(0)
;
4 changes: 1 addition & 3 deletions src/Algorithms/SignatureAlgorithmBag.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@ public function getAll(): array
public function getAllInstances(): array
{
return array_map(
function (SignatureAlgorithmEnum $signatureAlgorithmEnum) {
return $signatureAlgorithmEnum->instance();
},
fn(SignatureAlgorithmEnum $signatureAlgorithmEnum) => $signatureAlgorithmEnum->instance(),
$this->getAll(),
);
}
Expand Down
4 changes: 1 addition & 3 deletions src/Decorators/HttpClientDecorator.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,9 @@
class HttpClientDecorator
{
public const DEFAULT_HTTP_CLIENT_CONFIG = [RequestOptions::ALLOW_REDIRECTS => true,];
public readonly Client $client;

public function __construct(?Client $client = null)
public function __construct(public readonly Client $client = new Client(self::DEFAULT_HTTP_CLIENT_CONFIG))
{
$this->client = $client ?? new Client(self::DEFAULT_HTTP_CLIENT_CONFIG);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Factories/HttpClientDecoratorFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ class HttpClientDecoratorFactory
{
public function build(?Client $client = null): HttpClientDecorator
{
return new HttpClientDecorator($client);
return is_null($client) ? new HttpClientDecorator() : new HttpClientDecorator($client);
}
}
7 changes: 4 additions & 3 deletions src/Federation/TrustChainBag.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ public function add(TrustChain $trustChain, TrustChain ...$trustChains): void
$this->trustChains = array_merge($this->trustChains, $trustChains);

// Order the chains from shortest to longest one.
usort($this->trustChains, function (TrustChain $a, TrustChain $b) {
return $a->getResolvedLength() <=> $b->getResolvedLength();
});
usort(
$this->trustChains,
fn(TrustChain $a, TrustChain $b) => $a->getResolvedLength() <=> $b->getResolvedLength(),
);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Jws/ParsedJws.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ protected function validateByCallbacks(callable ...$calls): void
try {
call_user_func($call);
} catch (Throwable $exception) {
$errors[] = sprintf('%s: %s', get_class($exception), $exception->getMessage());
$errors[] = sprintf('%s: %s', $exception::class, $exception->getMessage());
}
}

Expand Down
4 changes: 1 addition & 3 deletions src/Serializers/JwsSerializerBag.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ public function getAll(): array
public function getAllInstances(): array
{
return array_map(
function (JwsSerializerEnum $jwsSerializerEnum) {
return $jwsSerializerEnum->instance();
},
fn(JwsSerializerEnum $jwsSerializerEnum) => $jwsSerializerEnum->instance(),
$this->getAll(),
);
}
Expand Down
42 changes: 18 additions & 24 deletions tests/src/Federation/TrustChainResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,10 @@ public function testCanGetConfigurationChains(): void
$this->entityStatementFetcherMock
->expects($this->exactly(3))
->method('fromCacheOrWellKnownEndpoint')
->willReturnCallback(function (string $entityId) {
return $this->configChainSample[$entityId] ?? throw new \Exception('No entity.');
});
->willReturnCallback(
fn(string $entityId) =>
$this->configChainSample[$entityId] ?? throw new \Exception('No entity.')
);

$this->leafEntityConfigurationMock
->expects($this->once())
Expand Down Expand Up @@ -136,9 +137,8 @@ public function testCanLimitMaximumConfigurationChainDepth(): void
$this->entityStatementFetcherMock
->expects($this->exactly(2))
->method('fromCacheOrWellKnownEndpoint')
->willReturnCallback(function (string $entityId) {
return $this->configChainSample[$entityId] ?? throw new \Exception('No entity.');
});
->willReturnCallback(fn(string $entityId) =>
$this->configChainSample[$entityId] ?? throw new \Exception('No entity.'));

$this->leafEntityConfigurationMock
->method('getAuthorityHints')
Expand All @@ -162,9 +162,8 @@ public function testCanDetectLoopInConfigurationChains(): void
{
$this->entityStatementFetcherMock
->method('fromCacheOrWellKnownEndpoint')
->willReturnCallback(function (string $entityId) {
return $this->configChainSample[$entityId] ?? throw new \Exception('No entity.');
});
->willReturnCallback(fn(string $entityId) =>
$this->configChainSample[$entityId] ?? throw new \Exception('No entity.'));

$this->leafEntityConfigurationMock
->method('getAuthorityHints')
Expand Down Expand Up @@ -192,9 +191,8 @@ public function testCanBailOnMaxAuthorityHintsRule(): void

$this->entityStatementFetcherMock
->method('fromCacheOrWellKnownEndpoint')
->willReturnCallback(function (string $entityId) {
return $this->configChainSample[$entityId] ?? throw new \Exception('No entity.');
});
->willReturnCallback(fn(string $entityId) =>
$this->configChainSample[$entityId] ?? throw new \Exception('No entity.'));

$this->loggerMock
->expects($this->atLeastOnce())
Expand All @@ -212,9 +210,8 @@ public function testCanResolveTrustChain(): void
{
$this->entityStatementFetcherMock
->method('fromCacheOrWellKnownEndpoint')
->willReturnCallback(function (string $entityId) {
return $this->configChainSample[$entityId] ?? throw new \Exception('No entity.');
});
->willReturnCallback(fn(string $entityId) =>
$this->configChainSample[$entityId] ?? throw new \Exception('No entity.'));

$this->leafEntityConfigurationMock
->expects($this->once())
Expand All @@ -238,9 +235,8 @@ public function testCanResolveMultipleTrustChains(): void
{
$this->entityStatementFetcherMock
->method('fromCacheOrWellKnownEndpoint')
->willReturnCallback(function (string $entityId) {
return $this->configChainSample[$entityId] ?? throw new \Exception('No entity.');
});
->willReturnCallback(fn(string $entityId) =>
$this->configChainSample[$entityId] ?? throw new \Exception('No entity.'));

$this->leafEntityConfigurationMock
->expects($this->once())
Expand Down Expand Up @@ -299,9 +295,8 @@ public function testCanWarnOnTrustChainResolutionSubordinateStatementFetchError(
{
$this->entityStatementFetcherMock
->method('fromCacheOrWellKnownEndpoint')
->willReturnCallback(function (string $entityId) {
return $this->configChainSample[$entityId] ?? throw new \Exception('No entity.');
});
->willReturnCallback(fn(string $entityId) =>
$this->configChainSample[$entityId] ?? throw new \Exception('No entity.'));

$this->entityStatementFetcherMock
->method('fromCacheOrFetchEndpoint')
Expand Down Expand Up @@ -329,9 +324,8 @@ public function testTrustChainResolveThrowsOnTrustChainBagFactoryError(): void
{
$this->entityStatementFetcherMock
->method('fromCacheOrWellKnownEndpoint')
->willReturnCallback(function (string $entityId) {
return $this->configChainSample[$entityId] ?? throw new \Exception('No entity.');
});
->willReturnCallback(fn(string $entityId) =>
$this->configChainSample[$entityId] ?? throw new \Exception('No entity.'));

$this->leafEntityConfigurationMock
->expects($this->once())
Expand Down
2 changes: 1 addition & 1 deletion tests/src/Jws/ParsedJwsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ protected function validate(): void
$this->validateByCallbacks($this->simulateError(...));
}

protected function simulateError(): void
protected function simulateError(): never
{
throw new \Exception('Error');
}
Expand Down

0 comments on commit fed07f3

Please sign in to comment.