diff --git a/.github/workflows/rector-cs.yml b/.github/workflows/rector-cs.yml
new file mode 100644
index 0000000..03b7c75
--- /dev/null
+++ b/.github/workflows/rector-cs.yml
@@ -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'
diff --git a/.github/workflows/rector.yml b/.github/workflows/rector.yml
deleted file mode 100644
index 5d6931d..0000000
--- a/.github/workflows/rector.yml
+++ /dev/null
@@ -1,24 +0,0 @@
-on:
- pull_request_target:
- paths-ignore:
- - 'docs/**'
- - 'README.md'
- - 'CHANGELOG.md'
- - '.gitignore'
- - '.gitattributes'
- - 'infection.json.dist'
- - 'psalm.xml'
-
-name: rector
-
-jobs:
- rector:
- uses: yiisoft/actions/.github/workflows/rector.yml@master
- secrets:
- token: ${{ secrets.YIISOFT_GITHUB_TOKEN }}
- with:
- repository: ${{ github.event.pull_request.head.repo.full_name }}
- os: >-
- ['ubuntu-latest']
- php: >-
- ['8.4']
diff --git a/.gitignore b/.gitignore
index efcb7f6..3c7df68 100644
--- a/.gitignore
+++ b/.gitignore
@@ -20,3 +20,7 @@ composer.lock
/phpunit.phar
/phpunit.xml
/.phpunit.cache
+
+# PHP CS Fixer
+/.php-cs-fixer.cache
+/.php-cs-fixer.php
diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php
new file mode 100644
index 0000000..7571f30
--- /dev/null
+++ b/.php-cs-fixer.dist.php
@@ -0,0 +1,35 @@
+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);
diff --git a/.styleci.yml b/.styleci.yml
deleted file mode 100644
index 1ab379b..0000000
--- a/.styleci.yml
+++ /dev/null
@@ -1,85 +0,0 @@
-preset: psr12
-risky: true
-
-version: 8.1
-
-finder:
- exclude:
- - docs
- - vendor
-
-enabled:
- - alpha_ordered_traits
- - array_indentation
- - array_push
- - combine_consecutive_issets
- - combine_consecutive_unsets
- - combine_nested_dirname
- - declare_strict_types
- - dir_constant
- - fully_qualified_strict_types
- - function_to_constant
- - hash_to_slash_comment
- - is_null
- - logical_operators
- - magic_constant_casing
- - magic_method_casing
- - method_separation
- - modernize_types_casting
- - native_function_casing
- - native_function_type_declaration_casing
- - no_alias_functions
- - no_empty_comment
- - no_empty_phpdoc
- - no_empty_statement
- - no_extra_block_blank_lines
- - no_short_bool_cast
- - no_superfluous_elseif
- - no_unneeded_control_parentheses
- - no_unneeded_curly_braces
- - no_unneeded_final_method
- - no_unset_cast
- - no_unused_imports
- - no_unused_lambda_imports
- - no_useless_else
- - no_useless_return
- - normalize_index_brace
- - php_unit_dedicate_assert
- - php_unit_dedicate_assert_internal_type
- - php_unit_expectation
- - php_unit_mock
- - php_unit_mock_short_will_return
- - php_unit_namespaced
- - php_unit_no_expectation_annotation
- - phpdoc_no_empty_return
- - phpdoc_no_useless_inheritdoc
- - phpdoc_order
- - phpdoc_property
- - phpdoc_scalar
- - phpdoc_singular_inheritdoc
- - phpdoc_trim
- - phpdoc_trim_consecutive_blank_line_separation
- - phpdoc_type_to_var
- - phpdoc_types
- - phpdoc_types_order
- - print_to_echo
- - regular_callable_call
- - return_assignment
- - self_accessor
- - self_static_accessor
- - set_type_to_cast
- - short_array_syntax
- - short_list_syntax
- - simplified_if_return
- - single_quote
- - standardize_not_equals
- - ternary_to_null_coalescing
- - trailing_comma_in_multiline_array
- - unalign_double_arrow
- - unalign_equals
- - empty_loop_body_braces
- - integer_literal_case
- - union_type_without_spaces
-
-disabled:
- - function_declaration
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 0271ea3..7059bc6 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -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
diff --git a/composer.json b/composer.json
index 8ddd554..745b7ad 100644
--- a/composer.json
+++ b/composer.json
@@ -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",
diff --git a/config/di-web.php b/config/di-web.php
index b5367a7..96c40ba 100644
--- a/config/di-web.php
+++ b/config/di-web.php
@@ -25,7 +25,7 @@
static fn(ContainerInterface $container) => new CompositeRendererProvider(
new HeadRendererProvider(),
new ContentTypeRendererProvider($container),
- )
+ ),
),
],
],
diff --git a/src/ErrorData.php b/src/ErrorData.php
index e446a57..c38d3b1 100644
--- a/src/ErrorData.php
+++ b/src/ErrorData.php
@@ -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.
diff --git a/src/ErrorHandler.php b/src/ErrorHandler.php
index b201196..e78b68c 100644
--- a/src/ErrorHandler.php
+++ b/src/ErrorHandler.php
@@ -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.
*/
@@ -50,9 +53,8 @@ public function __construct(
private readonly LoggerInterface $logger,
private readonly ThrowableRendererInterface $defaultRenderer,
private readonly ?EventDispatcherInterface $eventDispatcher = null,
- private readonly int $exitShutdownHandlerDepth = 2
- ) {
- }
+ private readonly int $exitShutdownHandlerDepth = 2,
+ ) {}
/**
* Handles throwable and returns error data.
@@ -63,7 +65,7 @@ public function __construct(
public function handle(
Throwable $t,
?ThrowableRendererInterface $renderer = null,
- ?ServerRequestInterface $request = null
+ ?ServerRequestInterface $request = null,
): ErrorData {
$renderer ??= $this->defaultRenderer;
@@ -190,7 +192,7 @@ private function initializeOnce(): void
$e['file'],
$e['line'],
null,
- $backtrace
+ $backtrace,
);
$this->renderThrowableAndTerminate($error);
}
@@ -226,7 +228,7 @@ private function renderThrowableAndTerminate(Throwable $t): void
static function (): void {
exit(1);
},
- $this->exitShutdownHandlerDepth
+ $this->exitShutdownHandlerDepth,
);
register_shutdown_function($handler);
@@ -244,7 +246,7 @@ private function wrapShutdownHandler(callable $handler, int $depth): callable
{
$currentDepth = 0;
while ($currentDepth < $depth) {
- $handler = static function() use ($handler): void {
+ $handler = static function () use ($handler): void {
register_shutdown_function($handler);
};
$currentDepth++;
diff --git a/src/Event/ApplicationError.php b/src/Event/ApplicationError.php
index 0a5fb66..3802732 100644
--- a/src/Event/ApplicationError.php
+++ b/src/Event/ApplicationError.php
@@ -13,8 +13,7 @@ final class ApplicationError
{
public function __construct(
private readonly Throwable $throwable,
- ) {
- }
+ ) {}
public function getThrowable(): Throwable
{
diff --git a/src/Exception/ErrorException.php b/src/Exception/ErrorException.php
index 5f61d77..4d48af9 100644
--- a/src/Exception/ErrorException.php
+++ b/src/Exception/ErrorException.php
@@ -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.
@@ -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');
}
}
diff --git a/src/HeadersProvider.php b/src/HeadersProvider.php
index 6cd64ef..18c5ff2 100644
--- a/src/HeadersProvider.php
+++ b/src/HeadersProvider.php
@@ -17,8 +17,7 @@ final class HeadersProvider
*/
public function __construct(
private array $headers = [],
- ) {
- }
+ ) {}
/**
* Adds a header to the list of headers.
@@ -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;
}
/**
diff --git a/src/Middleware/ErrorCatcher.php b/src/Middleware/ErrorCatcher.php
index 097e3da..6ee0973 100644
--- a/src/Middleware/ErrorCatcher.php
+++ b/src/Middleware/ErrorCatcher.php
@@ -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
{
diff --git a/src/Middleware/ExceptionResponder.php b/src/Middleware/ExceptionResponder.php
index 7af60e9..c01e331 100644
--- a/src/Middleware/ExceptionResponder.php
+++ b/src/Middleware/ExceptionResponder.php
@@ -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
{
diff --git a/src/Renderer/HeaderRenderer.php b/src/Renderer/HeaderRenderer.php
index ec65acc..08d1a2d 100644
--- a/src/Renderer/HeaderRenderer.php
+++ b/src/Renderer/HeaderRenderer.php
@@ -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
{
diff --git a/src/Renderer/HtmlRenderer.php b/src/Renderer/HtmlRenderer.php
index 0df1ef8..d9074d8 100644
--- a/src/Renderer/HtmlRenderer.php
+++ b/src/Renderer/HtmlRenderer.php
@@ -16,6 +16,9 @@
use Yiisoft\ErrorHandler\ThrowableRendererInterface;
use Yiisoft\FriendlyException\FriendlyExceptionInterface;
use Yiisoft\Http\Header;
+use ReflectionException;
+use ReflectionFunction;
+use ReflectionMethod;
use function array_values;
use function dirname;
@@ -45,6 +48,12 @@
use function str_replace;
use function stripos;
use function strlen;
+use function count;
+use function function_exists;
+
+use const DIRECTORY_SEPARATOR;
+use const ENT_QUOTES;
+use const EXTR_OVERWRITE;
/**
* Formats throwable into HTML string.
@@ -56,6 +65,25 @@ final class HtmlRenderer implements ThrowableRendererInterface
{
private const CONTENT_TYPE = 'text/html';
+ /**
+ * @var string|null The trace header line with placeholders to be substituted. Defaults to null.
+ *
+ * The placeholders are {file}, {line} and {icon}. A typical use case is the creation of IDE-specific links,
+ * since when you click on a trace header link, it opens directly in the IDE. You can also insert custom content.
+ *
+ * Example IDE link:
+ *
+ * ```
+ * {icon}
+ * ```
+ */
+ public readonly ?string $traceHeaderLine;
+
+ /**
+ * @psalm-var TraceLinkClosure
+ */
+ public readonly Closure $traceLinkGenerator;
+
private readonly GithubMarkdown $markdownParser;
/**
@@ -87,25 +115,6 @@ final class HtmlRenderer implements ThrowableRendererInterface
*/
private readonly int $maxTraceLines;
- /**
- * @var string|null The trace header line with placeholders to be substituted. Defaults to null.
- *
- * The placeholders are {file}, {line} and {icon}. A typical use case is the creation of IDE-specific links,
- * since when you click on a trace header link, it opens directly in the IDE. You can also insert custom content.
- *
- * Example IDE link:
- *
- * ```
- * {icon}
- * ```
- */
- public readonly ?string $traceHeaderLine;
-
- /**
- * @psalm-var TraceLinkClosure
- */
- public readonly Closure $traceLinkGenerator;
-
/**
* @var string[]|null The list of vendor paths is determined automatically.
*
@@ -329,11 +338,11 @@ public function renderCallStack(Throwable $t, array $trace = []): string
if (!str_contains($function, '{closure}')) {
try {
if ($class !== null && class_exists($class)) {
- $parameters = (new \ReflectionMethod($class, $function))->getParameters();
+ $parameters = (new ReflectionMethod($class, $function))->getParameters();
} elseif (function_exists($function)) {
- $parameters = (new \ReflectionFunction($function))->getParameters();
+ $parameters = (new ReflectionFunction($function))->getParameters();
}
- } catch (\ReflectionException) {
+ } catch (ReflectionException) {
// pass
}
}
@@ -453,7 +462,7 @@ public function renderRequest(ServerRequestInterface $request): string
}
}
- $body = (string)$request->getBody();
+ $body = (string) $request->getBody();
if (!empty($body)) {
$output .= "\n" . $body . "\n\n";
}
@@ -529,6 +538,13 @@ public function getThrowableName(Throwable $throwable): string
return $name;
}
+ public function removeAnonymous(string $value): string
+ {
+ $anonymousPosition = strpos($value, '@anonymous');
+
+ return $anonymousPosition !== false ? substr($value, 0, $anonymousPosition) : $value;
+ }
+
/**
* Renders a template.
*
@@ -720,13 +736,6 @@ private function getVendorPaths(): array
return $this->vendorPaths;
}
- public function removeAnonymous(string $value): string
- {
- $anonymousPosition = strpos($value, '@anonymous');
-
- return $anonymousPosition !== false ? substr($value, 0, $anonymousPosition) : $value;
- }
-
/**
* @psalm-param string|TraceLinkClosure|null $traceLink
* @psalm-return TraceLinkClosure
@@ -734,7 +743,7 @@ public function removeAnonymous(string $value): string
private function createTraceLinkGenerator(string|Closure|null $traceLink): Closure
{
if ($traceLink === null) {
- return static fn(): string|null => null;
+ return static fn(): ?string => null;
}
if (is_string($traceLink)) {
diff --git a/src/Renderer/JsonRenderer.php b/src/Renderer/JsonRenderer.php
index fa93af0..f7d83be 100644
--- a/src/Renderer/JsonRenderer.php
+++ b/src/Renderer/JsonRenderer.php
@@ -12,6 +12,12 @@
use function json_encode;
+use const JSON_INVALID_UTF8_SUBSTITUTE;
+use const JSON_PARTIAL_OUTPUT_ON_ERROR;
+use const JSON_PRETTY_PRINT;
+use const JSON_THROW_ON_ERROR;
+use const JSON_UNESCAPED_SLASHES;
+
/**
* Formats throwable into JSON string.
*/
@@ -26,7 +32,7 @@ public function render(Throwable $t, ?ServerRequestInterface $request = null): E
[
'message' => self::DEFAULT_ERROR_MESSAGE,
],
- JSON_THROW_ON_ERROR | JSON_UNESCAPED_SLASHES
+ JSON_THROW_ON_ERROR | JSON_UNESCAPED_SLASHES,
),
[Header::CONTENT_TYPE => self::CONTENT_TYPE],
);
@@ -44,7 +50,7 @@ public function renderVerbose(Throwable $t, ?ServerRequestInterface $request = n
'line' => $t->getLine(),
'trace' => $t->getTrace(),
],
- JSON_THROW_ON_ERROR | JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_INVALID_UTF8_SUBSTITUTE | JSON_PARTIAL_OUTPUT_ON_ERROR
+ JSON_THROW_ON_ERROR | JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_INVALID_UTF8_SUBSTITUTE | JSON_PARTIAL_OUTPUT_ON_ERROR,
),
[Header::CONTENT_TYPE => self::CONTENT_TYPE],
);
diff --git a/src/Renderer/PlainTextRenderer.php b/src/Renderer/PlainTextRenderer.php
index 8856e0e..d4334ac 100644
--- a/src/Renderer/PlainTextRenderer.php
+++ b/src/Renderer/PlainTextRenderer.php
@@ -19,8 +19,7 @@ final class PlainTextRenderer implements ThrowableRendererInterface
{
public function __construct(
private readonly string $contentType = 'text/plain',
- ) {
- }
+ ) {}
public function render(Throwable $t, ?ServerRequestInterface $request = null): ErrorData
{
@@ -53,7 +52,7 @@ public static function throwableToString(Throwable $t): string
$t->getMessage(),
$t->getFile(),
$t->getLine(),
- $t->getTraceAsString()
+ $t->getTraceAsString(),
);
}
}
diff --git a/src/RendererProvider/ClosureRendererProvider.php b/src/RendererProvider/ClosureRendererProvider.php
index 1eafa59..705ad1e 100644
--- a/src/RendererProvider/ClosureRendererProvider.php
+++ b/src/RendererProvider/ClosureRendererProvider.php
@@ -24,8 +24,7 @@ final class ClosureRendererProvider implements RendererProviderInterface
public function __construct(
private readonly Closure $closure,
private readonly ContainerInterface $container,
- ) {
- }
+ ) {}
public function get(ServerRequestInterface $request): ?ThrowableRendererInterface
{
diff --git a/tests/CompositeExceptionTest.php b/tests/CompositeExceptionTest.php
index 78f7e90..606377e 100644
--- a/tests/CompositeExceptionTest.php
+++ b/tests/CompositeExceptionTest.php
@@ -5,14 +5,16 @@
namespace Yiisoft\ErrorHandler\Tests;
use PHPUnit\Framework\TestCase;
+use Yiisoft\ErrorHandler\CompositeException;
+use Exception;
final class CompositeExceptionTest extends TestCase
{
public function testExceptions()
{
- $exception1 = new \Exception('Exception 1', 123, new \Exception('Previous exception'));
- $exception2 = new \Exception('Exception 2');
- $exception = new \Yiisoft\ErrorHandler\CompositeException(
+ $exception1 = new Exception('Exception 1', 123, new Exception('Previous exception'));
+ $exception2 = new Exception('Exception 2');
+ $exception = new CompositeException(
$exception1,
$exception2,
);
@@ -26,8 +28,8 @@ public function testExceptions()
public function testOnlyOneException()
{
- $exception1 = new \Exception('Exception 1', 123, new \Exception('Previous exception'));
- $exception = new \Yiisoft\ErrorHandler\CompositeException($exception1);
+ $exception1 = new Exception('Exception 1', 123, new Exception('Previous exception'));
+ $exception = new CompositeException($exception1);
$this->assertSame('Exception 1', $exception->getMessage());
$this->assertSame(123, $exception->getCode());
diff --git a/tests/ConfigTest.php b/tests/ConfigTest.php
index 838edf0..4863285 100644
--- a/tests/ConfigTest.php
+++ b/tests/ConfigTest.php
@@ -10,6 +10,8 @@
use Yiisoft\ErrorHandler\Renderer\HtmlRenderer;
use Yiisoft\ErrorHandler\ThrowableRendererInterface;
+use function dirname;
+
final class ConfigTest extends TestCase
{
public function testDiWeb(): void
@@ -25,8 +27,8 @@ private function createContainer(?string $postfix = null): Container
{
return new Container(
ContainerConfig::create()->withDefinitions(
- $this->getDiConfig($postfix)
- )
+ $this->getDiConfig($postfix),
+ ),
);
}
diff --git a/tests/Exception/UserException/NotFoundException.php b/tests/Exception/UserException/NotFoundException.php
index 15731b7..6b11004 100644
--- a/tests/Exception/UserException/NotFoundException.php
+++ b/tests/Exception/UserException/NotFoundException.php
@@ -8,6 +8,4 @@
use Yiisoft\ErrorHandler\Exception\UserException;
#[UserException]
-final class NotFoundException extends Exception
-{
-}
+final class NotFoundException extends Exception {}
diff --git a/tests/Middleware/ErrorCatcherTest.php b/tests/Middleware/ErrorCatcherTest.php
index e274aa8..1d4931c 100644
--- a/tests/Middleware/ErrorCatcherTest.php
+++ b/tests/Middleware/ErrorCatcherTest.php
@@ -24,7 +24,7 @@ public function testSuccess(): void
$errorCatcher = new ErrorCatcher(
$this->createThrowableResponseFactory(),
);
- $handler = new class () implements RequestHandlerInterface {
+ $handler = new class implements RequestHandlerInterface {
public function handle(ServerRequestInterface $request): ResponseInterface
{
return new Response();
@@ -32,7 +32,7 @@ public function handle(ServerRequestInterface $request): ResponseInterface
};
$response = $errorCatcher->process(
new ServerRequest(),
- $handler
+ $handler,
);
$this->assertSame(200, $response->getStatusCode());
@@ -68,7 +68,7 @@ public function testErrorWithEventDispatcher(): void
private function createThrowableResponseFactory(): ThrowableResponseFactoryInterface
{
- return new class () implements ThrowableResponseFactoryInterface {
+ return new class implements ThrowableResponseFactoryInterface {
public function create(Throwable $throwable, ServerRequestInterface $request): ResponseInterface
{
return new Response(Status::INTERNAL_SERVER_ERROR);
@@ -78,7 +78,7 @@ public function create(Throwable $throwable, ServerRequestInterface $request): R
private function createRequestHandlerWithThrowable(): RequestHandlerInterface
{
- return new class () implements RequestHandlerInterface {
+ return new class implements RequestHandlerInterface {
public function handle(ServerRequestInterface $request): ResponseInterface
{
throw new RuntimeException();
diff --git a/tests/Middleware/ExceptionResponderTest.php b/tests/Middleware/ExceptionResponderTest.php
index b669052..b0d36e3 100644
--- a/tests/Middleware/ExceptionResponderTest.php
+++ b/tests/Middleware/ExceptionResponderTest.php
@@ -44,15 +44,15 @@ public function testCallable(): void
{
$request = new ServerRequest(headers: ['X-TEST' => ['HELLO']]);
$middleware = $this->createMiddleware([
- DomainException::class =>
- static function (ResponseFactoryInterface $responseFactory, ServerRequestInterface $request) {
+ DomainException::class
+ => static function (ResponseFactoryInterface $responseFactory, ServerRequestInterface $request) {
return $responseFactory->createResponse(Status::CREATED, $request->getHeaderLine('X-TEST'));
},
]);
$response = $middleware->process(
$request,
- new class () implements RequestHandlerInterface {
+ new class implements RequestHandlerInterface {
public function handle(ServerRequestInterface $request): ResponseInterface
{
throw new DomainException();
@@ -78,10 +78,10 @@ public function testCheckResponseBody(): void
{
$middleware = $this->createMiddleware(checkResponseBody: true);
$request = (new ServerRequestFactory())->createServerRequest(Method::GET, 'http://example.com');
- $handler = new class () implements RequestHandlerInterface {
+ $handler = new class implements RequestHandlerInterface {
public function handle(ServerRequestInterface $request): ResponseInterface
{
- return new class () implements ResponseInterface {
+ return new class implements ResponseInterface {
use ResponseTrait;
public function getBody(): StreamInterface
@@ -101,7 +101,7 @@ public function testSuccess(): void
{
$middleware = $this->createMiddleware(checkResponseBody: true);
$request = (new ServerRequestFactory())->createServerRequest(Method::GET, 'http://example.com');
- $handler = new class () implements RequestHandlerInterface {
+ $handler = new class implements RequestHandlerInterface {
public function handle(ServerRequestInterface $request): ResponseInterface
{
return new Response();
@@ -117,12 +117,12 @@ private function process(ExceptionResponder $middleware): ResponseInterface
{
return $middleware->process(
(new ServerRequestFactory())->createServerRequest(Method::GET, 'http://example.com'),
- new class () implements RequestHandlerInterface {
+ new class implements RequestHandlerInterface {
public function handle(ServerRequestInterface $request): ResponseInterface
{
throw new DomainException();
}
- }
+ },
);
}
diff --git a/tests/Renderer/HtmlRendererTest.php b/tests/Renderer/HtmlRendererTest.php
index 7cfdd33..2304231 100644
--- a/tests/Renderer/HtmlRendererTest.php
+++ b/tests/Renderer/HtmlRendererTest.php
@@ -21,6 +21,9 @@
use function file_put_contents;
use function fopen;
use function unlink;
+use function sprintf;
+
+use const DIRECTORY_SEPARATOR;
final class HtmlRendererTest extends TestCase
{
@@ -139,7 +142,7 @@ public function testRenderCallStackItemIfFileIsNotExistAndLineMoreZero(): void
set_error_handler(
static function (int $code, string $message) use (&$errorMessage) {
$errorMessage = $message;
- }
+ },
);
$result = $this->invokeMethod(new HtmlRenderer(), 'renderCallStackItem', [
'file' => 'not-exist',
@@ -164,7 +167,7 @@ public function testRenderRequest(): void
$this->assertSame(
"GET https:/example.com\nAccept: text/html\n",
- $output
+ $output,
);
}
@@ -308,7 +311,7 @@ public static function dataTraceLinkGenerator(): iterable
yield [null, static fn() => null];
yield [
'phpstorm://open?file=test.php&line=42',
- static fn(string $file, int|null $line) => "phpstorm://open?file=$file&line=$line",
+ static fn(string $file, ?int $line) => "phpstorm://open?file=$file&line=$line",
];
yield [
'phpstorm://open?file=test.php&line=42',
@@ -324,10 +327,10 @@ public static function dataTraceLinkGenerator(): iterable
#[DataProvider('dataTraceLinkGenerator')]
public function testTraceLinkGenerator(
- string|null $expected,
+ ?string $expected,
mixed $traceLink,
string $file = 'test.php',
- int|null $line = 42,
+ ?int $line = 42,
): void {
$renderer = new HtmlRenderer(traceLink: $traceLink);
@@ -358,7 +361,7 @@ private function createServerRequestMock(): ServerRequestInterface
[
'Accept' => $acceptHeader,
'Host' => $hostHeader,
- ]
+ ],
);
$serverRequestMock
diff --git a/tests/Renderer/JsonRendererTest.php b/tests/Renderer/JsonRendererTest.php
index 690faf1..65dcf03 100644
--- a/tests/Renderer/JsonRendererTest.php
+++ b/tests/Renderer/JsonRendererTest.php
@@ -7,11 +7,19 @@
use PHPUnit\Framework\TestCase;
use RuntimeException;
use Yiisoft\ErrorHandler\Renderer\JsonRenderer;
+use JsonException;
+use Throwable;
use function json_encode;
use function md5;
use function pack;
+use const JSON_INVALID_UTF8_SUBSTITUTE;
+use const JSON_PARTIAL_OUTPUT_ON_ERROR;
+use const JSON_PRETTY_PRINT;
+use const JSON_THROW_ON_ERROR;
+use const JSON_UNESCAPED_SLASHES;
+
final class JsonRendererTest extends TestCase
{
public function testRender(): void
@@ -19,7 +27,7 @@ public function testRender(): void
$renderer = new JsonRenderer();
$data = $renderer->render(new RuntimeException());
- $this->assertSame(json_encode(['message' => JsonRenderer::DEFAULT_ERROR_MESSAGE]), (string)$data);
+ $this->assertSame(json_encode(['message' => JsonRenderer::DEFAULT_ERROR_MESSAGE]), (string) $data);
}
public function testRenderVerbose(): void
@@ -36,7 +44,7 @@ public function testRenderVerbose(): void
'trace' => $throwable->getTrace(),
], JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
- $this->assertSame($content, (string)$data);
+ $this->assertSame($content, (string) $data);
}
public function testRenderVerboseWithNotUtf8String(): void
@@ -53,7 +61,7 @@ public function testRenderVerboseWithNotUtf8String(): void
'trace' => $throwable->getTrace(),
], JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_INVALID_UTF8_SUBSTITUTE);
- $this->assertSame($content, (string)$data);
+ $this->assertSame($content, (string) $data);
}
public function testRenderVerboseWithJsonRecursion(): void
@@ -62,7 +70,7 @@ public function testRenderVerboseWithJsonRecursion(): void
try {
json_encode(
- new class () {
+ new class {
public self $self;
public function __construct()
@@ -70,23 +78,23 @@ public function __construct()
$this->self = $this;
}
},
- JSON_THROW_ON_ERROR
+ JSON_THROW_ON_ERROR,
);
- } catch (\Throwable $throwable) {
+ } catch (Throwable $throwable) {
$data = $renderer->renderVerbose($throwable);
$content = json_encode(
[
- 'type' => \JsonException::class,
+ 'type' => JsonException::class,
'message' => $throwable->getMessage(),
'code' => $throwable->getCode(),
'file' => $throwable->getFile(),
'line' => $throwable->getLine(),
'trace' => $throwable->getTrace(),
],
- JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_INVALID_UTF8_SUBSTITUTE | JSON_PARTIAL_OUTPUT_ON_ERROR
+ JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_INVALID_UTF8_SUBSTITUTE | JSON_PARTIAL_OUTPUT_ON_ERROR,
);
}
- $this->assertSame($content, (string)$data);
+ $this->assertSame($content, (string) $data);
}
}
diff --git a/tests/Renderer/PlainTextRendererTest.php b/tests/Renderer/PlainTextRendererTest.php
index ae8a859..a630260 100644
--- a/tests/Renderer/PlainTextRendererTest.php
+++ b/tests/Renderer/PlainTextRendererTest.php
@@ -10,6 +10,7 @@
use Yiisoft\ErrorHandler\Renderer\PlainTextRenderer;
use function PHPUnit\Framework\assertSame;
+use function sprintf;
final class PlainTextRendererTest extends TestCase
{
@@ -38,7 +39,7 @@ public function testRenderVerbose(): void
$throwable->getMessage(),
$throwable->getFile(),
$throwable->getLine(),
- $throwable->getTraceAsString()
+ $throwable->getTraceAsString(),
);
$data = $renderer->renderVerbose($throwable);
diff --git a/tests/ThrowableResponseFactoryTest.php b/tests/ThrowableResponseFactoryTest.php
index ed5d045..cd0451e 100644
--- a/tests/ThrowableResponseFactoryTest.php
+++ b/tests/ThrowableResponseFactoryTest.php
@@ -55,7 +55,7 @@ public function testHeaders(): void
new ContentTypeRendererProvider(
new SimpleContainer(),
),
- new HeadersProvider(['X-Test' => ['on'], 'X-Test-Custom' => 'hello'])
+ new HeadersProvider(['X-Test' => ['on'], 'X-Test-Custom' => 'hello']),
);
$response = $factory->create(