From 2791dfcab24437e4c99d8553508f9a88daeb3416 Mon Sep 17 00:00:00 2001 From: Alexander Makarov Date: Wed, 19 Jun 2024 23:34:58 +0300 Subject: [PATCH 1/5] Cleanup --- composer.json | 5 --- config/params.php | 6 ++-- src/Collector/Console/CommandCollector.php | 4 ++- .../Console/ConsoleAppInfoCollector.php | 4 ++- src/Collector/EventCollector.php | 4 ++- .../EventDispatcherInterfaceProxy.php | 4 +-- src/Collector/ExceptionCollector.php | 4 ++- src/Collector/HttpClientCollector.php | 4 ++- src/Collector/HttpClientInterfaceProxy.php | 5 ++- src/Collector/LogCollector.php | 4 ++- src/Collector/LoggerInterfaceProxy.php | 5 ++- src/Collector/ProxyLogTrait.php | 2 +- src/Collector/ServiceCollector.php | 4 ++- src/Collector/ServiceMethodProxy.php | 2 +- src/Collector/ServiceProxy.php | 2 +- .../Stream/FilesystemStreamCollector.php | 4 +-- src/Collector/Stream/HttpStreamCollector.php | 9 +++-- src/Collector/VarDumperCollector.php | 4 ++- .../VarDumperHandlerInterfaceProxy.php | 4 +-- src/Collector/Web/MiddlewareCollector.php | 4 ++- src/Collector/Web/RequestCollector.php | 4 ++- src/Collector/Web/WebAppInfoCollector.php | 4 ++- src/Command/DebugContainerCommand.php | 18 +++++----- src/Command/DebugEventsCommand.php | 15 ++++---- src/Command/DebugResetCommand.php | 13 +++---- src/Debugger.php | 6 ++-- src/Dumper.php | 10 ++++-- src/FlattenException.php | 11 +++--- src/Helper/StreamWrapper/StreamWrapper.php | 4 +-- src/Storage/FileStorage.php | 14 ++------ src/Storage/MemoryStorage.php | 4 ++- .../Stub/BrokenProxyImplementation.php | 4 ++- .../Collector/ConsoleAppInfoCollectorTest.php | 3 +- .../Collector/ContainerInterfaceProxyTest.php | 17 +++++---- .../EventDispatcherInterfaceProxyTest.php | 2 +- .../Unit/Collector/ExceptionCollectorTest.php | 2 +- .../FilesystemStreamCollectorTest.php | 32 ++++++++--------- .../HttpClientInterfaceProxyTest.php | 2 +- .../Collector/HttpStreamCollectorTest.php | 2 +- .../Stream/FilesystemStreamProxyTest.php | 4 +-- .../Collector/Stream/HttpStreamProxyTest.php | 2 +- .../Command/DebugContainerCommandTest.php | 2 +- tests/Unit/Command/DebugEventsCommandTest.php | 2 +- tests/Unit/Command/ResetCommandTest.php | 2 +- tests/Unit/DumperTest.php | 12 ++++--- tests/Unit/Event/ProxyMethodCallEventTest.php | 5 +-- tests/Unit/FlattenExceptionTest.php | 35 ++++++++++--------- .../Helper/BacktraceIgnoreMatcherTest.php | 3 +- .../Unit/Storage/AbstractStorageTestCase.php | 6 ++-- tests/Unit/Storage/MemoryStorageTest.php | 2 +- 50 files changed, 184 insertions(+), 142 deletions(-) diff --git a/composer.json b/composer.json index c10db6422..c68b7e109 100644 --- a/composer.json +++ b/composer.json @@ -26,8 +26,6 @@ "url": "https://github.com/sponsors/yiisoft" } ], - "minimum-stability": "dev", - "prefer-stable": true, "require": { "php": "^8.1", "ext-mbstring": "*", @@ -80,9 +78,6 @@ } }, "extra": { - "branch-alias": { - "dev-master": "3.0.x-dev" - }, "config-plugin-options": { "source-directory": "config" }, diff --git a/config/params.php b/config/params.php index 3457e19e3..57d383650 100644 --- a/config/params.php +++ b/config/params.php @@ -91,9 +91,9 @@ ], 'yiisoft/yii-console' => [ 'commands' => [ - DebugResetCommand::COMMAND_NAME => DebugResetCommand::class, - DebugContainerCommand::COMMAND_NAME => DebugContainerCommand::class, - DebugEventsCommand::COMMAND_NAME => DebugEventsCommand::class, + 'debug:reset' => DebugResetCommand::class, + 'debug:container' => DebugContainerCommand::class, + 'debug:events' => DebugEventsCommand::class, ], ], ]; diff --git a/src/Collector/Console/CommandCollector.php b/src/Collector/Console/CommandCollector.php index 334a37341..97ceba2ee 100644 --- a/src/Collector/Console/CommandCollector.php +++ b/src/Collector/Console/CommandCollector.php @@ -25,7 +25,9 @@ final class CommandCollector implements SummaryCollectorInterface private const UNDEFINED_EXIT_CODE = -1; private array $commands = []; - public function __construct(private TimelineCollector $timelineCollector) + public function __construct( + private readonly TimelineCollector $timelineCollector + ) { } diff --git a/src/Collector/Console/ConsoleAppInfoCollector.php b/src/Collector/Console/ConsoleAppInfoCollector.php index 5aa75a225..c6a8ad085 100644 --- a/src/Collector/Console/ConsoleAppInfoCollector.php +++ b/src/Collector/Console/ConsoleAppInfoCollector.php @@ -22,7 +22,9 @@ final class ConsoleAppInfoCollector implements SummaryCollectorInterface private float $requestProcessingTimeStarted = 0; private float $requestProcessingTimeStopped = 0; - public function __construct(private TimelineCollector $timelineCollector) + public function __construct( + private readonly TimelineCollector $timelineCollector + ) { } diff --git a/src/Collector/EventCollector.php b/src/Collector/EventCollector.php index d04985ca3..dd2161827 100644 --- a/src/Collector/EventCollector.php +++ b/src/Collector/EventCollector.php @@ -14,7 +14,9 @@ final class EventCollector implements SummaryCollectorInterface private array $events = []; - public function __construct(private TimelineCollector $timelineCollector) + public function __construct( + private readonly TimelineCollector $timelineCollector + ) { } diff --git a/src/Collector/EventDispatcherInterfaceProxy.php b/src/Collector/EventDispatcherInterfaceProxy.php index 90861d8d2..26061acd4 100644 --- a/src/Collector/EventDispatcherInterfaceProxy.php +++ b/src/Collector/EventDispatcherInterfaceProxy.php @@ -9,8 +9,8 @@ final class EventDispatcherInterfaceProxy implements EventDispatcherInterface { public function __construct( - private EventDispatcherInterface $dispatcher, - private EventCollector $collector + private readonly EventDispatcherInterface $dispatcher, + private readonly EventCollector $collector ) { } diff --git a/src/Collector/ExceptionCollector.php b/src/Collector/ExceptionCollector.php index 32b42fbdb..77563bbd8 100644 --- a/src/Collector/ExceptionCollector.php +++ b/src/Collector/ExceptionCollector.php @@ -13,7 +13,9 @@ final class ExceptionCollector implements SummaryCollectorInterface private ?Throwable $exception = null; - public function __construct(private TimelineCollector $timelineCollector) + public function __construct( + private readonly TimelineCollector $timelineCollector + ) { } diff --git a/src/Collector/HttpClientCollector.php b/src/Collector/HttpClientCollector.php index 55df1d1c0..ab634fda2 100644 --- a/src/Collector/HttpClientCollector.php +++ b/src/Collector/HttpClientCollector.php @@ -32,7 +32,9 @@ final class HttpClientCollector implements SummaryCollectorInterface */ private array $requests = []; - public function __construct(private TimelineCollector $timelineCollector) + public function __construct( + private readonly TimelineCollector $timelineCollector + ) { } diff --git a/src/Collector/HttpClientInterfaceProxy.php b/src/Collector/HttpClientInterfaceProxy.php index a7c588f70..bcfb400c1 100644 --- a/src/Collector/HttpClientInterfaceProxy.php +++ b/src/Collector/HttpClientInterfaceProxy.php @@ -10,7 +10,10 @@ final class HttpClientInterfaceProxy implements ClientInterface { - public function __construct(private ClientInterface $decorated, private HttpClientCollector $collector) + public function __construct( + private readonly ClientInterface $decorated, + private readonly HttpClientCollector $collector + ) { } diff --git a/src/Collector/LogCollector.php b/src/Collector/LogCollector.php index 13fb73c1c..e69d56cdc 100644 --- a/src/Collector/LogCollector.php +++ b/src/Collector/LogCollector.php @@ -10,7 +10,9 @@ class LogCollector implements SummaryCollectorInterface private array $messages = []; - public function __construct(private TimelineCollector $timelineCollector) + public function __construct( + private readonly TimelineCollector $timelineCollector + ) { } diff --git a/src/Collector/LoggerInterfaceProxy.php b/src/Collector/LoggerInterfaceProxy.php index 0575b9b34..0783602aa 100644 --- a/src/Collector/LoggerInterfaceProxy.php +++ b/src/Collector/LoggerInterfaceProxy.php @@ -10,7 +10,10 @@ final class LoggerInterfaceProxy implements LoggerInterface { - public function __construct(private LoggerInterface $logger, private LogCollector $collector) + public function __construct( + private readonly LoggerInterface $logger, + private readonly LogCollector $collector + ) { } diff --git a/src/Collector/ProxyLogTrait.php b/src/Collector/ProxyLogTrait.php index 2b2b80918..3620ab49f 100644 --- a/src/Collector/ProxyLogTrait.php +++ b/src/Collector/ProxyLogTrait.php @@ -33,7 +33,7 @@ protected function logProxy( /** * @psalm-param-out array|null $arguments */ - private function processLogData(array &$arguments, mixed &$result, ?object &$error): void + private function processLogData(?array &$arguments, mixed &$result, ?object &$error): void { if (!($this->config->getLogLevel() & ContainerInterfaceProxy::LOG_ARGUMENTS)) { $arguments = null; diff --git a/src/Collector/ServiceCollector.php b/src/Collector/ServiceCollector.php index ba95634ee..c061312df 100644 --- a/src/Collector/ServiceCollector.php +++ b/src/Collector/ServiceCollector.php @@ -10,7 +10,9 @@ final class ServiceCollector implements SummaryCollectorInterface private array $items = []; - public function __construct(private TimelineCollector $timelineCollector) + public function __construct( + private readonly TimelineCollector $timelineCollector + ) { } diff --git a/src/Collector/ServiceMethodProxy.php b/src/Collector/ServiceMethodProxy.php index d596f27d0..bddb467da 100644 --- a/src/Collector/ServiceMethodProxy.php +++ b/src/Collector/ServiceMethodProxy.php @@ -11,7 +11,7 @@ class ServiceMethodProxy extends ServiceProxy public function __construct( string $service, object $instance, - private array $methods, + private readonly array $methods, ContainerProxyConfig $config ) { parent::__construct($service, $instance, $config); diff --git a/src/Collector/ServiceProxy.php b/src/Collector/ServiceProxy.php index 3131dc167..783bf7ee4 100644 --- a/src/Collector/ServiceProxy.php +++ b/src/Collector/ServiceProxy.php @@ -11,7 +11,7 @@ class ServiceProxy extends ObjectProxy use ProxyLogTrait; public function __construct( - private string $service, + private readonly string $service, object $instance, ContainerProxyConfig $config, ) { diff --git a/src/Collector/Stream/FilesystemStreamCollector.php b/src/Collector/Stream/FilesystemStreamCollector.php index 692915edc..0c567d864 100644 --- a/src/Collector/Stream/FilesystemStreamCollector.php +++ b/src/Collector/Stream/FilesystemStreamCollector.php @@ -18,8 +18,8 @@ public function __construct( * - '/' . preg_quote('yii-debug/src/Dumper', '/') . '/' * - '/ClosureExporter/' */ - private array $ignoredPathPatterns = [], - private array $ignoredClasses = [], + private readonly array $ignoredPathPatterns = [], + private readonly array $ignoredClasses = [], ) { } diff --git a/src/Collector/Stream/HttpStreamCollector.php b/src/Collector/Stream/HttpStreamCollector.php index cda42d092..6896971af 100644 --- a/src/Collector/Stream/HttpStreamCollector.php +++ b/src/Collector/Stream/HttpStreamCollector.php @@ -11,11 +11,14 @@ final class HttpStreamCollector implements SummaryCollectorInterface { use CollectorTrait; + private array $ignoredPathPatterns; + public function __construct( - private array $ignoredPathPatterns = [], - private array $ignoredClasses = [], - private array $ignoredUrls = [] + array $ignoredPathPatterns = [], + private readonly array $ignoredClasses = [], + private readonly array $ignoredUrls = [] ) { + $this->ignoredPathPatterns = $ignoredPathPatterns; } private array $requests = []; diff --git a/src/Collector/VarDumperCollector.php b/src/Collector/VarDumperCollector.php index 8042f1520..3798ab9fe 100644 --- a/src/Collector/VarDumperCollector.php +++ b/src/Collector/VarDumperCollector.php @@ -10,7 +10,9 @@ final class VarDumperCollector implements SummaryCollectorInterface private array $vars = []; - public function __construct(private TimelineCollector $timelineCollector) + public function __construct( + private readonly TimelineCollector $timelineCollector + ) { } diff --git a/src/Collector/VarDumperHandlerInterfaceProxy.php b/src/Collector/VarDumperHandlerInterfaceProxy.php index 64c7e2aea..46a5ed510 100644 --- a/src/Collector/VarDumperHandlerInterfaceProxy.php +++ b/src/Collector/VarDumperHandlerInterfaceProxy.php @@ -9,8 +9,8 @@ final class VarDumperHandlerInterfaceProxy implements HandlerInterface { public function __construct( - private HandlerInterface $decorated, - private VarDumperCollector $collector, + private readonly HandlerInterface $decorated, + private readonly VarDumperCollector $collector, ) { } diff --git a/src/Collector/Web/MiddlewareCollector.php b/src/Collector/Web/MiddlewareCollector.php index 7dda19dd8..d41cdc4ab 100644 --- a/src/Collector/Web/MiddlewareCollector.php +++ b/src/Collector/Web/MiddlewareCollector.php @@ -18,7 +18,9 @@ final class MiddlewareCollector implements SummaryCollectorInterface private array $beforeStack = []; private array $afterStack = []; - public function __construct(private TimelineCollector $timelineCollector) + public function __construct( + private readonly TimelineCollector $timelineCollector + ) { } diff --git a/src/Collector/Web/RequestCollector.php b/src/Collector/Web/RequestCollector.php index c9b91a367..9a37cc3c1 100644 --- a/src/Collector/Web/RequestCollector.php +++ b/src/Collector/Web/RequestCollector.php @@ -27,7 +27,9 @@ final class RequestCollector implements SummaryCollectorInterface private ?ServerRequestInterface $request = null; private ?ResponseInterface $response = null; - public function __construct(private TimelineCollector $timelineCollector) + public function __construct( + private readonly TimelineCollector $timelineCollector + ) { } diff --git a/src/Collector/Web/WebAppInfoCollector.php b/src/Collector/Web/WebAppInfoCollector.php index b22b711cd..e2fe70afc 100644 --- a/src/Collector/Web/WebAppInfoCollector.php +++ b/src/Collector/Web/WebAppInfoCollector.php @@ -21,7 +21,9 @@ final class WebAppInfoCollector implements SummaryCollectorInterface private float $requestProcessingTimeStarted = 0; private float $requestProcessingTimeStopped = 0; - public function __construct(private TimelineCollector $timelineCollector) + public function __construct( + private readonly TimelineCollector $timelineCollector + ) { } diff --git a/src/Command/DebugContainerCommand.php b/src/Command/DebugContainerCommand.php index cb1e55a51..f3dcf38d9 100644 --- a/src/Command/DebugContainerCommand.php +++ b/src/Command/DebugContainerCommand.php @@ -5,6 +5,8 @@ namespace Yiisoft\Yii\Debug\Command; use Psr\Container\ContainerInterface; +use ReflectionClass; +use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Helper\Table; use Symfony\Component\Console\Input\InputArgument; @@ -21,14 +23,15 @@ use Yiisoft\Yii\Console\ExitCode; use Yiisoft\Yii\Debug\Debugger; +#[AsCommand( + name: 'debug:container', + description: 'Show information about container', +)] final class DebugContainerCommand extends Command { - public const COMMAND_NAME = 'debug:container'; - protected static $defaultName = self::COMMAND_NAME; - public function __construct( - private ContainerInterface $container, - private Debugger $debugger, + private readonly ContainerInterface $container, + private readonly Debugger $debugger, ) { parent::__construct(); } @@ -36,7 +39,6 @@ public function __construct( protected function configure(): void { $this - ->setDescription('Show information about container') ->addArgument('id', InputArgument::IS_ARRAY, 'Service ID') ->addOption('groups', null, InputOption::VALUE_NONE, 'Show groups') ->addOption('group', 'g', InputOption::VALUE_REQUIRED, 'Show group'); @@ -118,7 +120,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int $groups = array_keys($build); sort($groups); - $io->table(['Groups'], array_map(fn ($group) => [$group], $groups)); + $io->table(['Groups'], array_map(static fn ($group) => [$group], $groups)); return ExitCode::OK; } @@ -156,7 +158,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int private function getConfigBuild(mixed $config): array { - $reflection = new \ReflectionClass($config); + $reflection = new ReflectionClass($config); $buildReflection = $reflection->getProperty('build'); $buildReflection->setAccessible(true); return $buildReflection->getValue($config); diff --git a/src/Command/DebugEventsCommand.php b/src/Command/DebugEventsCommand.php index 372e7b053..c57e63e2c 100644 --- a/src/Command/DebugEventsCommand.php +++ b/src/Command/DebugEventsCommand.php @@ -6,6 +6,7 @@ use Psr\Container\ContainerInterface; use ReflectionClass; +use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Helper\Table; use Symfony\Component\Console\Input\InputArgument; @@ -19,14 +20,15 @@ use Yiisoft\Yii\Console\ExitCode; use Yiisoft\Yii\Debug\Debugger; +#[AsCommand( + name: 'debug:events', + description: 'Show information about events and listeners', +)] final class DebugEventsCommand extends Command { - public const COMMAND_NAME = 'debug:events'; - protected static $defaultName = self::COMMAND_NAME; - public function __construct( - private ContainerInterface $container, - private Debugger $debugger, + private readonly ContainerInterface $container, + private readonly Debugger $debugger, ) { parent::__construct(); } @@ -34,7 +36,6 @@ public function __construct( protected function configure(): void { $this - ->setDescription('Show information about events and listeners') ->addArgument('id', InputArgument::IS_ARRAY, 'Service ID') ->addOption('groups', null, InputOption::VALUE_NONE, 'Show groups') ->addOption('group', 'g', InputOption::VALUE_REQUIRED, 'Show group'); @@ -52,7 +53,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int $groups = array_keys($build); sort($groups); - $io->table(['Groups'], array_map(fn ($group) => [$group], $groups)); + $io->table(['Groups'], array_map(static fn ($group) => [$group], $groups)); return ExitCode::OK; } diff --git a/src/Command/DebugResetCommand.php b/src/Command/DebugResetCommand.php index b42585bc7..67c96ee88 100644 --- a/src/Command/DebugResetCommand.php +++ b/src/Command/DebugResetCommand.php @@ -4,6 +4,7 @@ namespace Yiisoft\Yii\Debug\Command; +use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; @@ -11,14 +12,15 @@ use Yiisoft\Yii\Debug\Debugger; use Yiisoft\Yii\Debug\Storage\StorageInterface; +#[AsCommand( + name: 'debug:reset', + description: 'Clear debug data', +)] final class DebugResetCommand extends Command { - public const COMMAND_NAME = 'debug:reset'; - protected static $defaultName = self::COMMAND_NAME; - public function __construct( - private StorageInterface $storage, - private Debugger $debugger, + private readonly StorageInterface $storage, + private readonly Debugger $debugger, ) { parent::__construct(); } @@ -26,7 +28,6 @@ public function __construct( protected function configure(): void { $this - ->setDescription('Clear debug data') ->setHelp('This command clears debug storage data'); } diff --git a/src/Debugger.php b/src/Debugger.php index 276e18ae3..693715d1a 100644 --- a/src/Debugger.php +++ b/src/Debugger.php @@ -17,12 +17,12 @@ final class Debugger private bool $active = false; public function __construct( - private DebuggerIdGenerator $idGenerator, - private StorageInterface $target, + private readonly DebuggerIdGenerator $idGenerator, + private readonly StorageInterface $target, /** * @var CollectorInterface[] */ - private array $collectors, + private readonly array $collectors, private array $ignoredRequests = [], private array $ignoredCommands = [], ) { diff --git a/src/Dumper.php b/src/Dumper.php index f88440b08..c9433d0a6 100644 --- a/src/Dumper.php +++ b/src/Dumper.php @@ -6,6 +6,7 @@ use __PHP_Incomplete_Class; use Closure; +use ReflectionException; use Yiisoft\VarDumper\ClosureExporter; final class Dumper @@ -18,7 +19,10 @@ final class Dumper /** * @param mixed $variable Variable to dump. */ - private function __construct(private mixed $variable, array $excludedClasses) + private function __construct( + private readonly mixed $variable, + array $excludedClasses + ) { $this->excludedClasses = array_flip($excludedClasses); } @@ -245,11 +249,11 @@ private function getResourceDescription(mixed $resource): array|string } /** - * Exports a {@see \Closure} instance. + * Exports a {@see Closure} instance. * * @param Closure $closure Closure instance. * - * @throws \ReflectionException + * @throws ReflectionException */ private function exportClosure(Closure $closure): string { diff --git a/src/FlattenException.php b/src/FlattenException.php index 442991dfd..3e63a5331 100644 --- a/src/FlattenException.php +++ b/src/FlattenException.php @@ -7,6 +7,7 @@ use __PHP_Incomplete_Class; use ArrayObject; use Exception; +use Stringable; use Throwable; /** @@ -15,7 +16,7 @@ * Basically, this class removes all objects from the trace. * Ported from Symfony components @link https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Debug/Exception/FlattenException.php */ -final class FlattenException implements \Stringable +final class FlattenException implements Stringable { /** * @var string @@ -24,7 +25,7 @@ final class FlattenException implements \Stringable /** * @var int|mixed */ - private $code; + private mixed $code; /** * @var string */ @@ -101,7 +102,7 @@ private function setMessage(string $message): void * * @return int|mixed the exception code as integer. */ - public function getCode() + public function getCode(): mixed { return $this->code; } @@ -109,7 +110,7 @@ public function getCode() /** * @param int|mixed $code the exception code as integer. */ - private function setCode($code): void + private function setCode(mixed $code): void { $this->code = $code; } @@ -255,7 +256,7 @@ private function setClass(string $class): void * * @return array arguments tracing. */ - private function flattenArgs(array $args, $level = 0, &$count = 0): array + private function flattenArgs(array $args, int $level = 0, int &$count = 0): array { $result = []; foreach ($args as $key => $value) { diff --git a/src/Helper/StreamWrapper/StreamWrapper.php b/src/Helper/StreamWrapper/StreamWrapper.php index 608e1ff48..74ab8b837 100644 --- a/src/Helper/StreamWrapper/StreamWrapper.php +++ b/src/Helper/StreamWrapper/StreamWrapper.php @@ -105,7 +105,7 @@ public function rmdir(string $path, int $options): bool /** * @psalm-suppress InvalidReturnType Unfortunately, I don't know what to return here. */ - public function stream_cast(int $castAs) + public function stream_cast(int $castAs): void { // ??? } @@ -211,8 +211,6 @@ public function url_stat(string $path, int $flags): array|false } trigger_error($e->getMessage(), E_USER_ERROR); } - - return false; } public function stream_metadata(string $path, int $option, mixed $value): bool diff --git a/src/Storage/FileStorage.php b/src/Storage/FileStorage.php index dcf5c229d..7c11425ca 100644 --- a/src/Storage/FileStorage.php +++ b/src/Storage/FileStorage.php @@ -31,7 +31,7 @@ final class FileStorage implements StorageInterface private int $historySize = 50; public function __construct( - private string $path, + private readonly string $path, private readonly DebuggerIdGenerator $idGenerator, private readonly array $excludedClasses = [] ) { @@ -90,7 +90,7 @@ public function flush(): void public function getData(): array { - return array_map(fn (CollectorInterface $collector) => $collector->getCollected(), $this->collectors); + return array_map(static fn (CollectorInterface $collector) => $collector->getCollected(), $this->collectors); } public function clear(): void @@ -144,14 +144,4 @@ private function gc(): void } } } - - private function reindexObjects(array $objectsAsArraysCollection): array - { - $toMerge = []; - foreach ($objectsAsArraysCollection as $objectAsArray) { - $toMerge[] = $objectAsArray; - } - - return array_merge(...$toMerge); - } } diff --git a/src/Storage/MemoryStorage.php b/src/Storage/MemoryStorage.php index 1a7e3275c..4efc011c2 100644 --- a/src/Storage/MemoryStorage.php +++ b/src/Storage/MemoryStorage.php @@ -14,7 +14,9 @@ final class MemoryStorage implements StorageInterface */ private array $collectors = []; - public function __construct(private DebuggerIdGenerator $idGenerator) + public function __construct( + private readonly DebuggerIdGenerator $idGenerator + ) { } diff --git a/tests/Support/Stub/BrokenProxyImplementation.php b/tests/Support/Stub/BrokenProxyImplementation.php index 9d9ff123a..e1490f462 100644 --- a/tests/Support/Stub/BrokenProxyImplementation.php +++ b/tests/Support/Stub/BrokenProxyImplementation.php @@ -4,10 +4,12 @@ namespace Yiisoft\Yii\Debug\Tests\Support\Stub; +use Exception; + class BrokenProxyImplementation implements Interface1 { public function __construct(private Interface1 $decorated) { - throw new \Exception('Broken proxy'); + throw new Exception('Broken proxy'); } } diff --git a/tests/Unit/Collector/ConsoleAppInfoCollectorTest.php b/tests/Unit/Collector/ConsoleAppInfoCollectorTest.php index da2eb9b85..5cf9238a7 100644 --- a/tests/Unit/Collector/ConsoleAppInfoCollectorTest.php +++ b/tests/Unit/Collector/ConsoleAppInfoCollectorTest.php @@ -4,6 +4,7 @@ namespace Yiisoft\Yii\Debug\Tests\Unit\Collector; +use Exception; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Event\ConsoleCommandEvent; use Symfony\Component\Console\Event\ConsoleErrorEvent; @@ -33,7 +34,7 @@ protected function collectTestData(CollectorInterface $collector): void $input = new ArrayInput([]); $output = new NullOutput(); $collector->collect(new ConsoleCommandEvent(null, $input, $output)); - $collector->collect(new ConsoleErrorEvent($input, $output, new \Exception())); + $collector->collect(new ConsoleErrorEvent($input, $output, new Exception())); $collector->collect(new ConsoleTerminateEvent($command, $input, $output, 2)); DIRECTORY_SEPARATOR === '\\' ? sleep(1) : usleep(123_000); diff --git a/tests/Unit/Collector/ContainerInterfaceProxyTest.php b/tests/Unit/Collector/ContainerInterfaceProxyTest.php index 083f59c70..54215ea23 100644 --- a/tests/Unit/Collector/ContainerInterfaceProxyTest.php +++ b/tests/Unit/Collector/ContainerInterfaceProxyTest.php @@ -4,6 +4,7 @@ namespace Yiisoft\Yii\Debug\Tests\Unit\Collector; +use Exception; use PHPUnit\Framework\TestCase; use Psr\Container\ContainerExceptionInterface; use Psr\Container\ContainerInterface; @@ -12,6 +13,7 @@ use Psr\Log\LoggerInterface; use Psr\Log\NullLogger; use stdClass; +use Throwable; use Yiisoft\Di\CompositeContainer; use Yiisoft\Di\Container; use Yiisoft\Di\ContainerConfig; @@ -190,16 +192,17 @@ public function testGetAndHasWithNotService(): void public function testHasThrowsExceptionButErrorInCollectorIsAbsent(): void { $container = new CompositeContainer(); - $container->attach(new class () implements ContainerInterface { + $container->attach( + container: new class () implements ContainerInterface { public function get($id) { - throw new class () extends \Exception implements ContainerExceptionInterface { + throw new class () extends Exception implements ContainerExceptionInterface { }; } public function has($id): bool { - throw new class () extends \Exception implements ContainerExceptionInterface { + throw new class () extends Exception implements ContainerExceptionInterface { }; } }); @@ -213,7 +216,7 @@ public function has($id): bool $thrown = null; try { $containerProxy->has('123'); - } catch (\Throwable $e) { + } catch (Throwable $e) { $thrown = $e; } @@ -235,13 +238,13 @@ public function testHasThrowsExceptionAndErrorInCollectorIsNotEmpty(): void $container->attach(new class () implements ContainerInterface { public function get($id) { - throw new class () extends \Exception implements ContainerExceptionInterface { + throw new class () extends Exception implements ContainerExceptionInterface { }; } public function has($id): bool { - throw new class () extends \Exception implements ContainerExceptionInterface { + throw new class () extends Exception implements ContainerExceptionInterface { }; } }); @@ -255,7 +258,7 @@ public function has($id): bool $thrown = null; try { $containerProxy->has('123'); - } catch (\Throwable $e) { + } catch (Throwable $e) { $thrown = $e; } diff --git a/tests/Unit/Collector/EventDispatcherInterfaceProxyTest.php b/tests/Unit/Collector/EventDispatcherInterfaceProxyTest.php index be091d9f2..0f198909c 100644 --- a/tests/Unit/Collector/EventDispatcherInterfaceProxyTest.php +++ b/tests/Unit/Collector/EventDispatcherInterfaceProxyTest.php @@ -13,7 +13,7 @@ final class EventDispatcherInterfaceProxyTest extends TestCase { - public function testDispatch() + public function testDispatch(): void { $event = new stdClass(); $collector = new EventCollector(new TimelineCollector()); diff --git a/tests/Unit/Collector/ExceptionCollectorTest.php b/tests/Unit/Collector/ExceptionCollectorTest.php index 6ed1de5cf..c25b0a8d2 100644 --- a/tests/Unit/Collector/ExceptionCollectorTest.php +++ b/tests/Unit/Collector/ExceptionCollectorTest.php @@ -70,7 +70,7 @@ protected function checkSummaryData(array $data): void $this->assertEquals(777, $exception['code']); } - public function testNoExceptionCollected() + public function testNoExceptionCollected(): void { $collector = new ExceptionCollector(new TimelineCollector()); diff --git a/tests/Unit/Collector/FilesystemStreamCollectorTest.php b/tests/Unit/Collector/FilesystemStreamCollectorTest.php index 844f6a835..06b0ca8ea 100644 --- a/tests/Unit/Collector/FilesystemStreamCollectorTest.php +++ b/tests/Unit/Collector/FilesystemStreamCollectorTest.php @@ -65,12 +65,12 @@ public function testSkipCollectOnMatchIgnoreReferences( public static function dataSkipCollectOnMatchIgnoreReferences(): iterable { - $mkdirBefore = function (string $path) { + $mkdirBefore = static function (string $path) { if (is_dir($path)) { @rmdir($path); } }; - $mkdirOperation = function (string $path) { + $mkdirOperation = static function (string $path) { mkdir($path, 0777, true); }; $mkdirAfter = $mkdirBefore; @@ -84,7 +84,7 @@ public static function dataSkipCollectOnMatchIgnoreReferences(): iterable $mkdirAfter, [ 'mkdir' => [ - ['path' => $path, 'args' => ['mode' => 0777, 'options' => 9]], // 9 for some reasons + ['path' => $path, 'args' => ['mode' => 0777, 'options' => 9]], // 9 for some reason ], ], ]; @@ -107,7 +107,7 @@ public static function dataSkipCollectOnMatchIgnoreReferences(): iterable [], ]; - $renameBefore = function (string $path) { + $renameBefore = static function (string $path) { if (!is_dir(dirname($path))) { mkdir(dirname($path), 0777, true); } @@ -115,10 +115,10 @@ public static function dataSkipCollectOnMatchIgnoreReferences(): iterable touch($path); } }; - $renameOperation = function (string $path) { + $renameOperation = static function (string $path) { rename($path, $path . '.renamed'); }; - $renameAfter = function (string $path) { + $renameAfter = static function (string $path) { FileHelper::removeDirectory(dirname($path)); }; @@ -154,15 +154,15 @@ public static function dataSkipCollectOnMatchIgnoreReferences(): iterable [], ]; - $rmdirBefore = function (string $path) { + $rmdirBefore = static function (string $path): void { if (!is_dir($path)) { mkdir($path, 0777, true); } }; - $rmdirOperation = function (string $path) { + $rmdirOperation = static function (string $path): void { rmdir($path); }; - $rmdirAfter = function (string $path) { + $rmdirAfter = static function (string $path): void { if (is_dir($path)) { rmdir($path); } @@ -177,7 +177,7 @@ public static function dataSkipCollectOnMatchIgnoreReferences(): iterable $rmdirAfter, [ 'rmdir' => [ - ['path' => $path, 'args' => ['options' => 8]], // 8 for some reasons + ['path' => $path, 'args' => ['options' => 8]], // 8 for some reason ], ], ]; @@ -200,7 +200,7 @@ public static function dataSkipCollectOnMatchIgnoreReferences(): iterable [], ]; - $unlinkBefore = function (string $path) { + $unlinkBefore = static function (string $path) { if (!is_dir(dirname($path))) { mkdir(dirname($path), 0777, true); } @@ -208,10 +208,10 @@ public static function dataSkipCollectOnMatchIgnoreReferences(): iterable touch($path); } }; - $unlinkOperation = function (string $path) { + $unlinkOperation = static function (string $path) { unlink($path); }; - $unlinkAfter = function (string $path) { + $unlinkAfter = static function (string $path) { FileHelper::removeDirectory(dirname($path)); }; @@ -247,7 +247,7 @@ public static function dataSkipCollectOnMatchIgnoreReferences(): iterable [], ]; - $fileStreamBefore = function (string $path) { + $fileStreamBefore = static function (string $path) { if (!is_dir(dirname($path))) { mkdir(dirname($path), 0777, true); } @@ -255,7 +255,7 @@ public static function dataSkipCollectOnMatchIgnoreReferences(): iterable touch($path); } }; - $fileStreamOperation = function (string $path) { + $fileStreamOperation = static function (string $path) { $stream = fopen($path, 'a+'); fwrite($stream, 'test'); fread($stream, 4); @@ -267,7 +267,7 @@ public static function dataSkipCollectOnMatchIgnoreReferences(): iterable flock($stream, LOCK_EX); fclose($stream); }; - $fileStreamAfter = function (string $path) { + $fileStreamAfter = static function (string $path) { FileHelper::removeDirectory(dirname($path)); }; diff --git a/tests/Unit/Collector/HttpClientInterfaceProxyTest.php b/tests/Unit/Collector/HttpClientInterfaceProxyTest.php index 188b2c9fd..e6b1e96e7 100644 --- a/tests/Unit/Collector/HttpClientInterfaceProxyTest.php +++ b/tests/Unit/Collector/HttpClientInterfaceProxyTest.php @@ -14,7 +14,7 @@ final class HttpClientInterfaceProxyTest extends TestCase { - public function testSendRequest() + public function testSendRequest(): void { $request = new Request('GET', 'http://example.com'); $response = new Response(200, [], 'test'); diff --git a/tests/Unit/Collector/HttpStreamCollectorTest.php b/tests/Unit/Collector/HttpStreamCollectorTest.php index 922deb083..8664174d9 100644 --- a/tests/Unit/Collector/HttpStreamCollectorTest.php +++ b/tests/Unit/Collector/HttpStreamCollectorTest.php @@ -68,7 +68,7 @@ public static function dataSkipCollectOnMatchIgnoreReferences(): iterable { $httpStreamBefore = function (string $url) { }; - $httpStreamOperation = function (string $url) { + $httpStreamOperation = static function (string $url) { $stream = fopen($url, 'r'); fread($stream, 4); ftell($stream); diff --git a/tests/Unit/Collector/Stream/FilesystemStreamProxyTest.php b/tests/Unit/Collector/Stream/FilesystemStreamProxyTest.php index abaf202a8..ff6812a2e 100644 --- a/tests/Unit/Collector/Stream/FilesystemStreamProxyTest.php +++ b/tests/Unit/Collector/Stream/FilesystemStreamProxyTest.php @@ -14,7 +14,7 @@ protected function tearDown(): void FilesystemStreamProxy::unregister(); } - public function testRegisteredTwice() + public function testRegisteredTwice(): void { FilesystemStreamProxy::unregister(); $this->assertFalse(FilesystemStreamProxy::$registered); @@ -24,7 +24,7 @@ public function testRegisteredTwice() $this->assertTrue(FilesystemStreamProxy::$registered); } - public function testProxyAccess() + public function testProxyAccess(): void { $proxy = new FilesystemStreamProxy(); FilesystemStreamProxy::register(); diff --git a/tests/Unit/Collector/Stream/HttpStreamProxyTest.php b/tests/Unit/Collector/Stream/HttpStreamProxyTest.php index 51f2acea5..a2f01dab4 100644 --- a/tests/Unit/Collector/Stream/HttpStreamProxyTest.php +++ b/tests/Unit/Collector/Stream/HttpStreamProxyTest.php @@ -14,7 +14,7 @@ protected function tearDown(): void HttpStreamProxy::unregister(); } - public function testRegisteredTwice() + public function testRegisteredTwice(): void { HttpStreamProxy::unregister(); $this->assertFalse(HttpStreamProxy::$registered); diff --git a/tests/Unit/Command/DebugContainerCommandTest.php b/tests/Unit/Command/DebugContainerCommandTest.php index 699bd8fe2..07778828d 100644 --- a/tests/Unit/Command/DebugContainerCommandTest.php +++ b/tests/Unit/Command/DebugContainerCommandTest.php @@ -21,7 +21,7 @@ final class DebugContainerCommandTest extends TestCase { - public function testCommand() + public function testCommand(): void { $container = $this->createContainer(); $idGenerator = new DebuggerIdGenerator(); diff --git a/tests/Unit/Command/DebugEventsCommandTest.php b/tests/Unit/Command/DebugEventsCommandTest.php index 7862c8b11..cce470244 100644 --- a/tests/Unit/Command/DebugEventsCommandTest.php +++ b/tests/Unit/Command/DebugEventsCommandTest.php @@ -21,7 +21,7 @@ final class DebugEventsCommandTest extends TestCase { - public function testCommand() + public function testCommand(): void { $container = $this->createContainer(); $idGenerator = new DebuggerIdGenerator(); diff --git a/tests/Unit/Command/ResetCommandTest.php b/tests/Unit/Command/ResetCommandTest.php index 1aa8bafce..a9d1cff96 100644 --- a/tests/Unit/Command/ResetCommandTest.php +++ b/tests/Unit/Command/ResetCommandTest.php @@ -13,7 +13,7 @@ final class ResetCommandTest extends TestCase { - public function testCommand() + public function testCommand(): void { $idGenerator = new DebuggerIdGenerator(); $storage = $this->createMock(StorageInterface::class); diff --git a/tests/Unit/DumperTest.php b/tests/Unit/DumperTest.php index 277494a34..8ffcb2775 100644 --- a/tests/Unit/DumperTest.php +++ b/tests/Unit/DumperTest.php @@ -11,6 +11,12 @@ use Yiisoft\Yii\Debug\Dumper; use Yiisoft\Yii\Debug\Tests\Support\Stub\ThreeProperties; +use function socket_create; + +use const AF_INET; +use const SOCK_STREAM; +use const SOL_TCP; + final class DumperTest extends TestCase { /** @@ -95,9 +101,7 @@ public function testCacheDoesNotCoversObjectOutOfDumpDepth(): void public function testDepthLimitInObjectMap(): void { $variable = [1, []]; - $expectedResult = sprintf( - '"array (2 items) [...]"', - ); + $expectedResult = '"array (2 items) [...]"'; $dumper = Dumper::create($variable); $actualResult = $dumper->asJson(0); @@ -459,7 +463,7 @@ public static function jsonDataProvider(): iterable '"{closed resource}"', ]; - $socketResource = \socket_create(\AF_INET, \SOCK_STREAM, \SOL_TCP); + $socketResource = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); $socketResourceId = spl_object_id($socketResource); yield 'socket resource' => [ $socketResource, diff --git a/tests/Unit/Event/ProxyMethodCallEventTest.php b/tests/Unit/Event/ProxyMethodCallEventTest.php index 8673aad14..079f53b72 100644 --- a/tests/Unit/Event/ProxyMethodCallEventTest.php +++ b/tests/Unit/Event/ProxyMethodCallEventTest.php @@ -5,6 +5,7 @@ namespace Yiisoft\Yii\Debug\Tests\Unit\Event; use PHPUnit\Framework\TestCase; +use stdClass; use Yiisoft\Yii\Debug\Event\ProxyMethodCallEvent; class ProxyMethodCallEventTest extends TestCase @@ -14,7 +15,7 @@ public function testEvent(): void $time = microtime(true); $event = new ProxyMethodCallEvent( 'test', - \stdClass::class, + stdClass::class, 'test', [], true, @@ -26,6 +27,6 @@ public function testEvent(): void $this->assertEquals($time, $event->timeStart); $this->assertEquals($time + 1, $event->timeEnd); - $this->assertEquals(\stdClass::class, $event->class); + $this->assertEquals(stdClass::class, $event->class); } } diff --git a/tests/Unit/FlattenExceptionTest.php b/tests/Unit/FlattenExceptionTest.php index ec8093976..63329ec2c 100644 --- a/tests/Unit/FlattenExceptionTest.php +++ b/tests/Unit/FlattenExceptionTest.php @@ -4,38 +4,41 @@ namespace Yiisoft\Yii\Debug\Tests\Unit; +use Closure; +use Exception; use PHPUnit\Framework\TestCase; +use RuntimeException; use Yiisoft\Yii\Debug\FlattenException; final class FlattenExceptionTest extends TestCase { public function testMessage(): void { - $flattened = new FlattenException(new \Exception('test')); + $flattened = new FlattenException(new Exception('test')); $this->assertEquals('test', $flattened->getMessage()); } public function testCode(): void { - $flattened = new FlattenException(new \Exception('test', 100)); + $flattened = new FlattenException(new Exception('test', 100)); $this->assertEquals(100, $flattened->getCode()); } public function testFile(): void { - $flattened = new FlattenException(new \Exception('test', 100)); + $flattened = new FlattenException(new Exception('test', 100)); $this->assertEquals(__FILE__, $flattened->getFile()); } public function testLine(): void { - $flattened = new FlattenException(new \Exception('test', 100)); + $flattened = new FlattenException(new Exception('test', 100)); $this->assertEquals(__LINE__ - 1, $flattened->getLine()); } public function testTrace(): void { - $i = (new \Exception('test')); + $i = (new Exception('test')); $flattened = new FlattenException($i); $trace = $flattened->getTrace(); @@ -47,8 +50,8 @@ public function testTrace(): void public function testPrevious(): void { - $exception2 = new \Exception(); - $exception = new \Exception('test', 0, $exception2); + $exception2 = new Exception(); + $exception = new Exception('test', 0, $exception2); $flattened = new FlattenException($exception); $flattened2 = new FlattenException($exception2); @@ -64,15 +67,15 @@ public function testTraceAsString(): void public function testToString(): void { - $exception = new \Exception(); + $exception = new Exception(); $this->assertEquals($exception->__toString(), (new FlattenException($exception))->__toString(), 'empty'); - $exception = new \Exception('test'); + $exception = new Exception('test'); $this->assertEquals($exception->__toString(), (new FlattenException($exception))->__toString()); } public function testClass(): void { - $this->assertEquals('Exception', (new FlattenException(new \Exception()))->getClass()); + $this->assertEquals('Exception', (new FlattenException(new Exception()))->getClass()); } public function testArguments(): void @@ -86,7 +89,7 @@ public function testArguments(): void $exception = $this->createException([ (object)['foo' => 1], - new \RuntimeException('test'), + new RuntimeException('test'), $incomplete, $dh, $fh, @@ -115,14 +118,14 @@ function () { $i = 0; $this->assertSame(['object', 'stdClass'], $array[$i++]); - $this->assertSame(['object', \RuntimeException::class], $array[$i++]); + $this->assertSame(['object', RuntimeException::class], $array[$i++]); $this->assertSame(['incomplete-object', 'BogusTestClass'], $array[$i++]); $this->assertSame(['resource', 'stream'], $array[$i++]); $this->assertSame(['resource', 'stream'], $array[$i++]); $args = $array[$i++]; $this->assertSame($args[0], 'object'); - $this->assertTrue(\Closure::class === $args[1] || is_subclass_of($args[1], '\\' . \Closure::class), 'Expect object class name to be Closure or a subclass of Closure.'); + $this->assertTrue(Closure::class === $args[1] || is_subclass_of($args[1], '\\' . Closure::class), 'Expect object class name to be Closure or a subclass of Closure.'); $this->assertSame(['array', [['integer', 1], ['integer', 2]]], $array[$i++]); $this->assertSame(['array', ['foo' => ['integer', 123]]], $array[$i++]); @@ -145,7 +148,7 @@ public function testClosureSerialize(): void $exception = $this->createException(fn () => 1 + 1); $flattened = new FlattenException($exception); - $this->assertStringContainsString(\Closure::class, serialize($flattened)); + $this->assertStringContainsString(Closure::class, serialize($flattened)); } public function testRecursionInArguments(): void @@ -188,8 +191,8 @@ public function testTooBigArray(): void $this->assertStringNotContainsString('*value1*', $serializeTrace); } - private function createException($foo): \Exception + private function createException($foo): Exception { - return new \Exception(); + return new Exception(); } } diff --git a/tests/Unit/Helper/BacktraceIgnoreMatcherTest.php b/tests/Unit/Helper/BacktraceIgnoreMatcherTest.php index 98231d0f2..8176a5eb3 100644 --- a/tests/Unit/Helper/BacktraceIgnoreMatcherTest.php +++ b/tests/Unit/Helper/BacktraceIgnoreMatcherTest.php @@ -5,6 +5,7 @@ namespace Yiisoft\Yii\Debug\Tests\Unit\Helper; use PHPUnit\Framework\TestCase; +use ReflectionClass; use stdClass; use Yiisoft\Yii\Debug\Helper\BacktraceIgnoreMatcher; @@ -26,7 +27,7 @@ public function testClassIgnorance(): void public function testFileIgnorance(): void { $backtrace = debug_backtrace(); - $reflection = new \ReflectionClass(TestCase::class); + $reflection = new ReflectionClass(TestCase::class); $file = $reflection->getFileName(); $this->assertFalse(BacktraceIgnoreMatcher::isIgnoredByFile($backtrace, [preg_quote($file)])); diff --git a/tests/Unit/Storage/AbstractStorageTestCase.php b/tests/Unit/Storage/AbstractStorageTestCase.php index 004bd2e90..12d997b4c 100644 --- a/tests/Unit/Storage/AbstractStorageTestCase.php +++ b/tests/Unit/Storage/AbstractStorageTestCase.php @@ -13,6 +13,8 @@ use Yiisoft\Yii\Debug\Storage\MemoryStorage; use Yiisoft\Yii\Debug\Storage\StorageInterface; +use function json_decode; + abstract class AbstractStorageTestCase extends TestCase { /** @@ -40,7 +42,7 @@ public function testRead(array $data): void $storage->addCollector($this->createFakeCollector($data)); $storage->addCollector($this->createFakeSummaryCollector($data)); $expectedData = $storage->getData(); - $encodedExpectedData = \json_decode(Dumper::create($expectedData)->asJson(), true, 512, JSON_THROW_ON_ERROR); + $encodedExpectedData = json_decode(Dumper::create($expectedData)->asJson(), true, 512, JSON_THROW_ON_ERROR); if (!$storage instanceof MemoryStorage) { $storage->flush(); @@ -48,7 +50,7 @@ public function testRead(array $data): void $result = $storage->read(StorageInterface::TYPE_DATA); $dumper = Dumper::create($result); - $encodedResult = \json_decode($dumper->asJson(), true, 512, JSON_THROW_ON_ERROR); + $encodedResult = json_decode($dumper->asJson(), true, 512, JSON_THROW_ON_ERROR); $this->assertEquals([$idGenerator->getId() => $encodedExpectedData], $encodedResult); } diff --git a/tests/Unit/Storage/MemoryStorageTest.php b/tests/Unit/Storage/MemoryStorageTest.php index a74e37eb3..06107ba03 100644 --- a/tests/Unit/Storage/MemoryStorageTest.php +++ b/tests/Unit/Storage/MemoryStorageTest.php @@ -15,7 +15,7 @@ public function getStorage(DebuggerIdGenerator $idGenerator): StorageInterface return new MemoryStorage($idGenerator); } - public function testSummaryCount() + public function testSummaryCount(): void { $idGenerator = new DebuggerIdGenerator(); $storage = $this->getStorage($idGenerator); From 90f3a79fb894eb0d49d6dce09e3b7b625f49a05a Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Wed, 19 Jun 2024 20:35:27 +0000 Subject: [PATCH 2/5] Apply fixes from StyleCI --- src/Collector/Console/CommandCollector.php | 3 +-- .../Console/ConsoleAppInfoCollector.php | 3 +-- src/Collector/EventCollector.php | 3 +-- src/Collector/ExceptionCollector.php | 3 +-- src/Collector/HttpClientCollector.php | 3 +-- src/Collector/HttpClientInterfaceProxy.php | 3 +-- src/Collector/LogCollector.php | 3 +-- src/Collector/LoggerInterfaceProxy.php | 3 +-- src/Collector/ServiceCollector.php | 3 +-- src/Collector/VarDumperCollector.php | 3 +-- src/Collector/Web/MiddlewareCollector.php | 3 +-- src/Collector/Web/RequestCollector.php | 3 +-- src/Collector/Web/WebAppInfoCollector.php | 3 +-- src/Dumper.php | 3 +-- src/Storage/FileStorage.php | 1 - src/Storage/MemoryStorage.php | 3 +-- .../Collector/ContainerInterfaceProxyTest.php | 23 ++++++++++--------- 17 files changed, 27 insertions(+), 42 deletions(-) diff --git a/src/Collector/Console/CommandCollector.php b/src/Collector/Console/CommandCollector.php index 97ceba2ee..bd2a2d140 100644 --- a/src/Collector/Console/CommandCollector.php +++ b/src/Collector/Console/CommandCollector.php @@ -27,8 +27,7 @@ final class CommandCollector implements SummaryCollectorInterface public function __construct( private readonly TimelineCollector $timelineCollector - ) - { + ) { } public function getCollected(): array diff --git a/src/Collector/Console/ConsoleAppInfoCollector.php b/src/Collector/Console/ConsoleAppInfoCollector.php index c6a8ad085..5594c482f 100644 --- a/src/Collector/Console/ConsoleAppInfoCollector.php +++ b/src/Collector/Console/ConsoleAppInfoCollector.php @@ -24,8 +24,7 @@ final class ConsoleAppInfoCollector implements SummaryCollectorInterface public function __construct( private readonly TimelineCollector $timelineCollector - ) - { + ) { } public function getCollected(): array diff --git a/src/Collector/EventCollector.php b/src/Collector/EventCollector.php index dd2161827..e7978539f 100644 --- a/src/Collector/EventCollector.php +++ b/src/Collector/EventCollector.php @@ -16,8 +16,7 @@ final class EventCollector implements SummaryCollectorInterface public function __construct( private readonly TimelineCollector $timelineCollector - ) - { + ) { } public function getCollected(): array diff --git a/src/Collector/ExceptionCollector.php b/src/Collector/ExceptionCollector.php index 77563bbd8..1dd6a8f47 100644 --- a/src/Collector/ExceptionCollector.php +++ b/src/Collector/ExceptionCollector.php @@ -15,8 +15,7 @@ final class ExceptionCollector implements SummaryCollectorInterface public function __construct( private readonly TimelineCollector $timelineCollector - ) - { + ) { } public function getCollected(): array diff --git a/src/Collector/HttpClientCollector.php b/src/Collector/HttpClientCollector.php index ab634fda2..7f14da53c 100644 --- a/src/Collector/HttpClientCollector.php +++ b/src/Collector/HttpClientCollector.php @@ -34,8 +34,7 @@ final class HttpClientCollector implements SummaryCollectorInterface public function __construct( private readonly TimelineCollector $timelineCollector - ) - { + ) { } public function collect(RequestInterface $request, float $startTime, string $line, string $uniqueId): void diff --git a/src/Collector/HttpClientInterfaceProxy.php b/src/Collector/HttpClientInterfaceProxy.php index bcfb400c1..158180a7d 100644 --- a/src/Collector/HttpClientInterfaceProxy.php +++ b/src/Collector/HttpClientInterfaceProxy.php @@ -13,8 +13,7 @@ final class HttpClientInterfaceProxy implements ClientInterface public function __construct( private readonly ClientInterface $decorated, private readonly HttpClientCollector $collector - ) - { + ) { } public function sendRequest(RequestInterface $request): ResponseInterface diff --git a/src/Collector/LogCollector.php b/src/Collector/LogCollector.php index e69d56cdc..d6aa5fa66 100644 --- a/src/Collector/LogCollector.php +++ b/src/Collector/LogCollector.php @@ -12,8 +12,7 @@ class LogCollector implements SummaryCollectorInterface public function __construct( private readonly TimelineCollector $timelineCollector - ) - { + ) { } public function getCollected(): array diff --git a/src/Collector/LoggerInterfaceProxy.php b/src/Collector/LoggerInterfaceProxy.php index 0783602aa..7576e33f6 100644 --- a/src/Collector/LoggerInterfaceProxy.php +++ b/src/Collector/LoggerInterfaceProxy.php @@ -13,8 +13,7 @@ final class LoggerInterfaceProxy implements LoggerInterface public function __construct( private readonly LoggerInterface $logger, private readonly LogCollector $collector - ) - { + ) { } public function emergency(string|Stringable $message, array $context = []): void diff --git a/src/Collector/ServiceCollector.php b/src/Collector/ServiceCollector.php index c061312df..31a48e6c2 100644 --- a/src/Collector/ServiceCollector.php +++ b/src/Collector/ServiceCollector.php @@ -12,8 +12,7 @@ final class ServiceCollector implements SummaryCollectorInterface public function __construct( private readonly TimelineCollector $timelineCollector - ) - { + ) { } public function getCollected(): array diff --git a/src/Collector/VarDumperCollector.php b/src/Collector/VarDumperCollector.php index 3798ab9fe..045804912 100644 --- a/src/Collector/VarDumperCollector.php +++ b/src/Collector/VarDumperCollector.php @@ -12,8 +12,7 @@ final class VarDumperCollector implements SummaryCollectorInterface public function __construct( private readonly TimelineCollector $timelineCollector - ) - { + ) { } public function collect(mixed $variable, string $line): void diff --git a/src/Collector/Web/MiddlewareCollector.php b/src/Collector/Web/MiddlewareCollector.php index d41cdc4ab..784aa0370 100644 --- a/src/Collector/Web/MiddlewareCollector.php +++ b/src/Collector/Web/MiddlewareCollector.php @@ -20,8 +20,7 @@ final class MiddlewareCollector implements SummaryCollectorInterface public function __construct( private readonly TimelineCollector $timelineCollector - ) - { + ) { } public function getCollected(): array diff --git a/src/Collector/Web/RequestCollector.php b/src/Collector/Web/RequestCollector.php index 9a37cc3c1..cacaaeb44 100644 --- a/src/Collector/Web/RequestCollector.php +++ b/src/Collector/Web/RequestCollector.php @@ -29,8 +29,7 @@ final class RequestCollector implements SummaryCollectorInterface public function __construct( private readonly TimelineCollector $timelineCollector - ) - { + ) { } public function getCollected(): array diff --git a/src/Collector/Web/WebAppInfoCollector.php b/src/Collector/Web/WebAppInfoCollector.php index e2fe70afc..6a0c55337 100644 --- a/src/Collector/Web/WebAppInfoCollector.php +++ b/src/Collector/Web/WebAppInfoCollector.php @@ -23,8 +23,7 @@ final class WebAppInfoCollector implements SummaryCollectorInterface public function __construct( private readonly TimelineCollector $timelineCollector - ) - { + ) { } public function getCollected(): array diff --git a/src/Dumper.php b/src/Dumper.php index c9433d0a6..9ea6377bd 100644 --- a/src/Dumper.php +++ b/src/Dumper.php @@ -22,8 +22,7 @@ final class Dumper private function __construct( private readonly mixed $variable, array $excludedClasses - ) - { + ) { $this->excludedClasses = array_flip($excludedClasses); } diff --git a/src/Storage/FileStorage.php b/src/Storage/FileStorage.php index 7c11425ca..6ec96c340 100644 --- a/src/Storage/FileStorage.php +++ b/src/Storage/FileStorage.php @@ -11,7 +11,6 @@ use Yiisoft\Yii\Debug\DebuggerIdGenerator; use Yiisoft\Yii\Debug\Dumper; -use function array_merge; use function array_slice; use function count; use function dirname; diff --git a/src/Storage/MemoryStorage.php b/src/Storage/MemoryStorage.php index 4efc011c2..a38776aa6 100644 --- a/src/Storage/MemoryStorage.php +++ b/src/Storage/MemoryStorage.php @@ -16,8 +16,7 @@ final class MemoryStorage implements StorageInterface public function __construct( private readonly DebuggerIdGenerator $idGenerator - ) - { + ) { } public function addCollector(CollectorInterface $collector): void diff --git a/tests/Unit/Collector/ContainerInterfaceProxyTest.php b/tests/Unit/Collector/ContainerInterfaceProxyTest.php index 54215ea23..26cdc5900 100644 --- a/tests/Unit/Collector/ContainerInterfaceProxyTest.php +++ b/tests/Unit/Collector/ContainerInterfaceProxyTest.php @@ -194,18 +194,19 @@ public function testHasThrowsExceptionButErrorInCollectorIsAbsent(): void $container = new CompositeContainer(); $container->attach( container: new class () implements ContainerInterface { - public function get($id) - { - throw new class () extends Exception implements ContainerExceptionInterface { - }; - } - - public function has($id): bool - { - throw new class () extends Exception implements ContainerExceptionInterface { - }; + public function get($id) + { + throw new class () extends Exception implements ContainerExceptionInterface { + }; + } + + public function has($id): bool + { + throw new class () extends Exception implements ContainerExceptionInterface { + }; + } } - }); + ); $container->attach($container); $config = $this->createConfig(ContainerInterfaceProxy::LOG_NOTHING); From 64c08fbe11612edfdeddb5196a1fc1bf9fc4ca35 Mon Sep 17 00:00:00 2001 From: samdark Date: Wed, 19 Jun 2024 20:35:53 +0000 Subject: [PATCH 3/5] Apply Rector changes (CI) --- src/Collector/Stream/HttpStreamCollector.php | 10 ++-------- src/Dumper.php | 5 ----- 2 files changed, 2 insertions(+), 13 deletions(-) diff --git a/src/Collector/Stream/HttpStreamCollector.php b/src/Collector/Stream/HttpStreamCollector.php index 6896971af..c7687c25b 100644 --- a/src/Collector/Stream/HttpStreamCollector.php +++ b/src/Collector/Stream/HttpStreamCollector.php @@ -11,14 +11,8 @@ final class HttpStreamCollector implements SummaryCollectorInterface { use CollectorTrait; - private array $ignoredPathPatterns; - - public function __construct( - array $ignoredPathPatterns = [], - private readonly array $ignoredClasses = [], - private readonly array $ignoredUrls = [] - ) { - $this->ignoredPathPatterns = $ignoredPathPatterns; + public function __construct(private array $ignoredPathPatterns = [], private readonly array $ignoredClasses = [], private readonly array $ignoredUrls = []) + { } private array $requests = []; diff --git a/src/Dumper.php b/src/Dumper.php index 9ea6377bd..59ab5d8df 100644 --- a/src/Dumper.php +++ b/src/Dumper.php @@ -16,9 +16,6 @@ final class Dumper private static ?ClosureExporter $closureExporter = null; private array $excludedClasses; - /** - * @param mixed $variable Variable to dump. - */ private function __construct( private readonly mixed $variable, array $excludedClasses @@ -27,8 +24,6 @@ private function __construct( } /** - * @param mixed $variable Variable to dump. - * * @return self An instance containing variable to dump. */ public static function create(mixed $variable, array $excludedClasses = []): self From 51700a079b3bc90a5a4c956a6721bf0327df826d Mon Sep 17 00:00:00 2001 From: Alexander Makarov Date: Wed, 19 Jun 2024 23:37:39 +0300 Subject: [PATCH 4/5] More cleanup --- src/Collector/Stream/HttpStreamCollector.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Collector/Stream/HttpStreamCollector.php b/src/Collector/Stream/HttpStreamCollector.php index c7687c25b..9cda2e828 100644 --- a/src/Collector/Stream/HttpStreamCollector.php +++ b/src/Collector/Stream/HttpStreamCollector.php @@ -11,8 +11,11 @@ final class HttpStreamCollector implements SummaryCollectorInterface { use CollectorTrait; - public function __construct(private array $ignoredPathPatterns = [], private readonly array $ignoredClasses = [], private readonly array $ignoredUrls = []) - { + public function __construct( + private readonly array $ignoredPathPatterns = [], + private readonly array $ignoredClasses = [], + private readonly array $ignoredUrls = [] + ) { } private array $requests = []; From 6bd33518c95c4938855fa75e5e9dd30daa1c9fb8 Mon Sep 17 00:00:00 2001 From: Alexander Makarov Date: Fri, 21 Jun 2024 15:46:48 +0300 Subject: [PATCH 5/5] Update src/Collector/ProxyLogTrait.php Co-authored-by: Sergei Predvoditelev --- src/Collector/ProxyLogTrait.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Collector/ProxyLogTrait.php b/src/Collector/ProxyLogTrait.php index 3620ab49f..2b2b80918 100644 --- a/src/Collector/ProxyLogTrait.php +++ b/src/Collector/ProxyLogTrait.php @@ -33,7 +33,7 @@ protected function logProxy( /** * @psalm-param-out array|null $arguments */ - private function processLogData(?array &$arguments, mixed &$result, ?object &$error): void + private function processLogData(array &$arguments, mixed &$result, ?object &$error): void { if (!($this->config->getLogLevel() & ContainerInterfaceProxy::LOG_ARGUMENTS)) { $arguments = null;