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 @@ -20,3 +20,7 @@ composer.lock
/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 @@ -3,6 +3,7 @@
## 5.0.0 under development

- Chg #162: Replace deprecated `ThrowableResponseFactory` class usage to new one, and remove it (@vjik)
- Enh #163: Explicitly import classes, functions, and constants in "use" section (@mspirkov)

## 4.3.2 January 09, 2026

Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"yiisoft/injector": "^1.0"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.92.5",
"bamarni/composer-bin-plugin": "^1.8.2",
"httpsoft/http-message": "^1.1.6",
"phpunit/phpunit": "^10.5.51",
Expand Down
2 changes: 1 addition & 1 deletion config/di-web.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
static fn(ContainerInterface $container) => new CompositeRendererProvider(
new HeadRendererProvider(),
new ContentTypeRendererProvider($container),
)
),
),
],
],
Expand Down
3 changes: 1 addition & 2 deletions src/ErrorData.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ final class ErrorData implements Stringable
public function __construct(
private readonly string $content,
private readonly array $headers = [],
) {
}
) {}

/**
* Returns a content to use as response body.
Expand Down
16 changes: 9 additions & 7 deletions src/ErrorHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
use function set_exception_handler;
use function str_repeat;

use const DEBUG_BACKTRACE_IGNORE_ARGS;
use const PHP_SAPI;

/**
* `ErrorHandler` handles out of memory errors, fatals, warnings, notices and exceptions.
*/
Expand Down Expand Up @@ -50,9 +53,8 @@
private readonly LoggerInterface $logger,
private readonly ThrowableRendererInterface $defaultRenderer,
private readonly ?EventDispatcherInterface $eventDispatcher = null,
private readonly int $exitShutdownHandlerDepth = 2
) {
}
private readonly int $exitShutdownHandlerDepth = 2,

Check warning on line 56 in src/ErrorHandler.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.1-ubuntu-latest

Escaped Mutant for Mutator "IncrementInteger": --- Original +++ New @@ @@ * @param EventDispatcherInterface|null $eventDispatcher Event dispatcher for error events. * @param int $exitShutdownHandlerDepth Depth of the exit() shutdown handler to ensure it's executed last. */ - public function __construct(private readonly LoggerInterface $logger, private readonly ThrowableRendererInterface $defaultRenderer, private readonly ?EventDispatcherInterface $eventDispatcher = null, private readonly int $exitShutdownHandlerDepth = 2) + public function __construct(private readonly LoggerInterface $logger, private readonly ThrowableRendererInterface $defaultRenderer, private readonly ?EventDispatcherInterface $eventDispatcher = null, private readonly int $exitShutdownHandlerDepth = 3) { } /**

Check warning on line 56 in src/ErrorHandler.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.1-ubuntu-latest

Escaped Mutant for Mutator "DecrementInteger": --- Original +++ New @@ @@ * @param EventDispatcherInterface|null $eventDispatcher Event dispatcher for error events. * @param int $exitShutdownHandlerDepth Depth of the exit() shutdown handler to ensure it's executed last. */ - public function __construct(private readonly LoggerInterface $logger, private readonly ThrowableRendererInterface $defaultRenderer, private readonly ?EventDispatcherInterface $eventDispatcher = null, private readonly int $exitShutdownHandlerDepth = 2) + public function __construct(private readonly LoggerInterface $logger, private readonly ThrowableRendererInterface $defaultRenderer, private readonly ?EventDispatcherInterface $eventDispatcher = null, private readonly int $exitShutdownHandlerDepth = 1) { } /**
) {}

/**
* Handles throwable and returns error data.
Expand All @@ -63,12 +65,12 @@
public function handle(
Throwable $t,
?ThrowableRendererInterface $renderer = null,
?ServerRequestInterface $request = null
?ServerRequestInterface $request = null,
): ErrorData {
$renderer ??= $this->defaultRenderer;

try {
$this->logger->error($t->getMessage(), ['throwable' => $t]);

Check warning on line 73 in src/ErrorHandler.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.1-ubuntu-latest

Escaped Mutant for Mutator "MethodCallRemoval": --- Original +++ New @@ @@ { $renderer ??= $this->defaultRenderer; try { - $this->logger->error($t->getMessage(), ['throwable' => $t]); + return $this->debug ? $renderer->renderVerbose($t, $request) : $renderer->render($t, $request); } catch (Throwable $t) { return new ErrorData((string) $t);

Check warning on line 73 in src/ErrorHandler.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.1-ubuntu-latest

Escaped Mutant for Mutator "ArrayItemRemoval": --- Original +++ New @@ @@ { $renderer ??= $this->defaultRenderer; try { - $this->logger->error($t->getMessage(), ['throwable' => $t]); + $this->logger->error($t->getMessage(), []); return $this->debug ? $renderer->renderVerbose($t, $request) : $renderer->render($t, $request); } catch (Throwable $t) { return new ErrorData((string) $t);
return $this->debug ? $renderer->renderVerbose($t, $request) : $renderer->render($t, $request);
} catch (Throwable $t) {
return new ErrorData((string) $t);
Expand Down Expand Up @@ -108,14 +110,14 @@
return;
}

if ($this->memoryReserveSize > 0) {

Check warning on line 113 in src/ErrorHandler.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.1-ubuntu-latest

Escaped Mutant for Mutator "GreaterThanNegotiation": --- Original +++ New @@ @@ if ($this->enabled) { return; } - if ($this->memoryReserveSize > 0) { + if ($this->memoryReserveSize <= 0) { $this->memoryReserve = str_repeat('x', $this->memoryReserveSize); } $this->initializeOnce();

Check warning on line 113 in src/ErrorHandler.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.1-ubuntu-latest

Escaped Mutant for Mutator "GreaterThan": --- Original +++ New @@ @@ if ($this->enabled) { return; } - if ($this->memoryReserveSize > 0) { + if ($this->memoryReserveSize >= 0) { $this->memoryReserve = str_repeat('x', $this->memoryReserveSize); } $this->initializeOnce();
$this->memoryReserve = str_repeat('x', $this->memoryReserveSize);
}

$this->initializeOnce();

Check warning on line 117 in src/ErrorHandler.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.1-ubuntu-latest

Escaped Mutant for Mutator "MethodCallRemoval": --- Original +++ New @@ @@ if ($this->memoryReserveSize > 0) { $this->memoryReserve = str_repeat('x', $this->memoryReserveSize); } - $this->initializeOnce(); + // Handles throwable that isn't caught otherwise, echo output and exit. set_exception_handler(function (Throwable $t) : void { if (!$this->enabled) {

// Handles throwable that isn't caught otherwise, echo output and exit.
set_exception_handler(function (Throwable $t): void {

Check warning on line 120 in src/ErrorHandler.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.1-ubuntu-latest

Escaped Mutant for Mutator "FunctionCallRemoval": --- Original +++ New @@ @@ $this->memoryReserve = str_repeat('x', $this->memoryReserveSize); } $this->initializeOnce(); - // Handles throwable that isn't caught otherwise, echo output and exit. - set_exception_handler(function (Throwable $t) : void { - if (!$this->enabled) { - return; - } - $this->renderThrowableAndTerminate($t); - }); + // Handles PHP execution errors such as warnings and notices. set_error_handler(function (int $severity, string $message, string $file, int $line) : bool { if (!$this->enabled) {
if (!$this->enabled) {
return;
}
Expand All @@ -129,7 +131,7 @@
return false;
}

if (!(error_reporting() & $severity)) {

Check warning on line 134 in src/ErrorHandler.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.1-ubuntu-latest

Escaped Mutant for Mutator "BitwiseAnd": --- Original +++ New @@ @@ if (!$this->enabled) { return false; } - if (!(error_reporting() & $severity)) { + if (!(error_reporting() | $severity)) { // This error code is not included in error_reporting. return true; }
// This error code is not included in error_reporting.
return true;
}
Expand All @@ -152,7 +154,7 @@
*/
public function unregister(): void
{
if (!$this->enabled) {

Check warning on line 157 in src/ErrorHandler.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.1-ubuntu-latest

Escaped Mutant for Mutator "LogicalNot": --- Original +++ New @@ @@ */ public function unregister() : void { - if (!$this->enabled) { + if ($this->enabled) { return; } $this->memoryReserve = '';
return;
}

Expand Down Expand Up @@ -190,7 +192,7 @@
$e['file'],
$e['line'],
null,
$backtrace
$backtrace,
);
$this->renderThrowableAndTerminate($error);
}
Expand Down Expand Up @@ -226,7 +228,7 @@
static function (): void {
exit(1);
},
$this->exitShutdownHandlerDepth
$this->exitShutdownHandlerDepth,
);

register_shutdown_function($handler);
Expand All @@ -244,7 +246,7 @@
{
$currentDepth = 0;
while ($currentDepth < $depth) {
$handler = static function() use ($handler): void {
$handler = static function () use ($handler): void {
register_shutdown_function($handler);
};
$currentDepth++;
Expand Down
3 changes: 1 addition & 2 deletions src/Event/ApplicationError.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ final class ApplicationError
{
public function __construct(
private readonly Throwable $throwable,
) {
}
) {}

public function getThrowable(): Throwable
{
Expand Down
18 changes: 17 additions & 1 deletion src/Exception/ErrorException.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,22 @@
use function array_slice;
use function in_array;
use function function_exists;
use function ini_get;

use const E_COMPILE_ERROR;
use const E_COMPILE_WARNING;
use const E_CORE_ERROR;
use const E_CORE_WARNING;
use const E_DEPRECATED;
use const E_ERROR;
use const E_NOTICE;
use const E_PARSE;
use const E_RECOVERABLE_ERROR;
use const E_USER_DEPRECATED;
use const E_USER_ERROR;
use const E_USER_NOTICE;
use const E_USER_WARNING;
use const E_WARNING;

/**
* `ErrorException` represents a PHP error.
Expand Down Expand Up @@ -148,6 +164,6 @@ private function isXdebugStackAvailable(): bool
}

// Xdebug 3 and later, proper mode is required
return str_contains((string) \ini_get('xdebug.mode'), 'develop');
return str_contains((string) ini_get('xdebug.mode'), 'develop');
}
}
5 changes: 2 additions & 3 deletions src/HeadersProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ final class HeadersProvider
*/
public function __construct(
private array $headers = [],
) {
}
) {}

/**
* Adds a header to the list of headers.
Expand All @@ -28,7 +27,7 @@ public function __construct(
*/
public function add(string $name, string|array $values): void
{
$this->headers[$name] = (array)$values;
$this->headers[$name] = (array) $values;
}

/**
Expand Down
3 changes: 1 addition & 2 deletions src/Middleware/ErrorCatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ final class ErrorCatcher implements MiddlewareInterface
public function __construct(
private readonly ThrowableResponseFactoryInterface $throwableResponseFactory,
private readonly ?EventDispatcherInterface $eventDispatcher = null,
) {
}
) {}

public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
{
Expand Down
3 changes: 1 addition & 2 deletions src/Middleware/ExceptionResponder.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@ public function __construct(
private readonly ResponseFactoryInterface $responseFactory,
private readonly Injector $injector,
private readonly bool $checkResponseBody = false,
) {
}
) {}

public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
{
Expand Down
3 changes: 1 addition & 2 deletions src/Renderer/HeaderRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ final class HeaderRenderer implements ThrowableRendererInterface
*/
public function __construct(
private readonly ?string $contentType = null,
) {
}
) {}

public function render(Throwable $t, ?ServerRequestInterface $request = null): ErrorData
{
Expand Down
Loading
Loading