diff --git a/src/Symfony/Component/VarDumper/Caster/CutStub.php b/src/Symfony/Component/VarDumper/Caster/CutStub.php index 464c6dbd1905d..b5a96a02cfcdc 100644 --- a/src/Symfony/Component/VarDumper/Caster/CutStub.php +++ b/src/Symfony/Component/VarDumper/Caster/CutStub.php @@ -20,7 +20,7 @@ */ class CutStub extends Stub { - public function __construct($value) + public function __construct(mixed $value) { $this->value = $value; diff --git a/src/Symfony/Component/VarDumper/Caster/DsPairStub.php b/src/Symfony/Component/VarDumper/Caster/DsPairStub.php index a1dcc156183e9..22112af9c073d 100644 --- a/src/Symfony/Component/VarDumper/Caster/DsPairStub.php +++ b/src/Symfony/Component/VarDumper/Caster/DsPairStub.php @@ -18,7 +18,7 @@ */ class DsPairStub extends Stub { - public function __construct($key, $value) + public function __construct(string|int $key, mixed $value) { $this->value = [ Caster::PREFIX_VIRTUAL.'key' => $key, diff --git a/src/Symfony/Component/VarDumper/Caster/LinkStub.php b/src/Symfony/Component/VarDumper/Caster/LinkStub.php index 0aa076a265846..e937cdc3efdc4 100644 --- a/src/Symfony/Component/VarDumper/Caster/LinkStub.php +++ b/src/Symfony/Component/VarDumper/Caster/LinkStub.php @@ -23,7 +23,7 @@ class LinkStub extends ConstStub private static $vendorRoots; private static $composerRoots; - public function __construct($label, int $line = 0, $href = null) + public function __construct(string $label, int $line = 0, string $href = null) { $this->value = $label; diff --git a/src/Symfony/Component/VarDumper/Caster/RdKafkaCaster.php b/src/Symfony/Component/VarDumper/Caster/RdKafkaCaster.php index c3e4eb9f341c6..8053363956637 100644 --- a/src/Symfony/Component/VarDumper/Caster/RdKafkaCaster.php +++ b/src/Symfony/Component/VarDumper/Caster/RdKafkaCaster.php @@ -31,7 +31,7 @@ */ class RdKafkaCaster { - public static function castKafkaConsumer(KafkaConsumer $c, array $a, Stub $stub, $isNested) + public static function castKafkaConsumer(KafkaConsumer $c, array $a, Stub $stub, bool $isNested) { $prefix = Caster::PREFIX_VIRTUAL; @@ -51,7 +51,7 @@ public static function castKafkaConsumer(KafkaConsumer $c, array $a, Stub $stub, return $a; } - public static function castTopic(Topic $c, array $a, Stub $stub, $isNested) + public static function castTopic(Topic $c, array $a, Stub $stub, bool $isNested) { $prefix = Caster::PREFIX_VIRTUAL; @@ -75,7 +75,7 @@ public static function castTopicPartition(TopicPartition $c, array $a) return $a; } - public static function castMessage(Message $c, array $a, Stub $stub, $isNested) + public static function castMessage(Message $c, array $a, Stub $stub, bool $isNested) { $prefix = Caster::PREFIX_VIRTUAL; @@ -86,7 +86,7 @@ public static function castMessage(Message $c, array $a, Stub $stub, $isNested) return $a; } - public static function castConf(Conf $c, array $a, Stub $stub, $isNested) + public static function castConf(Conf $c, array $a, Stub $stub, bool $isNested) { $prefix = Caster::PREFIX_VIRTUAL; @@ -97,7 +97,7 @@ public static function castConf(Conf $c, array $a, Stub $stub, $isNested) return $a; } - public static function castTopicConf(TopicConf $c, array $a, Stub $stub, $isNested) + public static function castTopicConf(TopicConf $c, array $a, Stub $stub, bool $isNested) { $prefix = Caster::PREFIX_VIRTUAL; @@ -108,7 +108,7 @@ public static function castTopicConf(TopicConf $c, array $a, Stub $stub, $isNest return $a; } - public static function castRdKafka(\RdKafka $c, array $a, Stub $stub, $isNested) + public static function castRdKafka(\RdKafka $c, array $a, Stub $stub, bool $isNested) { $prefix = Caster::PREFIX_VIRTUAL; @@ -121,14 +121,14 @@ public static function castRdKafka(\RdKafka $c, array $a, Stub $stub, $isNested) return $a; } - public static function castCollectionMetadata(CollectionMetadata $c, array $a, Stub $stub, $isNested) + public static function castCollectionMetadata(CollectionMetadata $c, array $a, Stub $stub, bool $isNested) { $a += iterator_to_array($c); return $a; } - public static function castTopicMetadata(TopicMetadata $c, array $a, Stub $stub, $isNested) + public static function castTopicMetadata(TopicMetadata $c, array $a, Stub $stub, bool $isNested) { $prefix = Caster::PREFIX_VIRTUAL; @@ -140,7 +140,7 @@ public static function castTopicMetadata(TopicMetadata $c, array $a, Stub $stub, return $a; } - public static function castPartitionMetadata(PartitionMetadata $c, array $a, Stub $stub, $isNested) + public static function castPartitionMetadata(PartitionMetadata $c, array $a, Stub $stub, bool $isNested) { $prefix = Caster::PREFIX_VIRTUAL; @@ -153,7 +153,7 @@ public static function castPartitionMetadata(PartitionMetadata $c, array $a, Stu return $a; } - public static function castBrokerMetadata(BrokerMetadata $c, array $a, Stub $stub, $isNested) + public static function castBrokerMetadata(BrokerMetadata $c, array $a, Stub $stub, bool $isNested) { $prefix = Caster::PREFIX_VIRTUAL; @@ -166,7 +166,7 @@ public static function castBrokerMetadata(BrokerMetadata $c, array $a, Stub $stu return $a; } - private static function extractMetadata($c) + private static function extractMetadata(KafkaConsumer|\RdKafka $c) { $prefix = Caster::PREFIX_VIRTUAL; diff --git a/src/Symfony/Component/VarDumper/Caster/RedisCaster.php b/src/Symfony/Component/VarDumper/Caster/RedisCaster.php index 8f97eaad3bd3f..eac25a12a8b56 100644 --- a/src/Symfony/Component/VarDumper/Caster/RedisCaster.php +++ b/src/Symfony/Component/VarDumper/Caster/RedisCaster.php @@ -102,10 +102,7 @@ public static function castRedisCluster(\RedisCluster $c, array $a, Stub $stub, return $a; } - /** - * @param \Redis|\RedisArray|\RedisCluster $redis - */ - private static function getRedisOptions($redis, array $options = []): EnumStub + private static function getRedisOptions(\Redis|\RedisArray|\RedisCluster $redis, array $options = []): EnumStub { $serializer = $redis->getOption(\Redis::OPT_SERIALIZER); if (\is_array($serializer)) { diff --git a/src/Symfony/Component/VarDumper/Caster/ResourceCaster.php b/src/Symfony/Component/VarDumper/Caster/ResourceCaster.php index 6b2ed522364e7..6ae908524f6c1 100644 --- a/src/Symfony/Component/VarDumper/Caster/ResourceCaster.php +++ b/src/Symfony/Component/VarDumper/Caster/ResourceCaster.php @@ -48,7 +48,7 @@ public static function castProcess($process, array $a, Stub $stub, bool $isNeste public static function castStream($stream, array $a, Stub $stub, bool $isNested) { $a = stream_get_meta_data($stream) + static::castStreamContext($stream, $a, $stub, $isNested); - if (isset($a['uri'])) { + if ($a['uri'] ?? false) { $a['uri'] = new LinkStub($a['uri']); } @@ -60,7 +60,7 @@ public static function castStreamContext($stream, array $a, Stub $stub, bool $is return @stream_context_get_params($stream) ?: $a; } - public static function castGd($gd, array $a, Stub $stub, $isNested) + public static function castGd($gd, array $a, Stub $stub, bool $isNested) { $a['size'] = imagesx($gd).'x'.imagesy($gd); $a['trueColor'] = imageistruecolor($gd); diff --git a/src/Symfony/Component/VarDumper/Caster/SplCaster.php b/src/Symfony/Component/VarDumper/Caster/SplCaster.php index 80af4c4c3e38d..c0dbecfc6c77f 100644 --- a/src/Symfony/Component/VarDumper/Caster/SplCaster.php +++ b/src/Symfony/Component/VarDumper/Caster/SplCaster.php @@ -39,7 +39,7 @@ public static function castArrayIterator(\ArrayIterator $c, array $a, Stub $stub return self::castSplArray($c, $a, $stub, $isNested); } - public static function castHeap(\Iterator $c, array $a, Stub $stub, $isNested) + public static function castHeap(\Iterator $c, array $a, Stub $stub, bool $isNested) { $a += [ Caster::PREFIX_VIRTUAL.'heap' => iterator_to_array(clone $c), @@ -121,7 +121,7 @@ public static function castFileInfo(\SplFileInfo $c, array $a, Stub $stub, bool } } - if (isset($a[$prefix.'realPath'])) { + if ($a[$prefix.'realPath'] ?? false) { $a[$prefix.'realPath'] = new LinkStub($a[$prefix.'realPath']); } diff --git a/src/Symfony/Component/VarDumper/Cloner/AbstractCloner.php b/src/Symfony/Component/VarDumper/Cloner/AbstractCloner.php index 1b7fa35eb7015..3b0e07229fa75 100644 --- a/src/Symfony/Component/VarDumper/Cloner/AbstractCloner.php +++ b/src/Symfony/Component/VarDumper/Cloner/AbstractCloner.php @@ -253,12 +253,11 @@ public function setMinDepth(int $minDepth) /** * Clones a PHP variable. * - * @param mixed $var Any PHP variable - * @param int $filter A bit field of Caster::EXCLUDE_* constants + * @param int $filter A bit field of Caster::EXCLUDE_* constants * * @return Data The cloned variable represented by a Data object */ - public function cloneVar($var, int $filter = 0) + public function cloneVar(mixed $var, int $filter = 0) { $this->prevErrorHandler = set_error_handler(function ($type, $msg, $file, $line, $context = []) { if (\E_RECOVERABLE_ERROR === $type || \E_USER_ERROR === $type) { @@ -291,11 +290,9 @@ public function cloneVar($var, int $filter = 0) /** * Effectively clones the PHP variable. * - * @param mixed $var Any PHP variable - * * @return array The cloned variable represented in an array */ - abstract protected function doClone($var); + abstract protected function doClone(mixed $var); /** * Casts an object to an array representation. diff --git a/src/Symfony/Component/VarDumper/Cloner/ClonerInterface.php b/src/Symfony/Component/VarDumper/Cloner/ClonerInterface.php index 7ed287a2ddf0d..fa1df1e8fd3db 100644 --- a/src/Symfony/Component/VarDumper/Cloner/ClonerInterface.php +++ b/src/Symfony/Component/VarDumper/Cloner/ClonerInterface.php @@ -19,9 +19,7 @@ interface ClonerInterface /** * Clones a PHP variable. * - * @param mixed $var Any PHP variable - * * @return Data The cloned variable represented by a Data object */ - public function cloneVar($var); + public function cloneVar(mixed $var); } diff --git a/src/Symfony/Component/VarDumper/Cloner/Data.php b/src/Symfony/Component/VarDumper/Cloner/Data.php index c695a11aef71e..6027d666f2d6e 100644 --- a/src/Symfony/Component/VarDumper/Cloner/Data.php +++ b/src/Symfony/Component/VarDumper/Cloner/Data.php @@ -69,7 +69,7 @@ public function getType() * * @return string|int|float|bool|array|Data[]|null A native representation of the original value */ - public function getValue($recursive = false) + public function getValue(array|bool $recursive = false) { $item = $this->data[$this->position][$this->key]; @@ -239,11 +239,9 @@ public function withContext(array $context) /** * Seeks to a specific key in nested data structures. * - * @param string|int $key The key to seek to - * * @return static|null Null if the key is not set */ - public function seek($key) + public function seek(string|int $key) { $item = $this->data[$this->position][$this->key]; @@ -309,7 +307,7 @@ public function dump(DumperInterface $dumper) * * @param mixed $item A Stub object or the original value being dumped */ - private function dumpItem(DumperInterface $dumper, Cursor $cursor, array &$refs, $item) + private function dumpItem(DumperInterface $dumper, Cursor $cursor, array &$refs, mixed $item) { $cursor->refIndex = 0; $cursor->softRefTo = $cursor->softRefHandle = $cursor->softRefCount = 0; @@ -431,7 +429,7 @@ private function dumpChildren(DumperInterface $dumper, Cursor $parentCursor, arr return $hashCut; } - private function getStub($item) + private function getStub(mixed $item) { if (!$item || !\is_array($item)) { return $item; diff --git a/src/Symfony/Component/VarDumper/Cloner/DumperInterface.php b/src/Symfony/Component/VarDumper/Cloner/DumperInterface.php index 6d60b723c7f79..61d02d2406d66 100644 --- a/src/Symfony/Component/VarDumper/Cloner/DumperInterface.php +++ b/src/Symfony/Component/VarDumper/Cloner/DumperInterface.php @@ -20,11 +20,8 @@ interface DumperInterface { /** * Dumps a scalar value. - * - * @param string $type The PHP type of the value being dumped - * @param string|int|float|bool $value The scalar value being dumped */ - public function dumpScalar(Cursor $cursor, string $type, $value); + public function dumpScalar(Cursor $cursor, string $type, string|int|float|bool|null $value); /** * Dumps a string. @@ -38,19 +35,19 @@ public function dumpString(Cursor $cursor, string $str, bool $bin, int $cut); /** * Dumps while entering an hash. * - * @param int $type A Cursor::HASH_* const for the type of hash - * @param string|int $class The object class, resource type or array count - * @param bool $hasChild When the dump of the hash has child item + * @param int $type A Cursor::HASH_* const for the type of hash + * @param string|int|null $class The object class, resource type or array count + * @param bool $hasChild When the dump of the hash has child item */ - public function enterHash(Cursor $cursor, int $type, $class, bool $hasChild); + public function enterHash(Cursor $cursor, int $type, string|int|null $class, bool $hasChild); /** * Dumps while leaving an hash. * - * @param int $type A Cursor::HASH_* const for the type of hash - * @param string|int $class The object class, resource type or array count - * @param bool $hasChild When the dump of the hash has child item - * @param int $cut The number of items the hash has been cut by + * @param int $type A Cursor::HASH_* const for the type of hash + * @param string|int|null $class The object class, resource type or array count + * @param bool $hasChild When the dump of the hash has child item + * @param int $cut The number of items the hash has been cut by */ - public function leaveHash(Cursor $cursor, int $type, $class, bool $hasChild, int $cut); + public function leaveHash(Cursor $cursor, int $type, string|int|null $class, bool $hasChild, int $cut); } diff --git a/src/Symfony/Component/VarDumper/Cloner/VarCloner.php b/src/Symfony/Component/VarDumper/Cloner/VarCloner.php index a3aab6ec43353..4a6817c1c4869 100644 --- a/src/Symfony/Component/VarDumper/Cloner/VarCloner.php +++ b/src/Symfony/Component/VarDumper/Cloner/VarCloner.php @@ -22,7 +22,7 @@ class VarCloner extends AbstractCloner /** * {@inheritdoc} */ - protected function doClone($var) + protected function doClone(mixed $var) { $len = 1; // Length of $queue $pos = 0; // Number of cloned items past the minimum depth diff --git a/src/Symfony/Component/VarDumper/Dumper/CliDumper.php b/src/Symfony/Component/VarDumper/Dumper/CliDumper.php index ab919e155850e..8cef9d3af49af 100644 --- a/src/Symfony/Component/VarDumper/Dumper/CliDumper.php +++ b/src/Symfony/Component/VarDumper/Dumper/CliDumper.php @@ -125,7 +125,7 @@ public function setDisplayOptions(array $displayOptions) /** * {@inheritdoc} */ - public function dumpScalar(Cursor $cursor, string $type, $value) + public function dumpScalar(Cursor $cursor, string $type, string|int|float|bool|null $value) { $this->dumpKey($cursor); @@ -267,7 +267,7 @@ public function dumpString(Cursor $cursor, string $str, bool $bin, int $cut) /** * {@inheritdoc} */ - public function enterHash(Cursor $cursor, int $type, $class, bool $hasChild) + public function enterHash(Cursor $cursor, int $type, string|int|null $class, bool $hasChild) { if (null === $this->colors) { $this->colors = $this->supportsColors(); @@ -308,7 +308,7 @@ public function enterHash(Cursor $cursor, int $type, $class, bool $hasChild) /** * {@inheritdoc} */ - public function leaveHash(Cursor $cursor, int $type, $class, bool $hasChild, int $cut) + public function leaveHash(Cursor $cursor, int $type, string|int|null $class, bool $hasChild, int $cut) { if (empty($cursor->attr['cut_hash'])) { $this->dumpEllipsis($cursor, $hasChild, $cut); @@ -324,7 +324,7 @@ public function leaveHash(Cursor $cursor, int $type, $class, bool $hasChild, int * @param bool $hasChild When the dump of the hash has child item * @param int $cut The number of items the hash has been cut by */ - protected function dumpEllipsis(Cursor $cursor, $hasChild, $cut) + protected function dumpEllipsis(Cursor $cursor, bool $hasChild, int $cut) { if ($cut) { $this->line .= ' …'; @@ -428,7 +428,7 @@ protected function dumpKey(Cursor $cursor) * * @return string The value with style decoration */ - protected function style($style, $value, $attr = []) + protected function style(string $style, string $value, array $attr = []) { if (null === $this->colors) { $this->colors = $this->supportsColors(); @@ -576,10 +576,8 @@ protected function endValue(Cursor $cursor) * * Reference: Composer\XdebugHandler\Process::supportsColor * https://github.com/composer/xdebug-handler - * - * @param mixed $stream A CLI output stream */ - private function hasColorSupport($stream): bool + private function hasColorSupport(mixed $stream): bool { if (!\is_resource($stream) || 'stream' !== get_resource_type($stream)) { return false; diff --git a/src/Symfony/Component/VarDumper/Dumper/HtmlDumper.php b/src/Symfony/Component/VarDumper/Dumper/HtmlDumper.php index 9bbd2d65abc68..9b6d0a34dbed5 100644 --- a/src/Symfony/Component/VarDumper/Dumper/HtmlDumper.php +++ b/src/Symfony/Component/VarDumper/Dumper/HtmlDumper.php @@ -116,21 +116,16 @@ public function setDisplayOptions(array $displayOptions) /** * Sets an HTML header that will be dumped once in the output stream. - * - * @param string $header An HTML string */ - public function setDumpHeader($header) + public function setDumpHeader(string $header) { $this->dumpHeader = $header; } /** * Sets an HTML prefix and suffix that will encapse every single dump. - * - * @param string $prefix The prepended HTML string - * @param string $suffix The appended HTML string */ - public function setDumpBoundaries($prefix, $suffix) + public function setDumpBoundaries(string $prefix, string $suffix) { $this->dumpPrefix = $prefix; $this->dumpSuffix = $suffix; @@ -808,7 +803,7 @@ public function dumpString(Cursor $cursor, string $str, bool $bin, int $cut) /** * {@inheritdoc} */ - public function enterHash(Cursor $cursor, int $type, $class, bool $hasChild) + public function enterHash(Cursor $cursor, int $type, string|int|null $class, bool $hasChild) { if (Cursor::HASH_OBJECT === $type) { $cursor->attr['depth'] = $cursor->depth; @@ -839,7 +834,7 @@ public function enterHash(Cursor $cursor, int $type, $class, bool $hasChild) /** * {@inheritdoc} */ - public function leaveHash(Cursor $cursor, int $type, $class, bool $hasChild, int $cut) + public function leaveHash(Cursor $cursor, int $type, string|int|null $class, bool $hasChild, int $cut) { $this->dumpEllipsis($cursor, $hasChild, $cut); if ($hasChild) { @@ -851,7 +846,7 @@ public function leaveHash(Cursor $cursor, int $type, $class, bool $hasChild, int /** * {@inheritdoc} */ - protected function style($style, $value, $attr = []) + protected function style(string $style, string $value, array $attr = []) { if ('' === $value) { return ''; diff --git a/src/Symfony/Component/VarDumper/Resources/functions/dump.php b/src/Symfony/Component/VarDumper/Resources/functions/dump.php index a485d573a007a..ed94fe148c947 100644 --- a/src/Symfony/Component/VarDumper/Resources/functions/dump.php +++ b/src/Symfony/Component/VarDumper/Resources/functions/dump.php @@ -15,7 +15,7 @@ /** * @author Nicolas Grekas */ - function dump($var, ...$moreVars) + function dump(mixed $var, mixed ...$moreVars): mixed { VarDumper::dump($var); @@ -32,7 +32,7 @@ function dump($var, ...$moreVars) } if (!function_exists('dd')) { - function dd(...$vars) + function dd(mixed ...$vars): void { foreach ($vars as $v) { VarDumper::dump($v); diff --git a/src/Symfony/Component/VarDumper/Server/Connection.php b/src/Symfony/Component/VarDumper/Server/Connection.php index d8be23587e764..ae4e76f7efdd3 100644 --- a/src/Symfony/Component/VarDumper/Server/Connection.php +++ b/src/Symfony/Component/VarDumper/Server/Connection.php @@ -78,7 +78,7 @@ public function write(Data $data): bool return false; } - private static function nullErrorHandler($t, $m) + private static function nullErrorHandler(int $t, string $m) { // no-op } diff --git a/src/Symfony/Component/VarDumper/Test/VarDumperTestTrait.php b/src/Symfony/Component/VarDumper/Test/VarDumperTestTrait.php index 33d60c020196b..ec18463252730 100644 --- a/src/Symfony/Component/VarDumper/Test/VarDumperTestTrait.php +++ b/src/Symfony/Component/VarDumper/Test/VarDumperTestTrait.php @@ -42,17 +42,17 @@ protected function tearDownVarDumper(): void $this->varDumperConfig['flags'] = null; } - public function assertDumpEquals($expected, $data, int $filter = 0, string $message = '') + public function assertDumpEquals(mixed $expected, mixed $data, int $filter = 0, string $message = '') { $this->assertSame($this->prepareExpectation($expected, $filter), $this->getDump($data, null, $filter), $message); } - public function assertDumpMatchesFormat($expected, $data, int $filter = 0, string $message = '') + public function assertDumpMatchesFormat(mixed $expected, mixed $data, int $filter = 0, string $message = '') { $this->assertStringMatchesFormat($this->prepareExpectation($expected, $filter), $this->getDump($data, null, $filter), $message); } - protected function getDump($data, $key = null, int $filter = 0): ?string + protected function getDump(mixed $data, string|int|null $key = null, int $filter = 0): ?string { if (null === $flags = $this->varDumperConfig['flags']) { $flags = getenv('DUMP_LIGHT_ARRAY') ? CliDumper::DUMP_LIGHT_ARRAY : 0; @@ -73,7 +73,7 @@ protected function getDump($data, $key = null, int $filter = 0): ?string return rtrim($dumper->dump($data, true)); } - private function prepareExpectation($expected, int $filter): string + private function prepareExpectation(mixed $expected, int $filter): string { if (!\is_string($expected)) { $expected = $this->getDump($expected, null, $filter); diff --git a/src/Symfony/Component/VarDumper/VarDumper.php b/src/Symfony/Component/VarDumper/VarDumper.php index b223e065106d2..e965d05e0e15f 100644 --- a/src/Symfony/Component/VarDumper/VarDumper.php +++ b/src/Symfony/Component/VarDumper/VarDumper.php @@ -34,7 +34,7 @@ class VarDumper { private static $handler; - public static function dump($var) + public static function dump(mixed $var) { if (null === self::$handler) { self::register();