Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[VarDumper] add types to all arguments #41434

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion 2 src/Symfony/Component/VarDumper/Caster/CutStub.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*/
class CutStub extends Stub
{
public function __construct($value)
public function __construct(mixed $value)
{
$this->value = $value;

Expand Down
2 changes: 1 addition & 1 deletion 2 src/Symfony/Component/VarDumper/Caster/DsPairStub.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion 2 src/Symfony/Component/VarDumper/Caster/LinkStub.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
22 changes: 11 additions & 11 deletions 22 src/Symfony/Component/VarDumper/Caster/RdKafkaCaster.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;

Expand All @@ -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;

Expand All @@ -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;

Expand All @@ -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;

Expand All @@ -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;

Expand All @@ -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;

Expand All @@ -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;

Expand All @@ -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;

Expand All @@ -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;

Expand Down
5 changes: 1 addition & 4 deletions 5 src/Symfony/Component/VarDumper/Caster/RedisCaster.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
4 changes: 2 additions & 2 deletions 4 src/Symfony/Component/VarDumper/Caster/ResourceCaster.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
}

Expand All @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions 4 src/Symfony/Component/VarDumper/Caster/SplCaster.php
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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']);
}

Expand Down
9 changes: 3 additions & 6 deletions 9 src/Symfony/Component/VarDumper/Cloner/AbstractCloner.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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.
Expand Down
4 changes: 1 addition & 3 deletions 4 src/Symfony/Component/VarDumper/Cloner/ClonerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
10 changes: 4 additions & 6 deletions 10 src/Symfony/Component/VarDumper/Cloner/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -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];

Expand Down Expand Up @@ -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];

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
23 changes: 10 additions & 13 deletions 23 src/Symfony/Component/VarDumper/Cloner/DumperInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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);
}
2 changes: 1 addition & 1 deletion 2 src/Symfony/Component/VarDumper/Cloner/VarCloner.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 6 additions & 8 deletions 14 src/Symfony/Component/VarDumper/Dumper/CliDumper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand All @@ -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 .= ' …';
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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;
Expand Down
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.