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
26 changes: 26 additions & 0 deletions .github/workflows/rector-cs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Rector + PHP CS Fixer

on:
pull_request:
paths:
- 'src/**'
- 'tests/**'
- '.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.0'
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 @@

## 3.2.1 under development

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

## 3.2.0 February 05, 2026

Expand Down
9 changes: 6 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,12 @@
"psr/simple-cache": "^2.0|^3.0"
},
"require-dev": {
"bamarni/composer-bin-plugin": "^1.8.3",
"maglnet/composer-require-checker": "^4.4",
"bamarni/composer-bin-plugin": "^1.9.1",
"friendsofphp/php-cs-fixer": "^3.95",
"phpunit/phpunit": "^9.6.22",
"rector/rector": "^2.0.9",
"spatie/phpunit-watcher": "^1.23.6"
"spatie/phpunit-watcher": "^1.23.6",
"yiisoft/code-style": "^1.1"
},
"autoload": {
"psr-4": {
Expand All @@ -53,6 +54,8 @@
}
},
"scripts": {
"cs-fix": "php-cs-fixer fix",
"rector": "rector",
"test": "phpunit --testdox --no-interaction",
"test-watch": "phpunit-watcher watch"
},
Expand Down
20 changes: 7 additions & 13 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,15 @@

declare(strict_types=1);

use Rector\CodeQuality\Rector\Class_\InlineConstructorDefaultToPropertyRector;
use Rector\Config\RectorConfig;
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(php80: true)
->withSets([
SetList::YII_CORE,
]);

// 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
3 changes: 1 addition & 2 deletions src/Clock/StaticClock.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ final class StaticClock implements ClockInterface
{
public function __construct(
private DateTimeImmutable $now,
) {
}
) {}

public function now(): DateTimeImmutable
{
Expand Down
13 changes: 6 additions & 7 deletions src/Container/SimpleContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,21 @@
* @param Closure|null $factory Should be closure that works like ContainerInterface::get(string $id): mixed
* @param Closure|null $hasCallback Should be closure that works like ContainerInterface::has(string $id): bool
*
* @psalm-param Closure(string) $factory
* @psalm-param Closure(string):mixed $factory
* @psalm-param Closure(string):bool $hasCallback
*/
public function __construct(
private array $definitions = [],
?Closure $factory = null,
?Closure $hasCallback = null
?Closure $hasCallback = null,
) {
$this->factory = $factory ??
/** @return mixed */
static function (string $id) {
$this->factory = $factory
?? static function (string $id): mixed {
throw new NotFoundException($id);
};

$this->hasCallback = $hasCallback ??
function (string $id): bool {
$this->hasCallback = $hasCallback

Check warning on line 42 in src/Container/SimpleContainer.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.5-ubuntu-latest

Escaped Mutant for Mutator "Coalesce": @@ @@ $this->factory = $factory ?? static function (string $id): mixed { throw new NotFoundException($id); }; - $this->hasCallback = $hasCallback ?? function (string $id): bool { + $this->hasCallback = function (string $id): bool { try { $this->get($id); return true; @@ @@ } catch (NotFoundException) { return false; } - }; + } ?? $hasCallback; } public function get($id) {
?? function (string $id): bool {
try {
$this->get($id);
return true;
Expand All @@ -62,7 +61,7 @@
public function has($id): bool
{
if (array_key_exists($id, $this->definitions)) {
return true;

Check warning on line 64 in src/Container/SimpleContainer.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.5-ubuntu-latest

Escaped Mutant for Mutator "ReturnRemoval": @@ @@ public function has($id): bool { if (array_key_exists($id, $this->definitions)) { - return true; + } return ($this->hasCallback)($id); } }
}
return ($this->hasCallback)($id);
}
Expand Down
6 changes: 3 additions & 3 deletions src/EventDispatcher/SimpleEventDispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,17 @@ public function clearEvents(): void

public function isObjectTriggered(object $event, ?int $times = null): bool
{
return $this->processBoolResult(static fn (object $e): bool => $e === $event, $times);
return $this->processBoolResult(static fn(object $e): bool => $e === $event, $times);
}

public function isClassTriggered(string $class, ?int $times = null): bool
{
return $this->processBoolResult(static fn (object $event): bool => $event::class === $class, $times);
return $this->processBoolResult(static fn(object $event): bool => $event::class === $class, $times);
}

public function isInstanceOfTriggered(string $class, ?int $times = null): bool
{
return $this->processBoolResult(static fn (object $event): bool => $event instanceof $class, $times);
return $this->processBoolResult(static fn(object $event): bool => $event instanceof $class, $times);
}

private function processBoolResult(Closure $closure, ?int $times): bool
Expand Down
7 changes: 6 additions & 1 deletion src/HttpMessage/StringStream.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@

use function is_array;
use function strlen;
use function sprintf;

use const SEEK_CUR;
use const SEEK_END;
use const SEEK_SET;

/**
* A test-specific implementation of PSR-7 stream.
Expand Down Expand Up @@ -46,7 +51,7 @@
$size = strlen($this->content);
if ($this->position < 0 || $this->position > $size) {
throw new LogicException(
sprintf('Position %d is out of valid range [0, %d].', $this->position, $size)
sprintf('Position %d is out of valid range [0, %d].', $this->position, $size),
);
}
}
Expand Down Expand Up @@ -190,8 +195,8 @@
throw new RuntimeException('Length cannot be negative.');
}

if ($this->position >= $this->getContentSize()) {

Check warning on line 198 in src/HttpMessage/StringStream.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.5-ubuntu-latest

Escaped Mutant for Mutator "GreaterThanOrEqualTo": @@ @@ if ($length < 0) { throw new RuntimeException('Length cannot be negative.'); } - if ($this->position >= $this->getContentSize()) { + if ($this->position > $this->getContentSize()) { return ''; } $result = substr($this->content, $this->position, $length);
return '';

Check warning on line 199 in src/HttpMessage/StringStream.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.5-ubuntu-latest

Escaped Mutant for Mutator "ReturnRemoval": @@ @@ throw new RuntimeException('Length cannot be negative.'); } if ($this->position >= $this->getContentSize()) { - return ''; + } $result = substr($this->content, $this->position, $length); $this->position += strlen($result);
}

$result = substr($this->content, $this->position, $length);
Expand All @@ -203,7 +208,7 @@
public function getContents(): string
{
return $this->read(
$this->getContentSize() - $this->position,

Check warning on line 211 in src/HttpMessage/StringStream.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.5-ubuntu-latest

Escaped Mutant for Mutator "Minus": @@ @@ } public function getContents(): string { - return $this->read($this->getContentSize() - $this->position); + return $this->read($this->getContentSize() + $this->position); } public function getMetadata(?string $key = null) {
);
}

Expand Down
7 changes: 4 additions & 3 deletions src/Log/SimpleLogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use function is_string;
use function preg_replace_callback;
use function sprintf;
use function in_array;

final class SimpleLogger implements LoggerInterface
{
Expand Down Expand Up @@ -53,19 +54,19 @@ public function log(mixed $level, string|Stringable $message, array $context = [
if (!is_string($level)) {
throw new InvalidArgumentException(sprintf(
'The log message level must be a string, %s provided.',
gettype($level)
gettype($level),
));
}

if (!in_array($level, self::LEVELS, true)) {
throw new InvalidArgumentException(sprintf(
'Invalid log message level "%s" provided. The following values are supported: "%s".',
$level,
implode('", "', self::LEVELS)
implode('", "', self::LEVELS),
));
}

$message = $this->parseMessage((string)$message, $context);
$message = $this->parseMessage((string) $message, $context);

$this->messages[] = ['level' => $level, 'message' => $message, 'context' => $context];
}
Expand Down
5 changes: 2 additions & 3 deletions src/SimpleCache/Action.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,8 @@ private function __construct(
private string $action,
private mixed $key = null,
private mixed $value = null,
private mixed $ttl = null
) {
}
private mixed $ttl = null,
) {}

/**
* @return TAction
Expand Down
4 changes: 1 addition & 3 deletions src/SimpleCache/Exception/InvalidArgumentException.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,4 @@
/**
* @final
*/
class InvalidArgumentException extends \InvalidArgumentException implements \Psr\SimpleCache\InvalidArgumentException
{
}
class InvalidArgumentException extends \InvalidArgumentException implements \Psr\SimpleCache\InvalidArgumentException {}
8 changes: 4 additions & 4 deletions src/SimpleCache/MemorySimpleCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@
return $default;
}

public function set(string $key, mixed $value, null|int|DateInterval $ttl = null): bool
public function set(string $key, mixed $value, int|DateInterval|null $ttl = null): bool
{
$this->validateKey($key);
$expiration = $this->ttlToExpiration($ttl);
if ($expiration < 0) {
return $this->delete($key);

Check warning on line 54 in src/SimpleCache/MemorySimpleCache.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.5-ubuntu-latest

Escaped Mutant for Mutator "ReturnRemoval": @@ @@ $this->validateKey($key); $expiration = $this->ttlToExpiration($ttl); if ($expiration < 0) { - return $this->delete($key); + } if (is_object($value)) { $value = clone $value;
}
if (is_object($value)) {
$value = clone $value;
Expand All @@ -76,7 +76,7 @@
public function getMultiple(iterable $keys, mixed $default = null): iterable
{
$keys = $this->iterableToArray($keys);
$this->validateKeys($keys);

Check warning on line 79 in src/SimpleCache/MemorySimpleCache.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.5-ubuntu-latest

Escaped Mutant for Mutator "MethodCallRemoval": @@ @@ public function getMultiple(iterable $keys, mixed $default = null): iterable { $keys = $this->iterableToArray($keys); - $this->validateKeys($keys); + /** @psalm-var string[] $keys */ $result = []; foreach ($keys as $key) {
/** @psalm-var string[] $keys */
$result = [];
foreach ($keys as $key) {
Expand All @@ -85,7 +85,7 @@
return $result;
}

public function setMultiple(iterable $values, null|int|DateInterval $ttl = null): bool
public function setMultiple(iterable $values, int|DateInterval|null $ttl = null): bool
{
$values = $this->iterableToArray($values);
$this->validateKeysOfValues($values);
Expand Down Expand Up @@ -132,19 +132,19 @@
*/
private function isExpired(string $key): bool
{
return $this->cache[$key][1] !== 0 && $this->cache[$key][1] <= time();

Check warning on line 135 in src/SimpleCache/MemorySimpleCache.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.5-ubuntu-latest

Escaped Mutant for Mutator "LogicalAndAllSubExprNegation": @@ @@ */ private function isExpired(string $key): bool { - return $this->cache[$key][1] !== 0 && $this->cache[$key][1] <= time(); + return !($this->cache[$key][1] !== 0) && !($this->cache[$key][1] <= time()); } /** * Converts TTL to expiration.

Check warning on line 135 in src/SimpleCache/MemorySimpleCache.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.5-ubuntu-latest

Escaped Mutant for Mutator "LessThanOrEqualTo": @@ @@ */ private function isExpired(string $key): bool { - return $this->cache[$key][1] !== 0 && $this->cache[$key][1] <= time(); + return $this->cache[$key][1] !== 0 && $this->cache[$key][1] < time(); } /** * Converts TTL to expiration.
}

/**
* Converts TTL to expiration.
*/
private function ttlToExpiration(null|int|DateInterval $ttl): int
private function ttlToExpiration(int|DateInterval|null $ttl): int
{
$ttl = $this->normalizeTtl($ttl);

if ($ttl === null) {
$expiration = self::EXPIRATION_INFINITY;
} elseif ($ttl <= 0) {

Check warning on line 147 in src/SimpleCache/MemorySimpleCache.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.5-ubuntu-latest

Escaped Mutant for Mutator "LessThanOrEqualTo": @@ @@ $ttl = $this->normalizeTtl($ttl); if ($ttl === null) { $expiration = self::EXPIRATION_INFINITY; - } elseif ($ttl <= 0) { + } elseif ($ttl < 0) { $expiration = self::EXPIRATION_EXPIRED; } else { $expiration = $ttl + time();
$expiration = self::EXPIRATION_EXPIRED;
} else {
$expiration = $ttl + time();
Expand All @@ -160,7 +160,7 @@
*
* @return int|null TTL value as UNIX timestamp or null meaning infinity.
*/
private function normalizeTtl(null|int|DateInterval $ttl): ?int
private function normalizeTtl(int|DateInterval|null $ttl): ?int
{
if ($ttl instanceof DateInterval) {
return (new DateTime('@0'))
Expand Down
Loading