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
2 changes: 1 addition & 1 deletion .github/workflows/bc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ jobs:
os: >-
['ubuntu-latest']
php: >-
['8.1']
['8.5']
27 changes: 27 additions & 0 deletions .github/workflows/rector-cs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Rector + PHP CS Fixer

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

permissions:
contents: read

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

jobs:
rector-cs:
permissions:
contents: write # Required to commit formatting fixes back to the PR
uses: yiisoft/actions/.github/workflows/rector-cs.yml@master
with:
php: '8.1'
24 changes: 0 additions & 24 deletions .github/workflows/rector.yml

This file was deleted.

22 changes: 22 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

declare(strict_types=1);

use PhpCsFixer\Finder;
use PhpCsFixer\Runner\Parallel\ParallelConfigFactory;
use Yiisoft\CodeStyle\ConfigBuilder;

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

return ConfigBuilder::build()
->setCacheFile(__DIR__ . '/runtime/.php-cs-fixer.cache')
->setRiskyAllowed(true)
->setParallelConfig(ParallelConfigFactory::detect())
->setRules([
'@Yiisoft/Core' => true,
'@Yiisoft/Core:risky' => true,
])
->setFinder($finder);
85 changes: 0 additions & 85 deletions .styleci.yml

This file was deleted.

2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## 2.3.3 under development

- no changes in this release.
- Enh #120: Explicitly import classes and constants in "use" section (@vjik)

## 2.3.2 December 23, 2025

Expand Down
14 changes: 12 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,15 @@
"yiisoft/http": "^1.2"
},
"require-dev": {
"bamarni/composer-bin-plugin": "^1.9.1",
"friendsofphp/php-cs-fixer": "^3.64",
"httpsoft/http-message": "^1.1.6",
"maglnet/composer-require-checker": "^4.7.1",
"phpunit/phpunit": "^10.5.45",
"rector/rector": "^2.0.10",
"roave/infection-static-analysis-plugin": "^1.35",
"spatie/phpunit-watcher": "^1.24",
"vimeo/psalm": "^5.26.1 || ^6.8.8",
"yiisoft/code-style": "^1.1",
"yiisoft/di": "^1.3",
"yiisoft/test-support": "^3.0.2"
},
Expand All @@ -68,17 +70,25 @@
"config-plugin": {
"params": "params.php",
"di-web": "di-web.php"
},
"bamarni-bin": {
"bin-links": true,
"target-directory": "tools",
"forward-command": true
}
},
"config": {
"sort-packages": true,
"bump-after-update": "dev",
"allow-plugins": {
"infection/extension-installer": true,
"composer/package-versions-deprecated": true
"composer/package-versions-deprecated": true,
"bamarni/composer-bin-plugin": true
}
},
"scripts": {
"cs-fix": "php-cs-fixer fix",
"rector": "rector",
"test": "phpunit --testdox --no-interaction",
"test-watch": "phpunit-watcher watch"
}
Expand Down
31 changes: 7 additions & 24 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,15 @@

declare(strict_types=1);

use Rector\CodeQuality\Rector\Class_\InlineConstructorDefaultToPropertyRector;
use Rector\Config\RectorConfig;
use Rector\Php74\Rector\Closure\ClosureToArrowFunctionRector;
use Rector\Php81\Rector\ClassMethod\NewInInitializerRector;
use Rector\Php81\Rector\Property\ReadOnlyPropertyRector;
use Rector\Php81\Rector\FuncCall\NullToStrictStringFuncCallArgRector;
use Rector\Set\ValueObject\LevelSetList;
use Yiisoft\CodeStyle\Rector\SetList;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->paths([
return RectorConfig::configure()
->withPaths([
__DIR__ . '/src',
__DIR__ . '/tests',
])
->withPhpSets(php81: true)
->withSets([
SetList::YII_CORE,
]);

// register a single rule
$rectorConfig->rule(InlineConstructorDefaultToPropertyRector::class);

// define sets of rules
$rectorConfig->sets([
LevelSetList::UP_TO_PHP_81,
]);

$rectorConfig->skip([
ClosureToArrowFunctionRector::class,
ReadOnlyPropertyRector::class,
NullToStrictStringFuncCallArgRector::class,
NewInInitializerRector::class,
]);
};
2 changes: 2 additions & 0 deletions runtime/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*
!.gitignore
2 changes: 1 addition & 1 deletion src/CurrentUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
public function __construct(
private IdentityRepositoryInterface $identityRepository,
private EventDispatcherInterface $eventDispatcher,
?GuestIdentityFactoryInterface $guestIdentityFactory = null
?GuestIdentityFactoryInterface $guestIdentityFactory = null,
) {
$this->guestIdentityFactory = $guestIdentityFactory ?? new GuestIdentityFactory();
}
Expand Down Expand Up @@ -310,7 +310,7 @@
/** @var mixed $id */
$id = $this->session->get(self::SESSION_AUTH_ID);

if ($id !== null && ($this->authTimeout !== null || $this->absoluteAuthTimeout !== null)) {

Check warning on line 313 in src/CurrentUser.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.3-ubuntu-latest

Escaped Mutant for Mutator "LogicalOrAllSubExprNegation": @@ @@ /** @var mixed $id */ $id = $this->session->get(self::SESSION_AUTH_ID); - if ($id !== null && ($this->authTimeout !== null || $this->absoluteAuthTimeout !== null)) { + if ($id !== null && (!($this->authTimeout !== null) || !($this->absoluteAuthTimeout !== null))) { $expire = $this->getExpire(); $expireAbsolute = $this->getExpireAbsolute();
$expire = $this->getExpire();
$expireAbsolute = $this->getExpireAbsolute();

Expand Down
4 changes: 1 addition & 3 deletions src/Event/AfterLogin.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@

final class AfterLogin
{
public function __construct(private IdentityInterface $identity)
{
}
public function __construct(private IdentityInterface $identity) {}

public function getIdentity(): IdentityInterface
{
Expand Down
4 changes: 1 addition & 3 deletions src/Event/AfterLogout.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@

final class AfterLogout
{
public function __construct(private IdentityInterface $identity)
{
}
public function __construct(private IdentityInterface $identity) {}

public function getIdentity(): IdentityInterface
{
Expand Down
4 changes: 1 addition & 3 deletions src/Event/BeforeLogin.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ final class BeforeLogin
{
private bool $isValid = true;

public function __construct(private IdentityInterface $identity)
{
}
public function __construct(private IdentityInterface $identity) {}

public function invalidate(): void
{
Expand Down
4 changes: 1 addition & 3 deletions src/Event/BeforeLogout.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ final class BeforeLogout
{
private bool $isValid = true;

public function __construct(private IdentityInterface $identity)
{
}
public function __construct(private IdentityInterface $identity) {}

public function invalidate(): void
{
Expand Down
4 changes: 1 addition & 3 deletions src/Guest/GuestIdentityInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,4 @@
/**
* Identity interface for a guest non-authenticated user.
*/
interface GuestIdentityInterface extends IdentityInterface
{
}
interface GuestIdentityInterface extends IdentityInterface {}
10 changes: 6 additions & 4 deletions src/Login/Cookie/CookieLogin.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@

use function json_encode;

use const JSON_THROW_ON_ERROR;
use const JSON_UNESCAPED_SLASHES;
use const JSON_UNESCAPED_UNICODE;

/**
* The service is used to send or remove auto-login cookie.
*
Expand All @@ -26,9 +30,7 @@
* @param DateInterval|null $duration Interval until the auto-login cookie expires. If it isn't set it means
* the auto-login cookie is session cookie that expires when browser is closed.
*/
public function __construct(private ?DateInterval $duration = null)
{
}
public function __construct(private ?DateInterval $duration = null) {}

/**
* Returns a new instance with the specified auto-login cookie name.
Expand All @@ -37,7 +39,7 @@
*/
public function withCookieName(string $name): self
{
$new = clone $this;

Check warning on line 42 in src/Login/Cookie/CookieLogin.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.3-ubuntu-latest

Escaped Mutant for Mutator "CloneRemoval": @@ @@ */ public function withCookieName(string $name): self { - $new = clone $this; + $new = $this; $new->cookieName = $name; return $new; }
$new->cookieName = $name;
return $new;
}
Expand All @@ -59,7 +61,7 @@
public function addCookie(
CookieLoginIdentityInterface $identity,
ResponseInterface $response,
DateInterval|null|false $duration = false,
DateInterval|false|null $duration = false,
): ResponseInterface {
$duration = $duration === false ? $this->duration : $duration;

Expand All @@ -73,7 +75,7 @@
$data[] = 0;
}

$cookieValue = json_encode($data, JSON_THROW_ON_ERROR | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);

Check warning on line 78 in src/Login/Cookie/CookieLogin.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.3-ubuntu-latest

Escaped Mutant for Mutator "BitwiseOr": @@ @@ $data[] = 0; } - $cookieValue = json_encode($data, JSON_THROW_ON_ERROR | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); + $cookieValue = json_encode($data, JSON_THROW_ON_ERROR | JSON_UNESCAPED_SLASHES & JSON_UNESCAPED_UNICODE); return (new Cookie(name: $this->cookieName, value: $cookieValue, expires: $expires))->addToResponse($response); }

return (new Cookie(name: $this->cookieName, value: $cookieValue, expires: $expires))->addToResponse($response);
}
Expand Down
9 changes: 5 additions & 4 deletions src/Login/Cookie/CookieLoginMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
use function sprintf;
use function time;

use const JSON_THROW_ON_ERROR;

/**
* `CookieLoginMiddleware` automatically logs user in based on cookie.
*/
Expand All @@ -39,9 +41,8 @@
private IdentityRepositoryInterface $identityRepository,
private LoggerInterface $logger,
private CookieLogin $cookieLogin,
private bool $forceAddCookie = false
) {
}
private bool $forceAddCookie = false,

Check warning on line 44 in src/Login/Cookie/CookieLoginMiddleware.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.3-ubuntu-latest

Escaped Mutant for Mutator "FalseValue": @@ @@ private IdentityRepositoryInterface $identityRepository, private LoggerInterface $logger, private CookieLogin $cookieLogin, - private bool $forceAddCookie = false, + private bool $forceAddCookie = true, ) {} /**
) {}

/**
* {@inheritDoc}
Expand Down Expand Up @@ -93,7 +94,7 @@
}

try {
$data = json_decode((string) $cookies[$cookieName], true, 512, JSON_THROW_ON_ERROR);

Check warning on line 97 in src/Login/Cookie/CookieLoginMiddleware.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.3-ubuntu-latest

Escaped Mutant for Mutator "DecrementInteger": @@ @@ } try { - $data = json_decode((string) $cookies[$cookieName], true, 512, JSON_THROW_ON_ERROR); + $data = json_decode((string) $cookies[$cookieName], true, 511, JSON_THROW_ON_ERROR); } catch (Throwable) { $this->logger->warning('Unable to authenticate user by cookie. Invalid cookie.'); return;

Check warning on line 97 in src/Login/Cookie/CookieLoginMiddleware.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.3-ubuntu-latest

Escaped Mutant for Mutator "IncrementInteger": @@ @@ } try { - $data = json_decode((string) $cookies[$cookieName], true, 512, JSON_THROW_ON_ERROR); + $data = json_decode((string) $cookies[$cookieName], true, 513, JSON_THROW_ON_ERROR); } catch (Throwable) { $this->logger->warning('Unable to authenticate user by cookie. Invalid cookie.'); return;
} catch (Throwable) {
$this->logger->warning('Unable to authenticate user by cookie. Invalid cookie.');
return;
Expand Down Expand Up @@ -122,18 +123,18 @@
sprintf(
'Identity repository must return an instance of %s in order for auto-login to function.',
CookieLoginIdentityInterface::class,
)
),
);
}

if (!$identity->validateCookieLoginKey($key)) {
$this->logger->warning('Unable to authenticate user by cookie. Invalid key.');
return;

Check warning on line 132 in src/Login/Cookie/CookieLoginMiddleware.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.3-ubuntu-latest

Escaped Mutant for Mutator "ReturnRemoval": @@ @@ if (!$identity->validateCookieLoginKey($key)) { $this->logger->warning('Unable to authenticate user by cookie. Invalid key.'); - return; + } if ($expires !== 0 && $expires < time()) {
}

if ($expires !== 0 && $expires < time()) {

Check warning on line 135 in src/Login/Cookie/CookieLoginMiddleware.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.3-ubuntu-latest

Escaped Mutant for Mutator "LessThan": @@ @@ return; } - if ($expires !== 0 && $expires < time()) { + if ($expires !== 0 && $expires <= time()) { $this->logger->warning('Unable to authenticate user by cookie. Lifetime has expired.'); return; }
$this->logger->warning('Unable to authenticate user by cookie. Lifetime has expired.');
return;

Check warning on line 137 in src/Login/Cookie/CookieLoginMiddleware.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.3-ubuntu-latest

Escaped Mutant for Mutator "ReturnRemoval": @@ @@ if ($expires !== 0 && $expires < time()) { $this->logger->warning('Unable to authenticate user by cookie. Lifetime has expired.'); - return; + } $this->currentUser->login($identity);
}

$this->currentUser->login($identity);
Expand Down
Loading