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
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 & CS fix

on:
pull_request:
paths:
- 'config/**'
- 'src/**'
- 'tests/**'
- 'rector.php'
- '.php-cs-fixer.dist.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.0'
26 changes: 0 additions & 26 deletions .github/workflows/rector.yml

This file was deleted.

23 changes: 23 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?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',
__DIR__ . '/config',
]);

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 @@

## 3.0.2 under development

- no changes in this release.
- Chg #81: Add explicit use imports for classes and constants (@vjik)

## 3.0.1 December 17, 2025

Expand Down
14 changes: 12 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,15 @@
"yiisoft/cookies": "^1.0"
},
"require-dev": {
"maglnet/composer-require-checker": "^4.4",
"bamarni/composer-bin-plugin": "*",
"friendsofphp/php-cs-fixer": "^3.95",
"nyholm/psr7": "^1.8.2",
"phpunit/phpunit": "^9.6.22",
"rector/rector": "^2.0.10",
"roave/infection-static-analysis-plugin": "^1.25",
"spatie/phpunit-watcher": "^1.23.6",
"vimeo/psalm": "^4.30 || ^5.6 || ^6.8.8",
"yiisoft/code-style": "^1.0",
"yiisoft/di": "^1.2.1"
},
"suggest": {
Expand All @@ -60,6 +62,11 @@
}
},
"extra": {
"bamarni-bin": {
"bin-links": true,
"target-directory": "tools",
"forward-command": true
},
"config-plugin-options": {
"source-directory": "config"
},
Expand All @@ -72,10 +79,13 @@
"sort-packages": true,
"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
23 changes: 11 additions & 12 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,18 @@

use Rector\CodeQuality\Rector\Class_\InlineConstructorDefaultToPropertyRector;
use Rector\Config\RectorConfig;
use Rector\Set\ValueObject\LevelSetList;
use Rector\Php74\Rector\Closure\ClosureToArrowFunctionRector;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->paths([
return RectorConfig::configure()
->withPaths([
__DIR__ . '/src',
__DIR__ . '/tests',
__DIR__ . '/config',
])
->withPhpSets(php80: true)
->withRules([
InlineConstructorDefaultToPropertyRector::class,
])
->withSkip([
ClosureToArrowFunctionRector::class,
]);

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

// define sets of rules
$rectorConfig->sets([
LevelSetList::UP_TO_PHP_80,
]);
};
2 changes: 2 additions & 0 deletions runtime/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*
!.gitignore
4 changes: 1 addition & 3 deletions src/Flash/Flash.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@

private ?string $sessionId = null;

public function __construct(private SessionInterface $session)
{
}
public function __construct(private SessionInterface $session) {}

public function get(string $key)
{
Expand All @@ -32,7 +30,7 @@
return null;
}

if ($flashes[self::COUNTERS][$key] < 0) {

Check warning on line 33 in src/Flash/Flash.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.2-ubuntu-latest

Escaped Mutant for Mutator "LessThan": @@ @@ if (!isset($flashes[$key], $flashes[self::COUNTERS][$key])) { return null; } - if ($flashes[self::COUNTERS][$key] < 0) { + if ($flashes[self::COUNTERS][$key] <= 0) { // Mark for deletion in the next request. $flashes[self::COUNTERS][$key] = 1; $this->save($flashes);
// Mark for deletion in the next request.
$flashes[self::COUNTERS][$key] = 1;
$this->save($flashes);
Expand All @@ -53,7 +51,7 @@
}

$list[$key] = $value;
if ($flashes[self::COUNTERS][$key] < 0) {

Check warning on line 54 in src/Flash/Flash.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.2-ubuntu-latest

Escaped Mutant for Mutator "LessThan": @@ @@ continue; } $list[$key] = $value; - if ($flashes[self::COUNTERS][$key] < 0) { + if ($flashes[self::COUNTERS][$key] <= 0) { // Mark for deletion in the next request. $flashes[self::COUNTERS][$key] = 1; }
// Mark for deletion in the next request.
$flashes[self::COUNTERS][$key] = 1;
}
Expand All @@ -64,23 +62,23 @@
return $list;
}

public function set(string $key, $value = true, bool $removeAfterAccess = true): void

Check warning on line 65 in src/Flash/Flash.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.2-ubuntu-latest

Escaped Mutant for Mutator "TrueValue": @@ @@ $this->save($flashes); return $list; } - public function set(string $key, $value = true, bool $removeAfterAccess = true): void + public function set(string $key, $value = false, bool $removeAfterAccess = true): void { $flashes = $this->fetch(); /** @psalm-suppress MixedArrayAssignment */
{
$flashes = $this->fetch();

/** @psalm-suppress MixedArrayAssignment */
$flashes[self::COUNTERS][$key] = $removeAfterAccess ? -1 : 0;

Check warning on line 70 in src/Flash/Flash.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.2-ubuntu-latest

Escaped Mutant for Mutator "IncrementInteger": @@ @@ { $flashes = $this->fetch(); /** @psalm-suppress MixedArrayAssignment */ - $flashes[self::COUNTERS][$key] = $removeAfterAccess ? -1 : 0; + $flashes[self::COUNTERS][$key] = $removeAfterAccess ? -1 : 1; $flashes[$key] = $value; $this->save($flashes); }

Check warning on line 70 in src/Flash/Flash.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.2-ubuntu-latest

Escaped Mutant for Mutator "DecrementInteger": @@ @@ { $flashes = $this->fetch(); /** @psalm-suppress MixedArrayAssignment */ - $flashes[self::COUNTERS][$key] = $removeAfterAccess ? -1 : 0; + $flashes[self::COUNTERS][$key] = $removeAfterAccess ? -1 : -1; $flashes[$key] = $value; $this->save($flashes); }

$flashes[$key] = $value;
$this->save($flashes);
}

public function add(string $key, $value = true, bool $removeAfterAccess = true): void

Check warning on line 76 in src/Flash/Flash.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.2-ubuntu-latest

Escaped Mutant for Mutator "TrueValue": @@ @@ $flashes[$key] = $value; $this->save($flashes); } - public function add(string $key, $value = true, bool $removeAfterAccess = true): void + public function add(string $key, $value = false, bool $removeAfterAccess = true): void { $flashes = $this->fetch(); /** @psalm-suppress MixedArrayAssignment */
{
$flashes = $this->fetch();

/** @psalm-suppress MixedArrayAssignment */
$flashes[self::COUNTERS][$key] = $removeAfterAccess ? -1 : 0;

Check warning on line 81 in src/Flash/Flash.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.2-ubuntu-latest

Escaped Mutant for Mutator "IncrementInteger": @@ @@ { $flashes = $this->fetch(); /** @psalm-suppress MixedArrayAssignment */ - $flashes[self::COUNTERS][$key] = $removeAfterAccess ? -1 : 0; + $flashes[self::COUNTERS][$key] = $removeAfterAccess ? -1 : 1; if (empty($flashes[$key])) { $flashes[$key] = [$value]; } elseif (is_array($flashes[$key])) {

Check warning on line 81 in src/Flash/Flash.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.2-ubuntu-latest

Escaped Mutant for Mutator "DecrementInteger": @@ @@ { $flashes = $this->fetch(); /** @psalm-suppress MixedArrayAssignment */ - $flashes[self::COUNTERS][$key] = $removeAfterAccess ? -1 : 0; + $flashes[self::COUNTERS][$key] = $removeAfterAccess ? -1 : -1; if (empty($flashes[$key])) { $flashes[$key] = [$value]; } elseif (is_array($flashes[$key])) {

if (empty($flashes[$key])) {
$flashes[$key] = [$value];
Expand Down Expand Up @@ -119,7 +117,7 @@
{
$flashes = $this->session->get(self::FLASH_PARAM, []);
if (!is_array($flashes)) {
$flashes = [self::COUNTERS => []];

Check warning on line 120 in src/Flash/Flash.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.2-ubuntu-latest

Escaped Mutant for Mutator "ArrayItemRemoval": @@ @@ { $flashes = $this->session->get(self::FLASH_PARAM, []); if (!is_array($flashes)) { - $flashes = [self::COUNTERS => []]; + $flashes = []; } $counters = $flashes[self::COUNTERS] ?? []; if (!is_array($counters)) {
}

$counters = $flashes[self::COUNTERS] ?? [];
Expand Down Expand Up @@ -150,7 +148,7 @@
private function fetch(): array
{
// Ensure session is active (and has id).
$this->session->open();

Check warning on line 151 in src/Flash/Flash.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.2-ubuntu-latest

Escaped Mutant for Mutator "MethodCallRemoval": @@ @@ */ private function fetch(): array { - // Ensure session is active (and has id). - $this->session->open(); + if ($this->sessionId !== $this->session->getId()) { $this->sessionId = $this->session->getId(); $this->updateCounters();
if ($this->sessionId !== $this->session->getId()) {
$this->sessionId = $this->session->getId();
$this->updateCounters();
Expand Down
36 changes: 9 additions & 27 deletions src/NullSession.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,39 +14,27 @@ public function get(string $key, $default = null)
return null;
}

public function set(string $key, $value): void
{
}
public function set(string $key, $value): void {}

public function close(): void
{
}
public function close(): void {}

public function open(): void
{
}
public function open(): void {}

public function isActive(): bool
{
return false;
}

public function regenerateId(): void
{
}
public function regenerateId(): void {}

public function discard(): void
{
}
public function discard(): void {}

public function all(): array
{
return [];
}

public function remove(string $key): void
{
}
public function remove(string $key): void {}

public function has(string $key): bool
{
Expand All @@ -58,9 +46,7 @@ public function pull(string $key, $default = null)
return null;
}

public function destroy(): void
{
}
public function destroy(): void {}

public function getCookieParameters(): array
{
Expand All @@ -72,16 +58,12 @@ public function getId(): ?string
return null;
}

public function setId(string $sessionId): void
{
}
public function setId(string $sessionId): void {}

public function getName(): string
{
return 'null';
}

public function clear(): void
{
}
public function clear(): void {}
}
6 changes: 4 additions & 2 deletions src/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
use SessionHandlerInterface;
use Throwable;

use const PHP_SESSION_ACTIVE;

/**
* Session provides session data management and the related configurations.
*
Expand Down Expand Up @@ -99,7 +101,7 @@ public function open(): void
*/
$this->sessionId = session_id();
} catch (Throwable $e) {
throw new SessionException('Failed to start session.', (int)$e->getCode(), $e);
throw new SessionException('Failed to start session.', (int) $e->getCode(), $e);
}
}

Expand All @@ -124,7 +126,7 @@ public function regenerateId(): void
$this->sessionId = session_id();
}
} catch (Throwable $e) {
throw new SessionException('Failed to regenerate ID.', (int)$e->getCode(), $e);
throw new SessionException('Failed to regenerate ID.', (int) $e->getCode(), $e);
}
}
}
Expand Down
4 changes: 1 addition & 3 deletions src/SessionException.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,4 @@

use RuntimeException;

final class SessionException extends RuntimeException
{
}
final class SessionException extends RuntimeException {}
Loading
Loading