Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions .github/workflows/rector-cs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Rector + PHP CS Fixer

on:
pull_request_target:
paths:
- 'config/**'
- 'src/**'
- 'tests/**'
- '.github/workflows/rector-cs.yml'
- 'composer.json'
- 'rector.php'
- '.php-cs-fixer.dist.php'

permissions:
contents: read

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
rector:
uses: yiisoft/actions/.github/workflows/rector-cs.yml@master
secrets:
token: ${{ secrets.YIISOFT_GITHUB_TOKEN }}
with:
repository: ${{ github.event.pull_request.head.repo.full_name }}
php: '8.1'
24 changes: 0 additions & 24 deletions .github/workflows/rector.yml

This file was deleted.

4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,7 @@ composer.phar
/phpunit.phar
/phpunit.xml
/.phpunit.cache

# PHP CS Fixer
/.php-cs-fixer.cache
/.php-cs-fixer.php
35 changes: 35 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

declare(strict_types=1);

use PhpCsFixer\Config;
use PhpCsFixer\Finder;
use PhpCsFixer\Runner\Parallel\ParallelConfigFactory;

$finder = (new Finder())->in([
__DIR__ . '/config',
__DIR__ . '/src',
__DIR__ . '/tests',
]);

return (new Config())
->setRiskyAllowed(true)
->setParallelConfig(ParallelConfigFactory::detect())
->setRules([
'@PER-CS3.0' => true,
'no_unused_imports' => true,
'ordered_class_elements' => true,
'class_attributes_separation' => ['elements' => ['method' => 'one']],
'declare_strict_types' => true,
'native_function_invocation' => true,
'native_constant_invocation' => true,
'fully_qualified_strict_types' => [
'import_symbols' => true
],
'global_namespace_import' => [
'import_classes' => true,
'import_constants' => true,
'import_functions' => true,
],
])
->setFinder($finder);
85 changes: 0 additions & 85 deletions .styleci.yml

This file was deleted.

1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

- Chg #104: Bump minimal PHP version to 8.1 (@vjik)
- Enh #104: Explicitly mark readonly properties (@vjik)
- Enh #105: Explicitly import classes and functions in "use" section (@mspirkov)

## 3.2.1 December 17, 2025

Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"yiisoft/strings": "^2.0"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.92.5",
"jetbrains/phpstorm-attributes": "^1.2",
"maglnet/composer-require-checker": "^4.7.1",
"nyholm/psr7": "^1.8.2",
Expand Down
4 changes: 1 addition & 3 deletions src/Debug/AuthenticationMethodInterfaceProxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@

final class AuthenticationMethodInterfaceProxy implements AuthenticationMethodInterface
{
public function __construct(private readonly AuthenticationMethodInterface $decorated, private readonly IdentityCollector $collector)
{
}
public function __construct(private readonly AuthenticationMethodInterface $decorated, private readonly IdentityCollector $collector) {}

public function authenticate(ServerRequestInterface $request): ?IdentityInterface
{
Expand Down
13 changes: 8 additions & 5 deletions src/Debug/IdentityCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
use Yiisoft\Yii\Debug\Collector\CollectorTrait;
use Yiisoft\Yii\Debug\Collector\SummaryCollectorInterface;

use function count;
use function is_array;

final class IdentityCollector implements SummaryCollectorInterface
{
use CollectorTrait;
Expand All @@ -17,7 +20,7 @@
public function getCollected(): array
{
if (!$this->isActive()) {
return [];

Check warning on line 23 in src/Debug/IdentityCollector.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.3-ubuntu-latest

Escaped Mutant for Mutator "ReturnRemoval": @@ @@ public function getCollected(): array { if (!$this->isActive()) { - return []; + } return $this->identities; }
}
return $this->identities;
}
Expand All @@ -25,7 +28,7 @@
public function collect(?IdentityInterface $identity): void
{
if (!$this->isActive()) {
return;

Check warning on line 31 in src/Debug/IdentityCollector.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.3-ubuntu-latest

Escaped Mutant for Mutator "ReturnRemoval": @@ @@ public function collect(?IdentityInterface $identity): void { if (!$this->isActive()) { - return; + } if ($identity === null) {
}

if ($identity === null) {
Expand All @@ -38,11 +41,6 @@
];
}

private function reset(): void
{
$this->identities = [];
}

public function getSummary(): array
{
if (!$this->isActive()) {
Expand All @@ -54,4 +52,9 @@
'total' => count($this->identities),
];
}

private function reset(): void
{
$this->identities = [];
}
}
3 changes: 1 addition & 2 deletions src/Handler/AuthenticationFailureHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ final class AuthenticationFailureHandler implements RequestHandlerInterface
{
public function __construct(
private readonly ResponseFactoryInterface $responseFactory,
) {
}
) {}

public function handle(ServerRequestInterface $request): ResponseInterface
{
Expand Down
6 changes: 3 additions & 3 deletions src/Method/Composite.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Psr\Http\Message\ServerRequestInterface;
use Yiisoft\Auth\AuthenticationMethodInterface;
use Yiisoft\Auth\IdentityInterface;
use RuntimeException;

/**
* Composite allows multiple authentication methods at the same time.
Expand All @@ -19,14 +20,13 @@
*/
public function __construct(
private readonly array $methods,
) {
}
) {}

public function authenticate(ServerRequestInterface $request): ?IdentityInterface
{
foreach ($this->methods as $method) {
if (!$method instanceof AuthenticationMethodInterface) {
throw new \RuntimeException('Authentication method must be an instance of ' . AuthenticationMethodInterface::class . '.');
throw new RuntimeException('Authentication method must be an instance of ' . AuthenticationMethodInterface::class . '.');

Check warning on line 29 in src/Method/Composite.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.3-ubuntu-latest

Escaped Mutant for Mutator "ConcatOperandRemoval": @@ @@ { foreach ($this->methods as $method) { if (!$method instanceof AuthenticationMethodInterface) { - throw new RuntimeException('Authentication method must be an instance of ' . AuthenticationMethodInterface::class . '.'); + throw new RuntimeException('Authentication method must be an instance of ' . AuthenticationMethodInterface::class); } $identity = $method->authenticate($request);

Check warning on line 29 in src/Method/Composite.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.3-ubuntu-latest

Escaped Mutant for Mutator "Concat": @@ @@ { foreach ($this->methods as $method) { if (!$method instanceof AuthenticationMethodInterface) { - throw new RuntimeException('Authentication method must be an instance of ' . AuthenticationMethodInterface::class . '.'); + throw new RuntimeException('Authentication method must be an instance of ' . '.' . AuthenticationMethodInterface::class); } $identity = $method->authenticate($request);

Check warning on line 29 in src/Method/Composite.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.3-ubuntu-latest

Escaped Mutant for Mutator "ConcatOperandRemoval": @@ @@ { foreach ($this->methods as $method) { if (!$method instanceof AuthenticationMethodInterface) { - throw new RuntimeException('Authentication method must be an instance of ' . AuthenticationMethodInterface::class . '.'); + throw new RuntimeException('Authentication method must be an instance of ' . '.'); } $identity = $method->authenticate($request);

Check warning on line 29 in src/Method/Composite.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.3-ubuntu-latest

Escaped Mutant for Mutator "ConcatOperandRemoval": @@ @@ { foreach ($this->methods as $method) { if (!$method instanceof AuthenticationMethodInterface) { - throw new RuntimeException('Authentication method must be an instance of ' . AuthenticationMethodInterface::class . '.'); + throw new RuntimeException(AuthenticationMethodInterface::class . '.'); } $identity = $method->authenticate($request);

Check warning on line 29 in src/Method/Composite.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.3-ubuntu-latest

Escaped Mutant for Mutator "Concat": @@ @@ { foreach ($this->methods as $method) { if (!$method instanceof AuthenticationMethodInterface) { - throw new RuntimeException('Authentication method must be an instance of ' . AuthenticationMethodInterface::class . '.'); + throw new RuntimeException(AuthenticationMethodInterface::class . 'Authentication method must be an instance of ' . '.'); } $identity = $method->authenticate($request);
}

$identity = $method->authenticate($request);
Expand Down
13 changes: 6 additions & 7 deletions src/Method/HttpBasic.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Yiisoft\Auth\IdentityInterface;
use Yiisoft\Auth\IdentityWithTokenRepositoryInterface;
use Yiisoft\Http\Header;
use SensitiveParameter;

use function call_user_func;
use function count;
Expand Down Expand Up @@ -37,9 +38,7 @@
*/
private $authenticationCallback;

public function __construct(private IdentityWithTokenRepositoryInterface $identityRepository)
{
}
public function __construct(private IdentityWithTokenRepositoryInterface $identityRepository) {}

public function authenticate(ServerRequestInterface $request): ?IdentityInterface
{
Expand Down Expand Up @@ -159,15 +158,15 @@
return $request->getServerParams()['REDIRECT_HTTP_AUTHORIZATION'] ?? null;
}

private function extractCredentialsFromHeader(#[\SensitiveParameter] string $authToken): array
private function extractCredentialsFromHeader(#[SensitiveParameter] string $authToken): array
{
return array_map(
static fn ($value) => $value === '' ? null : $value,
explode(':', base64_decode(substr($authToken, 6)), 2)
static fn($value) => $value === '' ? null : $value,
explode(':', base64_decode(substr($authToken, 6)), 2),

Check warning on line 165 in src/Method/HttpBasic.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.3-ubuntu-latest

Escaped Mutant for Mutator "DecrementInteger": @@ @@ { return array_map( static fn($value) => $value === '' ? null : $value, - explode(':', base64_decode(substr($authToken, 6)), 2), + explode(':', base64_decode(substr($authToken, 5)), 2), ); }
);
}

private function isBasicToken(#[\SensitiveParameter] string $token): bool
private function isBasicToken(#[SensitiveParameter] string $token): bool
{
return strncasecmp($token, 'basic', 5) === 0;
}
Expand Down
7 changes: 3 additions & 4 deletions src/Method/HttpCookie.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,10 @@ final class HttpCookie implements AuthenticationMethodInterface
private ?string $tokenType = null;

public function __construct(
private IdentityWithTokenRepositoryInterface $identityRepository
) {
}
private IdentityWithTokenRepositoryInterface $identityRepository,
) {}

public function authenticate(ServerRequestInterface $request): IdentityInterface|null
public function authenticate(ServerRequestInterface $request): ?IdentityInterface
{
$authToken = $this->getAuthenticationToken($request);

Expand Down
6 changes: 2 additions & 4 deletions src/Method/HttpHeader.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,15 @@
class HttpHeader implements AuthenticationMethodInterface
{
protected string $headerName = 'X-Api-Key';
private ?string $tokenType = null;

/**
* @var string A pattern to use to extract the HTTP authentication value.
* @psalm-var non-empty-string
*/
protected string $pattern = '/(.*)/';
private ?string $tokenType = null;

public function __construct(protected IdentityWithTokenRepositoryInterface $identityRepository)
{
}
public function __construct(protected IdentityWithTokenRepositoryInterface $identityRepository) {}

public function authenticate(ServerRequestInterface $request): ?IdentityInterface
{
Expand Down
4 changes: 1 addition & 3 deletions src/Method/QueryParameter.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ final class QueryParameter implements AuthenticationMethodInterface
private string $parameterName = 'access-token';
private ?string $tokenType = null;

public function __construct(private IdentityWithTokenRepositoryInterface $identityRepository)
{
}
public function __construct(private IdentityWithTokenRepositoryInterface $identityRepository) {}

public function authenticate(ServerRequestInterface $request): ?IdentityInterface
{
Expand Down
4 changes: 2 additions & 2 deletions src/Middleware/Authentication.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function __construct(
?RequestHandlerInterface $authenticationFailureHandler = null,
) {
$this->failureHandler = $authenticationFailureHandler ?? new AuthenticationFailureHandler(
$responseFactory
$responseFactory,
);
}

Expand All @@ -51,7 +51,7 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface

if ($identity === null && !$this->isOptional($request)) {
return $this->authenticationMethod->challenge(
$this->failureHandler->handle($request)
$this->failureHandler->handle($request),
);
}

Expand Down
2 changes: 1 addition & 1 deletion tests/AuthenticationFailureHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function testShouldReturnCorrectErrorInBody(): void
$response = $this
->createHandler()
->handle($this->createRequest());
$this->assertEquals('Your request was made with invalid credentials.', (string)$response->getBody());
$this->assertEquals('Your request was made with invalid credentials.', (string) $response->getBody());
}

private function createHandler(): AuthenticationFailureHandler
Expand Down
Loading
Loading