From 754b6ecded0a9690164cdd565e6df9ca8a4281b8 Mon Sep 17 00:00:00 2001 From: Sergei Predvoditelev Date: Thu, 30 Jul 2026 12:11:25 +0300 Subject: [PATCH 1/2] Replace StyleCI to PHP CS Fixer --- .github/workflows/rector-cs.yml | 27 ++++++ .github/workflows/rector.yml | 26 ------ .php-cs-fixer.dist.php | 23 +++++ .styleci.yml | 85 ------------------ composer.json | 4 + config/di-providers-web.php | 2 +- config/di-web.php | 6 +- config/params.php | 7 +- config/routes.php | 8 +- rector.php | 7 +- runtime/.gitignore | 2 + src/Debug/Controller/DebugController.php | 90 ++++++++++--------- src/Debug/Exception/NotFoundException.php | 6 +- .../PackageNotInstalledException.php | 4 +- src/Debug/Http/HttpApplicationWrapper.php | 7 +- src/Debug/Http/RouteCollectorWrapper.php | 3 +- src/Debug/Middleware/DebugHeaders.php | 3 +- .../MiddlewareDispatcherMiddleware.php | 5 +- src/Debug/Middleware/ResponseDataWrapper.php | 12 ++- src/Debug/ModuleFederationAssetBundle.php | 4 +- src/Debug/Provider/DebugApiProvider.php | 4 +- src/Debug/Repository/CollectorRepository.php | 10 +-- .../CollectorRepositoryInterface.php | 2 +- src/Inspector/Command/BashCommand.php | 5 +- src/Inspector/Command/CodeceptionCommand.php | 11 +-- src/Inspector/Command/PHPUnitCommand.php | 11 +-- src/Inspector/Command/PsalmCommand.php | 11 +-- src/Inspector/CommandResponse.php | 3 +- src/Inspector/Controller/CacheController.php | 9 +- .../Controller/CommandController.php | 16 ++-- .../Controller/ComposerController.php | 16 ++-- src/Inspector/Controller/GitController.php | 19 ++-- .../Controller/InspectController.php | 58 ++++++------ .../Controller/OpcacheController.php | 9 +- .../Database/Cycle/CycleSchemaProvider.php | 4 +- .../Database/Db/DbSchemaProvider.php | 4 +- .../Test/CodeceptionJSONReporter.php | 21 +++-- src/Inspector/Test/PHPUnitJSONReporter.php | 17 ++-- src/ServerSentEventsStream.php | 25 +++--- tests/Support/StubCollector.php | 12 +-- .../Debug/Middleware/DebugHeadersTest.php | 4 +- .../Middleware/ResponseDataWrapperTest.php | 8 +- .../Repository/CollectorRepositoryTest.php | 8 +- .../Inspector/Command/BashCommandTest.php | 2 + .../Database/DbSchemaProviderTest.php | 2 +- 45 files changed, 290 insertions(+), 332 deletions(-) create mode 100644 .github/workflows/rector-cs.yml delete mode 100644 .github/workflows/rector.yml create mode 100644 .php-cs-fixer.dist.php delete mode 100644 .styleci.yml create mode 100644 runtime/.gitignore diff --git a/.github/workflows/rector-cs.yml b/.github/workflows/rector-cs.yml new file mode 100644 index 0000000..ff90320 --- /dev/null +++ b/.github/workflows/rector-cs.yml @@ -0,0 +1,27 @@ +name: Rector + PHP CS Fixer + +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.1' diff --git a/.github/workflows/rector.yml b/.github/workflows/rector.yml deleted file mode 100644 index ce2d17f..0000000 --- a/.github/workflows/rector.yml +++ /dev/null @@ -1,26 +0,0 @@ -on: - pull_request: - paths-ignore: - - 'docs/**' - - 'README.md' - - 'CHANGELOG.md' - - '.gitignore' - - '.gitattributes' - - 'infection.json.dist' - - 'psalm.xml' - -name: rector - -permissions: - contents: read - -jobs: - rector: - permissions: - contents: write # Required by the reusable Rector workflow to commit changes back to PR branches. - uses: yiisoft/actions/.github/workflows/rector.yml@master - with: - os: >- - ['ubuntu-latest'] - php: >- - ['8.4'] diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php new file mode 100644 index 0000000..5016848 --- /dev/null +++ b/.php-cs-fixer.dist.php @@ -0,0 +1,23 @@ +in([ + __DIR__ . '/config', + __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); 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/composer.json b/composer.json index 792d0ea..d1beee3 100644 --- a/composer.json +++ b/composer.json @@ -62,6 +62,7 @@ }, "require-dev": { "codeception/codeception": "^5.0", + "friendsofphp/php-cs-fixer": "^3.95", "maglnet/composer-require-checker": "^4.2", "phpunit/phpunit": "^10.5", "rector/rector": "^2.1.1", @@ -70,6 +71,7 @@ "vimeo/psalm": "^5.15 || ^6.12", "yiisoft/active-record": "dev-master", "yiisoft/assets": "^5.1", + "yiisoft/code-style": "^1.1", "yiisoft/csrf": "^2.0", "yiisoft/db": "1.2 as dev-master", "yiisoft/db-sqlite": "^1.0", @@ -110,6 +112,8 @@ } }, "scripts": { + "cs-fix": "php-cs-fixer fix", + "rector": "rector", "test": "phpunit --testdox --no-interaction", "test-watch": "phpunit-watcher watch" }, diff --git a/config/di-providers-web.php b/config/di-providers-web.php index b72d912..a5b83b8 100644 --- a/config/di-providers-web.php +++ b/config/di-providers-web.php @@ -4,7 +4,7 @@ use Yiisoft\Yii\Debug\Api\Debug\Provider\DebugApiProvider; -if (!(bool)($params['yiisoft/yii-debug-api']['enabled'] ?? false)) { +if (!(bool) ($params['yiisoft/yii-debug-api']['enabled'] ?? false)) { return []; } diff --git a/config/di-web.php b/config/di-web.php index 1e17aec..1a73234 100644 --- a/config/di-web.php +++ b/config/di-web.php @@ -19,7 +19,7 @@ */ return [ - CollectorRepositoryInterface::class => static fn (StorageInterface $storage) => new CollectorRepository($storage), + CollectorRepositoryInterface::class => static fn(StorageInterface $storage) => new CollectorRepository($storage), SchemaProviderInterface::class => function (ContainerInterface $container) { if ($container->has(DatabaseProviderInterface::class)) { return $container->get(CycleSchemaProvider::class); @@ -30,10 +30,10 @@ } throw new LogicException( - sprintf( + \sprintf( 'Inspecting database is not available. Configure "%s" service to be able to inspect database.', ConnectionInterface::class, - ) + ), ); }, HttpApplicationWrapper::class => [ diff --git a/config/params.php b/config/params.php index 5351837..0ba451a 100644 --- a/config/params.php +++ b/config/params.php @@ -7,9 +7,10 @@ use Yiisoft\Yii\Debug\Api\Inspector\Command\CodeceptionCommand; use Yiisoft\Yii\Debug\Api\Inspector\Command\PHPUnitCommand; use Yiisoft\Yii\Debug\Api\Inspector\Command\PsalmCommand; +use PHPUnit\Framework\Test; $testCommands = []; -if (class_exists(PHPUnit\Framework\Test::class)) { +if (class_exists(Test::class)) { $testCommands[PHPUnitCommand::COMMAND_NAME] = PHPUnitCommand::class; } if (class_exists(Extension::class)) { @@ -41,8 +42,8 @@ ], 'yiisoft/yii-swagger' => [ 'annotation-paths' => [ - dirname(__DIR__) . '/src/Debug/Controller', - dirname(__DIR__) . '/src/Debug/Middleware', + \dirname(__DIR__) . '/src/Debug/Controller', + \dirname(__DIR__) . '/src/Debug/Middleware', ], ], ]; diff --git a/config/routes.php b/config/routes.php index eadac30..42c03ee 100644 --- a/config/routes.php +++ b/config/routes.php @@ -32,9 +32,9 @@ static function (ResponseFactoryInterface $responseFactory, ValidatorInterface $ return new IpFilter( validator: $validator, responseFactory: $responseFactory, - ipRanges: $params['yiisoft/yii-debug-api']['allowedIPs'] + ipRanges: $params['yiisoft/yii-debug-api']['allowedIPs'], ); - } + }, ) ->middleware(FormatDataResponseAsJson::class) ->middleware(ResponseDataWrapper::class) @@ -67,9 +67,9 @@ static function (ResponseFactoryInterface $responseFactory, ValidatorInterface $ return new IpFilter( validator: $validator, responseFactory: $responseFactory, - ipRanges: $params['yiisoft/yii-debug-api']['allowedIPs'] + ipRanges: $params['yiisoft/yii-debug-api']['allowedIPs'], ); - } + }, ) ->middleware(FormatDataResponseAsJson::class) ->middleware(ResponseDataWrapper::class) diff --git a/rector.php b/rector.php index 54537c2..348db8d 100644 --- a/rector.php +++ b/rector.php @@ -2,20 +2,21 @@ declare(strict_types=1); -use Rector\CodeQuality\Rector\Class_\InlineConstructorDefaultToPropertyRector; use Rector\Config\RectorConfig; use Rector\Php74\Rector\Closure\ClosureToArrowFunctionRector; use Rector\Php81\Rector\Property\ReadOnlyPropertyRector; use Rector\Php81\Rector\FuncCall\NullToStrictStringFuncCallArgRector; +use Yiisoft\CodeStyle\Rector\SetList; return RectorConfig::configure() ->withPaths([ + __DIR__ . '/config', __DIR__ . '/src', __DIR__ . '/tests', ]) ->withPhpSets(php81: true) - ->withRules([ - InlineConstructorDefaultToPropertyRector::class, + ->withSets([ + SetList::YII_CORE, ]) ->withSkip([ ClosureToArrowFunctionRector::class, diff --git a/runtime/.gitignore b/runtime/.gitignore new file mode 100644 index 0000000..d6b7ef3 --- /dev/null +++ b/runtime/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore diff --git a/src/Debug/Controller/DebugController.php b/src/Debug/Controller/DebugController.php index a6b8ae1..aaf7eb2 100644 --- a/src/Debug/Controller/DebugController.php +++ b/src/Debug/Controller/DebugController.php @@ -26,20 +26,24 @@ use Yiisoft\Yii\View\Renderer\ViewRenderer; use OpenApi\Attributes as OA; +use function dirname; +use function sprintf; + +use const JSON_THROW_ON_ERROR; + /** * Debug controller provides endpoints that expose information about requests processed that debugger collected. */ #[OA\Tag( name: 'yii-debug-api', - description: 'Yii Debug API' + description: 'Yii Debug API', )] final class DebugController { public function __construct( private DataResponseFactoryInterface $responseFactory, - private CollectorRepositoryInterface $collectorRepository - ) { - } + private CollectorRepositoryInterface $collectorRepository, + ) {} /** * List of requests processed. @@ -55,10 +59,10 @@ public function __construct( content: new OA\JsonContent( allOf: [ new OA\Schema(ref: '#/components/schemas/DebugSuccessResponse'), - ] - ) + ], + ), ), - ] + ], )] public function index(): ResponseInterface { @@ -79,8 +83,8 @@ public function index(): ResponseInterface content: new OA\JsonContent( allOf: [ new OA\Schema(ref: '#/components/schemas/DebugSuccessResponse'), - ] - ) + ], + ), ), new OA\Response( response: '404', @@ -88,8 +92,8 @@ public function index(): ResponseInterface content: new OA\JsonContent( allOf: [ new OA\Schema(ref: '#/components/schemas/DebugNotFoundResponse'), - ] - ) + ], + ), ), ], parameters: [ @@ -99,9 +103,9 @@ public function index(): ResponseInterface in: 'path', parameter: 'id', description: 'Request ID for getting the summary', - schema: new OA\Schema(type: 'string') + schema: new OA\Schema(type: 'string'), ), - ] + ], )] public function summary(CurrentRoute $currentRoute): ResponseInterface { @@ -123,8 +127,8 @@ public function summary(CurrentRoute $currentRoute): ResponseInterface content: new OA\JsonContent( allOf: [ new OA\Schema(ref: '#/components/schemas/DebugSuccessResponse'), - ] - ) + ], + ), ), new OA\Response( response: '404', @@ -132,8 +136,8 @@ public function summary(CurrentRoute $currentRoute): ResponseInterface content: new OA\JsonContent( allOf: [ new OA\Schema(ref: '#/components/schemas/DebugNotFoundResponse'), - ] - ) + ], + ), ), ], parameters: [ @@ -143,7 +147,7 @@ public function summary(CurrentRoute $currentRoute): ResponseInterface in: 'path', parameter: 'id', description: 'Request ID for getting the summary', - schema: new OA\Schema(type: 'string') + schema: new OA\Schema(type: 'string'), ), new OA\Parameter( name: 'collector', @@ -151,9 +155,9 @@ public function summary(CurrentRoute $currentRoute): ResponseInterface parameter: 'collector', description: 'Collector for getting the detail information', schema: new OA\Schema(type: 'string'), - allowEmptyValue: true + allowEmptyValue: true, ), - ] + ], )] public function view( CurrentRoute $currentRoute, @@ -161,13 +165,13 @@ public function view( ContainerInterface $container, ): ResponseInterface { $data = $this->collectorRepository->getDetail( - $currentRoute->getArgument('id') + $currentRoute->getArgument('id'), ); $collectorClass = $serverRequest->getQueryParams()['collector'] ?? null; if ($collectorClass !== null) { $data = $data[$collectorClass] ?? throw new NotFoundException( - sprintf("Requested collector doesn't exist: %s.", $collectorClass) + sprintf("Requested collector doesn't exist: %s.", $collectorClass), ); } if (is_subclass_of($collectorClass, HtmlViewProviderInterface::class)) { @@ -197,8 +201,8 @@ public function view( content: new OA\JsonContent( allOf: [ new OA\Schema(ref: '#/components/schemas/DebugSuccessResponse'), - ] - ) + ], + ), ), new OA\Response( response: '404', @@ -206,8 +210,8 @@ public function view( content: new OA\JsonContent( allOf: [ new OA\Schema(ref: '#/components/schemas/DebugNotFoundResponse'), - ] - ) + ], + ), ), ], parameters: [ @@ -217,7 +221,7 @@ public function view( in: 'path', parameter: 'id', description: 'Request ID for getting the dump information', - schema: new OA\Schema(type: 'string') + schema: new OA\Schema(type: 'string'), ), new OA\Parameter( name: 'collector', @@ -226,14 +230,14 @@ public function view( parameter: 'collector', description: 'Collector for getting the dump information', schema: new OA\Schema(type: 'string'), - allowEmptyValue: true + allowEmptyValue: true, ), - ] + ], )] public function dump(CurrentRoute $currentRoute): ResponseInterface { $data = $this->collectorRepository->getDumpObject( - $currentRoute->getArgument('id') + $currentRoute->getArgument('id'), ); if ($currentRoute->getArgument('collector') !== null) { @@ -263,8 +267,8 @@ public function dump(CurrentRoute $currentRoute): ResponseInterface content: new OA\JsonContent( allOf: [ new OA\Schema(ref: '#/components/schemas/DebugSuccessResponse'), - ] - ) + ], + ), ), new OA\Response( response: '404', @@ -272,8 +276,8 @@ public function dump(CurrentRoute $currentRoute): ResponseInterface content: new OA\JsonContent( allOf: [ new OA\Schema(ref: '#/components/schemas/DebugNotFoundResponse'), - ] - ) + ], + ), ), ], parameters: [ @@ -283,7 +287,7 @@ public function dump(CurrentRoute $currentRoute): ResponseInterface in: 'path', parameter: 'id', description: 'Request ID for getting the object information', - schema: new OA\Schema(type: 'string') + schema: new OA\Schema(type: 'string'), ), new OA\Parameter( name: 'objectId', @@ -291,15 +295,15 @@ public function dump(CurrentRoute $currentRoute): ResponseInterface in: 'path', parameter: 'objectId', description: 'ID for getting the object information', - schema: new OA\Schema(type: 'string') + schema: new OA\Schema(type: 'string'), ), - ] + ], )] public function object(CurrentRoute $currentRoute): ResponseInterface { $data = $this->collectorRepository->getObject( $currentRoute->getArgument('id'), - $currentRoute->getArgument('objectId') + $currentRoute->getArgument('objectId'), ); if (null === $data) { @@ -314,7 +318,7 @@ public function object(CurrentRoute $currentRoute): ResponseInterface public function eventStream( StorageInterface $storage, - ResponseFactoryInterface $responseFactory + ResponseFactoryInterface $responseFactory, ): ResponseInterface { // TODO implement OS signal handling $compareFunction = static function () use ($storage) { @@ -359,7 +363,7 @@ public function eventStream( sleep(1); return true; - }) + }), ); } @@ -377,7 +381,7 @@ public function eventStream( private function createJsPanelResponse( ContainerInterface $container, string $collectorClass, - mixed $data + mixed $data, ): DataResponse { $asset = $collectorClass::getAsset(); $module = $asset->getModule(); @@ -437,7 +441,7 @@ private function createJsPanelResponse( private function createHtmlPanelResponse( ContainerInterface $container, string $collectorClass, - mixed $data + mixed $data, ): DataResponse { if (!class_exists(ViewRenderer::class) || !$container->has(ViewRenderer::class)) { /** @@ -448,7 +452,7 @@ private function createHtmlPanelResponse( sprintf( '"%s" is not defined in the dependency container.', ViewRenderer::class, - ) + ), ); } $viewRenderer = $container->get(ViewRenderer::class); diff --git a/src/Debug/Exception/NotFoundException.php b/src/Debug/Exception/NotFoundException.php index 62b79ba..1de2ab4 100644 --- a/src/Debug/Exception/NotFoundException.php +++ b/src/Debug/Exception/NotFoundException.php @@ -4,6 +4,6 @@ namespace Yiisoft\Yii\Debug\Api\Debug\Exception; -final class NotFoundException extends \Exception -{ -} +use Exception; + +final class NotFoundException extends Exception {} diff --git a/src/Debug/Exception/PackageNotInstalledException.php b/src/Debug/Exception/PackageNotInstalledException.php index a6ccfab..5b3b945 100644 --- a/src/Debug/Exception/PackageNotInstalledException.php +++ b/src/Debug/Exception/PackageNotInstalledException.php @@ -8,13 +8,15 @@ use Throwable; use Yiisoft\FriendlyException\FriendlyExceptionInterface; +use function sprintf; + final class PackageNotInstalledException extends Exception implements FriendlyExceptionInterface { public function __construct( private string $packageName, string $message = '', int $code = 0, - ?Throwable $previous = null + ?Throwable $previous = null, ) { parent::__construct($message, $code, $previous); } diff --git a/src/Debug/Http/HttpApplicationWrapper.php b/src/Debug/Http/HttpApplicationWrapper.php index 8ca0782..15e3f4b 100644 --- a/src/Debug/Http/HttpApplicationWrapper.php +++ b/src/Debug/Http/HttpApplicationWrapper.php @@ -14,8 +14,7 @@ final class HttpApplicationWrapper public function __construct( private MiddlewareDispatcher $middlewareDispatcher, private array $middlewareDefinitions, - ) { - } + ) {} public function wrap(Application $application): void { @@ -26,12 +25,12 @@ public function wrap(Application $application): void /** * @psalm-suppress InaccessibleProperty */ - static fn (Application $application) => $application->dispatcher = $middlewareDispatcher->withMiddlewares([ + static fn(Application $application) => $application->dispatcher = $middlewareDispatcher->withMiddlewares([ ...$middlewareDefinitions, ['class' => MiddlewareDispatcherMiddleware::class, '$middlewareDispatcher' => $application->dispatcher], ]), null, - $application + $application, ); $closure($application); diff --git a/src/Debug/Http/RouteCollectorWrapper.php b/src/Debug/Http/RouteCollectorWrapper.php index c31fe75..1292412 100644 --- a/src/Debug/Http/RouteCollectorWrapper.php +++ b/src/Debug/Http/RouteCollectorWrapper.php @@ -10,8 +10,7 @@ final class RouteCollectorWrapper { public function __construct( private array $middlewareDefinitions, - ) { - } + ) {} public function wrap(RouteCollectorInterface $routeCollector): void { diff --git a/src/Debug/Middleware/DebugHeaders.php b/src/Debug/Middleware/DebugHeaders.php index 9a3cd0e..af36661 100644 --- a/src/Debug/Middleware/DebugHeaders.php +++ b/src/Debug/Middleware/DebugHeaders.php @@ -20,8 +20,7 @@ final class DebugHeaders implements MiddlewareInterface public function __construct( private UrlGeneratorInterface $urlGenerator, private ?Debugger $debugger = null, - ) { - } + ) {} public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface { diff --git a/src/Debug/Middleware/MiddlewareDispatcherMiddleware.php b/src/Debug/Middleware/MiddlewareDispatcherMiddleware.php index 4cdaf74..61c1644 100644 --- a/src/Debug/Middleware/MiddlewareDispatcherMiddleware.php +++ b/src/Debug/Middleware/MiddlewareDispatcherMiddleware.php @@ -13,9 +13,8 @@ final class MiddlewareDispatcherMiddleware implements MiddlewareInterface { public function __construct( - public MiddlewareDispatcher $middlewareDispatcher - ) { - } + public MiddlewareDispatcher $middlewareDispatcher, + ) {} public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface { diff --git a/src/Debug/Middleware/ResponseDataWrapper.php b/src/Debug/Middleware/ResponseDataWrapper.php index 683d5b2..c1a948e 100644 --- a/src/Debug/Middleware/ResponseDataWrapper.php +++ b/src/Debug/Middleware/ResponseDataWrapper.php @@ -19,32 +19,30 @@ #[OA\Schema( schema: 'DebugSuccessResponse', allOf: [ - new OA\Schema(ref:'#/components/schemas/DebugResponse'), + new OA\Schema(ref: '#/components/schemas/DebugResponse'), new OA\Schema(properties: [ new OA\Property(property: 'id', title: 'ID', description: 'ID', format: 'string'), new OA\Property(property: 'data', title: 'Data', description: 'Data', format: 'object', nullable: true), new OA\Property(property: 'error', title: 'Error', description: 'Error', format: 'string', nullable: true, example: null), new OA\Property(property: 'success', title: 'Success', description: 'Success', format: 'boolean', example: true), ]), - ] + ], )] #[OA\Schema( schema: 'DebugNotFoundResponse', allOf: [ - new OA\Schema(ref:'#/components/schemas/DebugResponse'), + new OA\Schema(ref: '#/components/schemas/DebugResponse'), new OA\Schema(properties: [ new OA\Property(property: 'id', title: 'ID', description: 'ID', format: 'string'), new OA\Property(property: 'data', title: 'Data', description: 'Data', format: 'object', nullable: true, example: null), new OA\Property(property: 'error', title: 'Error', description: 'Error', format: 'string'), new OA\Property(property: 'success', title: 'Success', description: 'Success', format: 'boolean', example: false), ]), - ] + ], )] final class ResponseDataWrapper implements MiddlewareInterface { - public function __construct(private DataResponseFactoryInterface $responseFactory, private CurrentRoute $currentRoute) - { - } + public function __construct(private DataResponseFactoryInterface $responseFactory, private CurrentRoute $currentRoute) {} public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface { diff --git a/src/Debug/ModuleFederationAssetBundle.php b/src/Debug/ModuleFederationAssetBundle.php index 8f453a9..076cbaf 100644 --- a/src/Debug/ModuleFederationAssetBundle.php +++ b/src/Debug/ModuleFederationAssetBundle.php @@ -5,9 +5,7 @@ namespace Yiisoft\Yii\Debug\Api\Debug; if (!class_exists(\Yiisoft\Assets\AssetBundle::class)) { - class AssetBundle - { - } + class AssetBundle {} } else { class_alias(\Yiisoft\Assets\AssetBundle::class, AssetBundle::class); } diff --git a/src/Debug/Provider/DebugApiProvider.php b/src/Debug/Provider/DebugApiProvider.php index ec3a5ec..5e87ab8 100644 --- a/src/Debug/Provider/DebugApiProvider.php +++ b/src/Debug/Provider/DebugApiProvider.php @@ -29,7 +29,7 @@ public function getExtensions(): array $extensions = [ RouteCollectorInterface::class => static function ( ContainerInterface $container, - RouteCollectorInterface $routeCollector + RouteCollectorInterface $routeCollector, ) { /** * Register debug middlewares twice because a `Subfolder` middleware may rewrite base URL @@ -43,7 +43,7 @@ public function getExtensions(): array if (class_exists(Application::class)) { $extensions[Application::class] = static function ( ContainerInterface $container, - Application $application + Application $application, ): Application { $applicationWrapper = $container->get(HttpApplicationWrapper::class); $applicationWrapper->wrap($application); diff --git a/src/Debug/Repository/CollectorRepository.php b/src/Debug/Repository/CollectorRepository.php index 777963e..b6ba74e 100644 --- a/src/Debug/Repository/CollectorRepository.php +++ b/src/Debug/Repository/CollectorRepository.php @@ -7,11 +7,11 @@ use Yiisoft\Yii\Debug\Api\Debug\Exception\NotFoundException; use Yiisoft\Yii\Debug\Storage\StorageInterface; +use function sprintf; + final class CollectorRepository implements CollectorRepositoryInterface { - public function __construct(private StorageInterface $storage) - { - } + public function __construct(private StorageInterface $storage) {} public function getSummary(?string $id = null): array { @@ -33,12 +33,12 @@ public function getDumpObject(string $id): array return $this->loadData(StorageInterface::TYPE_OBJECTS, $id); } - public function getObject(string $id, string $objectId): array|null + public function getObject(string $id, string $objectId): ?array { $dump = $this->loadData(StorageInterface::TYPE_OBJECTS, $id); foreach ($dump as $name => $value) { - if (($pos = strrpos((string)$name, "#$objectId")) !== false) { + if (($pos = strrpos((string) $name, "#$objectId")) !== false) { return [substr($name, 0, $pos), $value]; } } diff --git a/src/Debug/Repository/CollectorRepositoryInterface.php b/src/Debug/Repository/CollectorRepositoryInterface.php index 6d97d16..b97fd37 100644 --- a/src/Debug/Repository/CollectorRepositoryInterface.php +++ b/src/Debug/Repository/CollectorRepositoryInterface.php @@ -15,5 +15,5 @@ public function getDumpObject(string $id): array; /** * @return array{string, mixed}|null Returns a list with object class, and it's value or null */ - public function getObject(string $id, string $objectId): array|null; + public function getObject(string $id, string $objectId): ?array; } diff --git a/src/Inspector/Command/BashCommand.php b/src/Inspector/Command/BashCommand.php index 9485c99..78840c3 100644 --- a/src/Inspector/Command/BashCommand.php +++ b/src/Inspector/Command/BashCommand.php @@ -14,8 +14,7 @@ final class BashCommand implements CommandInterface public function __construct( private Aliases $aliases, private array $command, - ) { - } + ) {} public static function getTitle(): string { @@ -50,7 +49,7 @@ public function run(): CommandResponse return new CommandResponse( status: $process->isSuccessful() ? CommandResponse::STATUS_OK : CommandResponse::STATUS_ERROR, - result: $processOutput . $process->getErrorOutput() + result: $processOutput . $process->getErrorOutput(), ); } } diff --git a/src/Inspector/Command/CodeceptionCommand.php b/src/Inspector/Command/CodeceptionCommand.php index 1da023c..82f9d54 100644 --- a/src/Inspector/Command/CodeceptionCommand.php +++ b/src/Inspector/Command/CodeceptionCommand.php @@ -10,13 +10,14 @@ use Yiisoft\Yii\Debug\Api\Inspector\CommandResponse; use Yiisoft\Yii\Debug\Api\Inspector\Test\CodeceptionJSONReporter; +use const DIRECTORY_SEPARATOR; +use const JSON_THROW_ON_ERROR; + class CodeceptionCommand implements CommandInterface { public const COMMAND_NAME = 'test/codeception'; - public function __construct(private Aliases $aliases) - { - } + public function __construct(private Aliases $aliases) {} public static function getTitle(): string { @@ -56,7 +57,7 @@ public function run(): CommandResponse file_get_contents($debugDirectory . DIRECTORY_SEPARATOR . CodeceptionJSONReporter::FILENAME), true, 512, - JSON_THROW_ON_ERROR + JSON_THROW_ON_ERROR, ); if (!$process->getExitCode() > 1) { @@ -69,7 +70,7 @@ public function run(): CommandResponse return new CommandResponse( status: $process->isSuccessful() ? CommandResponse::STATUS_OK : CommandResponse::STATUS_ERROR, - result: $processOutput + result: $processOutput, ); } } diff --git a/src/Inspector/Command/PHPUnitCommand.php b/src/Inspector/Command/PHPUnitCommand.php index 16bd4e2..8b39b2e 100644 --- a/src/Inspector/Command/PHPUnitCommand.php +++ b/src/Inspector/Command/PHPUnitCommand.php @@ -10,6 +10,9 @@ use Yiisoft\Yii\Debug\Api\Inspector\CommandResponse; use Yiisoft\Yii\Debug\Api\Inspector\Test\PHPUnitJSONReporter; +use const DIRECTORY_SEPARATOR; +use const JSON_THROW_ON_ERROR; + /** * @psalm-suppress MissingDependency */ @@ -17,9 +20,7 @@ class PHPUnitCommand implements CommandInterface { public const COMMAND_NAME = 'test/phpunit'; - public function __construct(private Aliases $aliases) - { - } + public function __construct(private Aliases $aliases) {} public static function getTitle(): string { @@ -56,7 +57,7 @@ public function run(): CommandResponse file_get_contents($debugDirectory . DIRECTORY_SEPARATOR . PHPUnitJSONReporter::FILENAME), true, 512, - JSON_THROW_ON_ERROR + JSON_THROW_ON_ERROR, ); if (!$process->getExitCode() > 1) { @@ -69,7 +70,7 @@ public function run(): CommandResponse return new CommandResponse( status: $process->isSuccessful() ? CommandResponse::STATUS_OK : CommandResponse::STATUS_ERROR, - result: $processOutput + result: $processOutput, ); } } diff --git a/src/Inspector/Command/PsalmCommand.php b/src/Inspector/Command/PsalmCommand.php index 9401b49..dc34d5f 100644 --- a/src/Inspector/Command/PsalmCommand.php +++ b/src/Inspector/Command/PsalmCommand.php @@ -9,13 +9,14 @@ use Yiisoft\Yii\Debug\Api\Inspector\CommandInterface; use Yiisoft\Yii\Debug\Api\Inspector\CommandResponse; +use const DIRECTORY_SEPARATOR; +use const JSON_THROW_ON_ERROR; + class PsalmCommand implements CommandInterface { public const COMMAND_NAME = 'analyse/psalm'; - public function __construct(private Aliases $aliases) - { - } + public function __construct(private Aliases $aliases) {} public static function getTitle(): string { @@ -50,7 +51,7 @@ public function run(): CommandResponse file_get_contents($outputFilePath), true, 512, - JSON_THROW_ON_ERROR + JSON_THROW_ON_ERROR, ); if (!$process->getExitCode() > 1) { @@ -63,7 +64,7 @@ public function run(): CommandResponse return new CommandResponse( status: $process->isSuccessful() ? CommandResponse::STATUS_OK : CommandResponse::STATUS_ERROR, - result: $processOutput + result: $processOutput, ); } } diff --git a/src/Inspector/CommandResponse.php b/src/Inspector/CommandResponse.php index 978de10..bba3a96 100644 --- a/src/Inspector/CommandResponse.php +++ b/src/Inspector/CommandResponse.php @@ -14,8 +14,7 @@ public function __construct( private string $status, private mixed $result, private array $errors = [], - ) { - } + ) {} public function getStatus(): string { diff --git a/src/Inspector/Controller/CacheController.php b/src/Inspector/Controller/CacheController.php index 8c4b946..869e61d 100644 --- a/src/Inspector/Controller/CacheController.php +++ b/src/Inspector/Controller/CacheController.php @@ -16,8 +16,7 @@ class CacheController { public function __construct( private DataResponseFactoryInterface $responseFactory, - ) { - } + ) {} public function view( ServerRequestInterface $request, @@ -32,7 +31,7 @@ public function view( if (!$container->has(CacheInterface::class)) { // TODO: fix message throw new RuntimeException( - 'Psr\\SimpleCache\\CacheInterface does not exist in the application configuration.' + 'Psr\\SimpleCache\\CacheInterface does not exist in the application configuration.', ); } $cache = $container->get(CacheInterface::class); @@ -63,7 +62,7 @@ public function delete( if (!$container->has(CacheInterface::class)) { // TODO: fix message throw new RuntimeException( - 'Psr\\SimpleCache\\CacheInterface does not exist in the application configuration.' + 'Psr\\SimpleCache\\CacheInterface does not exist in the application configuration.', ); } $cache = $container->get(CacheInterface::class); @@ -85,7 +84,7 @@ public function clear( if (!$container->has(CacheInterface::class)) { // TODO: fix message throw new RuntimeException( - 'Psr\\SimpleCache\\CacheInterface does not exist in the application configuration.' + 'Psr\\SimpleCache\\CacheInterface does not exist in the application configuration.', ); } $cache = $container->get(CacheInterface::class); diff --git a/src/Inspector/Controller/CommandController.php b/src/Inspector/Controller/CommandController.php index de0997b..40e6767 100644 --- a/src/Inspector/Controller/CommandController.php +++ b/src/Inspector/Controller/CommandController.php @@ -17,13 +17,15 @@ use function array_key_exists; use function is_array; use function is_string; +use function sprintf; + +use const JSON_THROW_ON_ERROR; class CommandController { public function __construct( private DataResponseFactoryInterface $responseFactory, - ) { - } + ) {} public function index(ConfigInterface $config, Aliases $aliases): ResponseInterface { @@ -90,8 +92,8 @@ public function run( throw new InvalidArgumentException( sprintf( 'Command must not be null. Available commands: "%s".', - implode('", "', array_keys($commandList)) - ) + implode('", "', array_keys($commandList)), + ), ); } @@ -100,8 +102,8 @@ public function run( sprintf( 'Unknown command "%s". Available commands: "%s".', $commandName, - implode('", "', array_keys($commandList)) - ) + implode('", "', array_keys($commandList)), + ), ); } @@ -109,7 +111,7 @@ public function run( if (is_string($commandClass) && $container->has($commandClass)) { $command = $container->get($commandClass); } else { - $command = new BashCommand($aliases, (array)$commandClass); + $command = new BashCommand($aliases, (array) $commandClass); } $result = $command->run(); diff --git a/src/Inspector/Controller/ComposerController.php b/src/Inspector/Controller/ComposerController.php index 954cc45..8e41d82 100644 --- a/src/Inspector/Controller/ComposerController.php +++ b/src/Inspector/Controller/ComposerController.php @@ -13,12 +13,16 @@ use Yiisoft\Yii\Debug\Api\Inspector\Command\BashCommand; use Yiisoft\Yii\Debug\Api\Inspector\CommandResponse; +use function is_string; +use function sprintf; + +use const JSON_THROW_ON_ERROR; + final class ComposerController { public function __construct( private DataResponseFactoryInterface $responseFactory, - ) { - } + ) {} public function index(Aliases $aliases): ResponseInterface { @@ -29,7 +33,7 @@ public function index(Aliases $aliases): ResponseInterface sprintf( 'Could not find composer.json by the path "%s".', $composerJsonPath, - ) + ), ); } $result = [ @@ -47,7 +51,7 @@ public function inspect(ServerRequestInterface $request, Aliases $aliases): Resp $package = $request->getQueryParams()['package'] ?? null; if ($package === null) { throw new InvalidArgumentException( - 'Query parameter "package" should not be empty.' + 'Query parameter "package" should not be empty.', ); } $command = new BashCommand($aliases, ['composer', 'show', $package, '--all', '--format=json']); @@ -65,13 +69,13 @@ public function inspect(ServerRequestInterface $request, Aliases $aliases): Resp public function require(ServerRequestInterface $request, Aliases $aliases): ResponseInterface { // Request factory may be unable to parse JSON so don't rely on getParsedBody(). - $parsedBody = \json_decode($request->getBody()->getContents(), true, 512, JSON_THROW_ON_ERROR); + $parsedBody = json_decode($request->getBody()->getContents(), true, 512, JSON_THROW_ON_ERROR); $package = $parsedBody['package'] ?? null; $version = $parsedBody['version'] ?? null; $isDev = $parsedBody['isDev'] ?? false; if ($package === null) { throw new InvalidArgumentException( - 'Query parameter "package" should not be empty.' + 'Query parameter "package" should not be empty.', ); } $packageWithVersion = sprintf('%s:%s', $package, $version ?? '*'); diff --git a/src/Inspector/Controller/GitController.php b/src/Inspector/Controller/GitController.php index 7d92f59..2dfc263 100644 --- a/src/Inspector/Controller/GitController.php +++ b/src/Inspector/Controller/GitController.php @@ -15,13 +15,18 @@ use Yiisoft\DataResponse\DataResponseFactoryInterface; use Yiisoft\VarDumper\VarDumper; +use function dirname; +use function in_array; +use function sprintf; + +use const JSON_THROW_ON_ERROR; + final class GitController { public function __construct( private DataResponseFactoryInterface $responseFactory, private Aliases $aliases, - ) { - } + ) {} public function summary(): ResponseInterface { @@ -36,11 +41,11 @@ public function summary(): ResponseInterface $result = [ 'currentBranch' => $branch->getName(), 'sha' => $branch->getCommitHash(), - 'remotes' => array_map(fn (string $name) => [ + 'remotes' => array_map(fn(string $name) => [ 'name' => $name, 'url' => trim($git->run('remote', ['get-url', $name])), ], $remoteNames), - 'branches' => array_map(fn (Branch $branch) => $branch->getName(), $branches), + 'branches' => array_map(fn(Branch $branch) => $branch->getName(), $branches), 'lastCommit' => $this->serializeCommit($branch->getCommit()), 'status' => explode("\n", $git->run('status')), ]; @@ -68,7 +73,7 @@ public function checkout(ServerRequestInterface $request): ResponseInterface { $git = $this->getGit(); - $parsedBody = \json_decode($request->getBody()->getContents(), true, 512, JSON_THROW_ON_ERROR); + $parsedBody = json_decode($request->getBody()->getContents(), true, 512, JSON_THROW_ON_ERROR); $branch = $parsedBody['branch'] ?? null; if ($branch === null) { @@ -95,7 +100,7 @@ public function command(ServerRequestInterface $request): ResponseInterface 'Unknown command "%s". Available commands: "%s".', $command, implode('", "', $availableCommands), - ) + ), ); } @@ -125,7 +130,7 @@ private function getGit(): Repository sprintf( 'Could find any repositories up from "%s" directory.', $projectPath, - ) + ), ); } diff --git a/src/Inspector/Controller/InspectController.php b/src/Inspector/Controller/InspectController.php index cad40ef..c24ea67 100644 --- a/src/Inspector/Controller/InspectController.php +++ b/src/Inspector/Controller/InspectController.php @@ -32,14 +32,21 @@ use Yiisoft\Yii\Debug\Api\Inspector\ApplicationState; use Yiisoft\Yii\Debug\Api\Inspector\Database\SchemaProviderInterface; use Yiisoft\Yii\Debug\Collector\Web\RequestCollector; +use ReflectionObject; + +use function dirname; +use function function_exists; +use function in_array; +use function sprintf; + +use const JSON_THROW_ON_ERROR; class InspectController { public function __construct( private DataResponseFactoryInterface $responseFactory, private Aliases $aliases, - ) { - } + ) {} public function config(ContainerInterface $container, ServerRequestInterface $request): ResponseInterface { @@ -67,8 +74,8 @@ public function getTranslations(ContainerInterface $container): ResponseInterfac $locales = array_keys($params['locale']['locales']); if ($locales === []) { throw new RuntimeException( - 'Unable to determine list of available locales. ' . - 'Make sure that "$params[\'locale\'][\'locales\']" contains all available locales.' + 'Unable to determine list of available locales. ' + . 'Make sure that "$params[\'locale\'][\'locales\']" contains all available locales.', ); } $messages = []; @@ -83,7 +90,7 @@ public function getTranslations(ContainerInterface $container): ResponseInterfac foreach ($locales as $locale) { $messages[$categoryName][$locale] = array_merge( $messages[$categoryName][$locale] ?? [], - $categorySource->getMessages($locale) + $categorySource->getMessages($locale), ); } } catch (Throwable) { @@ -101,7 +108,7 @@ public function putTranslation(ContainerInterface $container, ServerRequestInter */ $categorySources = $container->get('tag@translation.categorySource'); - $body = \json_decode($request->getBody()->getContents(), true, 512, JSON_THROW_ON_ERROR); + $body = json_decode($request->getBody()->getContents(), true, 512, JSON_THROW_ON_ERROR); $categoryName = $body['category'] ?? ''; $locale = $body['locale'] ?? ''; $translationId = $body['translation'] ?? ''; @@ -120,9 +127,9 @@ public function putTranslation(ContainerInterface $container, ServerRequestInter $categoryName, implode( '", "', - array_map(fn (CategorySource $categorySource) => $categorySource->getName(), $categorySources) - ) - ) + array_map(fn(CategorySource $categorySource) => $categorySource->getName(), $categorySources), + ), + ), ); } $messages = $categorySource->getMessages($locale); @@ -195,7 +202,7 @@ public function files(ServerRequestInterface $request): ResponseInterface $directoryIterator = new RecursiveDirectoryIterator( $destination, - FilesystemIterator::KEY_AS_PATHNAME | FilesystemIterator::CURRENT_AS_FILEINFO + FilesystemIterator::KEY_AS_PATHNAME | FilesystemIterator::CURRENT_AS_FILEINFO, ); $files = []; @@ -222,7 +229,7 @@ public function files(ServerRequestInterface $request): ResponseInterface [ 'path' => $path, ], - $this->serializeFileInfo($file) + $this->serializeFileInfo($file), ); } @@ -237,12 +244,12 @@ public function classes(): ResponseInterface $inspected = [...get_declared_classes(), ...get_declared_interfaces()]; // TODO: think how to ignore heavy objects $patterns = [ - fn (string $class) => !str_starts_with($class, 'ComposerAutoloaderInit'), - fn (string $class) => !str_starts_with($class, 'Composer\\'), - fn (string $class) => !str_starts_with($class, 'Yiisoft\\Yii\\Debug\\'), - fn (string $class) => !str_starts_with($class, 'Yiisoft\\ErrorHandler\\ErrorHandler'), - fn (string $class) => !str_contains($class, '@anonymous'), - fn (string $class) => !is_subclass_of($class, Throwable::class), + fn(string $class) => !str_starts_with($class, 'ComposerAutoloaderInit'), + fn(string $class) => !str_starts_with($class, 'Composer\\'), + fn(string $class) => !str_starts_with($class, 'Yiisoft\\Yii\\Debug\\'), + fn(string $class) => !str_starts_with($class, 'Yiisoft\\ErrorHandler\\ErrorHandler'), + fn(string $class) => !str_contains($class, '@anonymous'), + fn(string $class) => !is_subclass_of($class, Throwable::class), ]; foreach ($patterns as $patternFunction) { $inspected = array_filter($inspected, $patternFunction); @@ -318,7 +325,7 @@ public function routes(RouteCollectionInterface $routeCollection): ResponseInter public function checkRoute( ServerRequestInterface $request, UrlMatcherInterface $matcher, - ServerRequestFactoryInterface $serverRequestFactory + ServerRequestFactoryInterface $serverRequestFactory, ): ResponseInterface { $queryParams = $request->getQueryParams(); $path = $queryParams['route'] ?? null; @@ -347,7 +354,7 @@ public function checkRoute( } $route = $result->route(); - $reflection = new \ReflectionObject($route); + $reflection = new ReflectionObject($route); $property = $reflection->getProperty('middlewareDefinitions'); $middlewareDefinitions = $property->getValue($route); $action = end($middlewareDefinitions); @@ -372,7 +379,7 @@ public function getTable(SchemaProviderInterface $schemaProvider, CurrentRoute $ public function request( ServerRequestInterface $request, - CollectorRepositoryInterface $collectorRepository + CollectorRepositoryInterface $collectorRepository, ): ResponseInterface { $request = $request->getQueryParams(); $debugEntryId = $request['debugEntryId'] ?? null; @@ -404,12 +411,11 @@ public function eventListeners(ContainerInterface $container) public function buildCurl( ServerRequestInterface $request, - CollectorRepositoryInterface $collectorRepository + CollectorRepositoryInterface $collectorRepository, ): ResponseInterface { $request = $request->getQueryParams(); $debugEntryId = $request['debugEntryId'] ?? null; - $data = $collectorRepository->getDetail($debugEntryId); $rawRequest = $data[RequestCollector::class]['requestRaw']; @@ -422,7 +428,7 @@ public function buildCurl( } catch (Throwable $e) { return $this->responseFactory->createResponse([ 'command' => null, - 'exception' => (string)$e, + 'exception' => (string) $e, ]); } @@ -437,7 +443,7 @@ private function removeBasePath(string $rootPath, string $path): string|array|nu '/^' . preg_quote($rootPath, '/') . '/', '', $path, - 1 + 1, ); } @@ -494,8 +500,8 @@ private function readFile(string $destination, array $extra = []): DataResponse 'path' => $this->removeBasePath($rootPath, $destination), 'absolutePath' => $destination, ], - $this->serializeFileInfo($file) - ) + $this->serializeFileInfo($file), + ), ); } } diff --git a/src/Inspector/Controller/OpcacheController.php b/src/Inspector/Controller/OpcacheController.php index c2c2732..3f811e5 100644 --- a/src/Inspector/Controller/OpcacheController.php +++ b/src/Inspector/Controller/OpcacheController.php @@ -8,16 +8,17 @@ use Yiisoft\DataResponse\DataResponseFactoryInterface; use Yiisoft\Http\Status; +use function function_exists; + final class OpcacheController { public function __construct( private DataResponseFactoryInterface $responseFactory, - ) { - } + ) {} public function index(): ResponseInterface { - if (!\function_exists('opcache_get_status') || ($status = \opcache_get_status(true)) === false) { + if (!function_exists('opcache_get_status') || ($status = opcache_get_status(true)) === false) { return $this->responseFactory->createResponse([ 'message' => 'OPcache is not installed or configured', ], Status::UNPROCESSABLE_ENTITY); @@ -25,7 +26,7 @@ public function index(): ResponseInterface return $this->responseFactory->createResponse([ 'status' => $status, - 'configuration' => \opcache_get_configuration(), + 'configuration' => opcache_get_configuration(), ]); } } diff --git a/src/Inspector/Database/Cycle/CycleSchemaProvider.php b/src/Inspector/Database/Cycle/CycleSchemaProvider.php index 0120845..30ea612 100644 --- a/src/Inspector/Database/Cycle/CycleSchemaProvider.php +++ b/src/Inspector/Database/Cycle/CycleSchemaProvider.php @@ -10,9 +10,7 @@ class CycleSchemaProvider implements SchemaProviderInterface { - public function __construct(private DatabaseProviderInterface $databaseProvider) - { - } + public function __construct(private DatabaseProviderInterface $databaseProvider) {} public function getTables(): array { diff --git a/src/Inspector/Database/Db/DbSchemaProvider.php b/src/Inspector/Database/Db/DbSchemaProvider.php index cfd7455..8916bed 100644 --- a/src/Inspector/Database/Db/DbSchemaProvider.php +++ b/src/Inspector/Database/Db/DbSchemaProvider.php @@ -12,9 +12,7 @@ class DbSchemaProvider implements SchemaProviderInterface { - public function __construct(private ConnectionInterface $db) - { - } + public function __construct(private ConnectionInterface $db) {} public function getTables(): array { diff --git a/src/Inspector/Test/CodeceptionJSONReporter.php b/src/Inspector/Test/CodeceptionJSONReporter.php index 93a7469..06b221b 100644 --- a/src/Inspector/Test/CodeceptionJSONReporter.php +++ b/src/Inspector/Test/CodeceptionJSONReporter.php @@ -13,26 +13,29 @@ use ReflectionClass; use ReflectionObject; +use const DIRECTORY_SEPARATOR; +use const JSON_THROW_ON_ERROR; + final class CodeceptionJSONReporter extends Extension { + public const FILENAME = 'codeception-report.json'; + + public static array $events = [ + Events::TEST_SUCCESS => 'success', + Events::TEST_FAIL => 'fail', + Events::TEST_ERROR => 'error', + Events::RESULT_PRINT_AFTER => 'all', + ]; protected array $config = [ 'output-path' => __DIR__, ]; private array $data = []; - public const FILENAME = 'codeception-report.json'; public function _initialize(): void { $this->_reconfigure(['settings' => ['silent' => true]]); } - public static array $events = [ - Events::TEST_SUCCESS => 'success', - Events::TEST_FAIL => 'fail', - Events::TEST_ERROR => 'error', - Events::RESULT_PRINT_AFTER => 'all', - ]; - public function success(TestEvent $event): void { $this->data[] = [ @@ -70,7 +73,7 @@ public function all(PrintResultEvent $event): void { file_put_contents( $this->config['output-path'] . DIRECTORY_SEPARATOR . self::FILENAME, - json_encode($this->data, JSON_THROW_ON_ERROR) + json_encode($this->data, JSON_THROW_ON_ERROR), ); } diff --git a/src/Inspector/Test/PHPUnitJSONReporter.php b/src/Inspector/Test/PHPUnitJSONReporter.php index c208637..daa6525 100644 --- a/src/Inspector/Test/PHPUnitJSONReporter.php +++ b/src/Inspector/Test/PHPUnitJSONReporter.php @@ -16,6 +16,9 @@ use ReflectionClass; use Throwable; +use const DIRECTORY_SEPARATOR; +use const JSON_THROW_ON_ERROR; + /** * @psalm-suppress InternalClass, InternalMethod, UndefinedClass */ @@ -39,7 +42,7 @@ public function printResult(TestResult $result): void file_put_contents( $path . DIRECTORY_SEPARATOR . self::FILENAME, - json_encode(array_values($this->data), JSON_THROW_ON_ERROR) + json_encode(array_values($this->data), JSON_THROW_ON_ERROR), ); } @@ -78,17 +81,11 @@ public function addSkippedTest(Test $test, Throwable $t, float $time): void $this->logErroredTest($test, $t); } - public function startTestSuite(TestSuite $suite): void - { - } + public function startTestSuite(TestSuite $suite): void {} - public function endTestSuite(TestSuite $suite): void - { - } + public function endTestSuite(TestSuite $suite): void {} - public function startTest(Test $test): void - { - } + public function startTest(Test $test): void {} public function endTest(Test $test, float $time): void { diff --git a/src/ServerSentEventsStream.php b/src/ServerSentEventsStream.php index 8956b11..72b71ca 100644 --- a/src/ServerSentEventsStream.php +++ b/src/ServerSentEventsStream.php @@ -6,15 +6,25 @@ use Closure; use Psr\Http\Message\StreamInterface; +use RuntimeException; +use Stringable; -final class ServerSentEventsStream implements StreamInterface, \Stringable +use function sprintf; + +use const SEEK_SET; + +final class ServerSentEventsStream implements StreamInterface, Stringable { public array $buffer = []; private bool $eof = false; public function __construct( private Closure $stream, - ) { + ) {} + + public function __toString(): string + { + return $this->getContents(); } public function close(): void @@ -49,12 +59,12 @@ public function isSeekable(): bool public function seek($offset, $whence = SEEK_SET): void { - throw new \RuntimeException('Stream is not seekable'); + throw new RuntimeException('Stream is not seekable'); } public function rewind(): void { - throw new \RuntimeException('Stream is not seekable'); + throw new RuntimeException('Stream is not seekable'); } public function isWritable(): bool @@ -64,7 +74,7 @@ public function isWritable(): bool public function write($string): int { - throw new \RuntimeException('Stream is not writable'); + throw new RuntimeException('Stream is not writable'); } public function isReadable(): bool @@ -101,9 +111,4 @@ public function getMetadata($key = null): array { return []; } - - public function __toString(): string - { - return $this->getContents(); - } } diff --git a/tests/Support/StubCollector.php b/tests/Support/StubCollector.php index 06abc04..f54b109 100644 --- a/tests/Support/StubCollector.php +++ b/tests/Support/StubCollector.php @@ -8,22 +8,16 @@ final class StubCollector implements CollectorInterface { - public function __construct(private array $data = []) - { - } + public function __construct(private array $data = []) {} public function getName(): string { return 'stub'; } - public function startup(): void - { - } + public function startup(): void {} - public function shutdown(): void - { - } + public function shutdown(): void {} public function getCollected(): array { diff --git a/tests/Unit/Debug/Middleware/DebugHeadersTest.php b/tests/Unit/Debug/Middleware/DebugHeadersTest.php index 8e550a5..0cf8840 100644 --- a/tests/Unit/Debug/Middleware/DebugHeadersTest.php +++ b/tests/Unit/Debug/Middleware/DebugHeadersTest.php @@ -21,7 +21,7 @@ public function testHeaders(): void { $urlGenerator = $this->createMock(UrlGeneratorInterface::class); $urlGenerator->method('generate')->willReturnCallback( - fn (string $route, array $parameters) => $route . '?' . http_build_query($parameters) + fn(string $route, array $parameters) => $route . '?' . http_build_query($parameters), ); $debugger = new Debugger(new MemoryStorage(), []); @@ -37,7 +37,7 @@ public function testHeaders(): void protected function createRequestHandler(): RequestHandlerInterface { - return new class () implements RequestHandlerInterface { + return new class implements RequestHandlerInterface { public function handle($request): ResponseInterface { return new Response(200); diff --git a/tests/Unit/Debug/Middleware/ResponseDataWrapperTest.php b/tests/Unit/Debug/Middleware/ResponseDataWrapperTest.php index 634cc66..f77679e 100644 --- a/tests/Unit/Debug/Middleware/ResponseDataWrapperTest.php +++ b/tests/Unit/Debug/Middleware/ResponseDataWrapperTest.php @@ -76,7 +76,7 @@ public function testDataResponseException(): void $middleware = $this->createMiddleware(); $response = $middleware->process( new ServerRequest(), - $this->createExceptionRequestHandler(new NotFoundException($errorMessage)) + $this->createExceptionRequestHandler(new NotFoundException($errorMessage)), ); $this->assertInstanceOf(ResponseInterface::class, $response); @@ -96,8 +96,7 @@ private function createRequestHandler(ResponseInterface $response): RequestHandl return new class ($response) implements RequestHandlerInterface { public function __construct( private ResponseInterface $response, - ) { - } + ) {} public function handle($request): ResponseInterface { @@ -111,8 +110,7 @@ private function createExceptionRequestHandler(Throwable $exception): RequestHan return new class ($exception) implements RequestHandlerInterface { public function __construct( private Throwable $exception, - ) { - } + ) {} public function handle($request): ResponseInterface { diff --git a/tests/Unit/Debug/Repository/CollectorRepositoryTest.php b/tests/Unit/Debug/Repository/CollectorRepositoryTest.php index 69f1f82..85753b0 100644 --- a/tests/Unit/Debug/Repository/CollectorRepositoryTest.php +++ b/tests/Unit/Debug/Repository/CollectorRepositoryTest.php @@ -23,7 +23,7 @@ public function testSummary(): void [ ['total' => 7], ], - $repository->getSummary() + $repository->getSummary(), ); } @@ -36,7 +36,7 @@ public function testDetail(): void $this->assertSame( ['stub' => ['key' => 'value']], - $repository->getDetail('testId') + $repository->getDetail('testId'), ); } @@ -49,7 +49,7 @@ public function testDumpObject(): void $this->assertSame( ['object' => []], - $repository->getDumpObject('testId') + $repository->getDumpObject('testId'), ); } @@ -74,7 +74,7 @@ public function testObject(): void 'stdClass', 'value', ], - $object + $object, ); } } diff --git a/tests/Unit/Inspector/Command/BashCommandTest.php b/tests/Unit/Inspector/Command/BashCommandTest.php index 5a327f7..9cd4405 100644 --- a/tests/Unit/Inspector/Command/BashCommandTest.php +++ b/tests/Unit/Inspector/Command/BashCommandTest.php @@ -9,6 +9,8 @@ use Yiisoft\Yii\Debug\Api\Inspector\Command\BashCommand; use Yiisoft\Yii\Debug\Api\Inspector\CommandResponse; +use function dirname; + final class BashCommandTest extends TestCase { public function testSuccess(): void diff --git a/tests/Unit/Inspector/Database/DbSchemaProviderTest.php b/tests/Unit/Inspector/Database/DbSchemaProviderTest.php index 5a00506..3ef1815 100644 --- a/tests/Unit/Inspector/Database/DbSchemaProviderTest.php +++ b/tests/Unit/Inspector/Database/DbSchemaProviderTest.php @@ -83,7 +83,7 @@ private function generateTables(ConnectionInterface $db): void [ 'id' => 'pk', 'email' => 'string', - ] + ], )->execute(); $db->createCommand()->createTable( From 56979bbf5bece2eb01d53516db57d53557994b1d Mon Sep 17 00:00:00 2001 From: Sergei Predvoditelev Date: Thu, 30 Jul 2026 13:04:15 +0300 Subject: [PATCH 2/2] fix --- rector.php | 8 -------- 1 file changed, 8 deletions(-) diff --git a/rector.php b/rector.php index 348db8d..91b5cc0 100644 --- a/rector.php +++ b/rector.php @@ -3,9 +3,6 @@ declare(strict_types=1); use Rector\Config\RectorConfig; -use Rector\Php74\Rector\Closure\ClosureToArrowFunctionRector; -use Rector\Php81\Rector\Property\ReadOnlyPropertyRector; -use Rector\Php81\Rector\FuncCall\NullToStrictStringFuncCallArgRector; use Yiisoft\CodeStyle\Rector\SetList; return RectorConfig::configure() @@ -17,9 +14,4 @@ ->withPhpSets(php81: true) ->withSets([ SetList::YII_CORE, - ]) - ->withSkip([ - ClosureToArrowFunctionRector::class, - ReadOnlyPropertyRector::class, - NullToStrictStringFuncCallArgRector::class, ]);