8000 [VarDumper] Add parameter type declarations by derrabus · Pull Request #33153 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[VarDumper] Add parameter type declarations #33153

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
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
5 changes: 4 additions & 1 deletion src/Symfony/Component/Console/Tests/Helper/DumperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ public static function tearDownAfterClass(): void
*/
public function testInvoke($variable)
{
$dumper = new Dumper($this->getMockBuilder(OutputInterface::class)->getMock());
$output = $this->getMockBuilder(OutputInterface::class)->getMock();
$output->method('isDecorated')->willReturn(false);

$dumper = new Dumper($output);

$this->assertDumpMatchesFormat($dumper($variable), $variable);
}
Expand Down
12 changes: 6 additions & 6 deletions src/Symfony/Component/VarDumper/Caster/AmqpCaster.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class AmqpCaster
AMQP_EX_TYPE_HEADERS => 'AMQP_EX_TYPE_HEADERS',
];

public static function castConnection(\AMQPConnection $c, array $a, Stub $stub, $isNested)
public static function castConnection(\AMQPConnection $c, array $a, Stub $stub, bool $isNested)
{
$prefix = Caster::PREFIX_VIRTUAL;

Expand Down Expand Up @@ -77,7 +77,7 @@ public static function castConnection(\AMQPConnection $c, array $a, Stub $stub,
return $a;
}

public static function castChannel(\AMQPChannel $c, array $a, Stub $stub, $isNested)
public static function castChannel(\AMQPChannel $c, array $a, Stub $stub, bool $isNested)
{
$prefix = Caster::PREFIX_VIRTUAL;

Expand All @@ -100,7 +100,7 @@ public static function castChannel(\AMQPChannel $c, array $a, Stub $stub, $isNes
return $a;
}

public static function castQueue(\AMQPQueue $c, array $a, Stub $stub, $isNested)
public static function castQueue(\AMQPQueue $c, array $a, Stub $stub, bool $isNested)
{
$prefix = Caster::PREFIX_VIRTUAL;

Expand All @@ -123,7 +123,7 @@ public static function castQueue(\AMQPQueue $c, array $a, Stub $stub, $isNested)
return $a;
}

public static function castExchange(\AMQPExchange $c, array $a, Stub $stub, $isNested)
public static function castExchange(\AMQPExchange $c, array $a, Stub $stub, bool $isNested)
{
$prefix = Caster::PREFIX_VIRTUAL;

Expand Down Expand Up @@ -151,7 +151,7 @@ public static function castExchange(\AMQPExchange $c, array $a, Stub $stub, $isN
return $a;
}

public static function castEnvelope(\AMQPEnvelope $c, array $a, Stub $stub, $isNested, $filter = 0)
public static function castEnvelope(\AMQPEnvelope $c, array $a, Stub $stub, bool $isNested, int $filter = 0)
{
$prefix = Caster::PREFIX_VIRTUAL;

Expand Down Expand Up @@ -191,7 +191,7 @@ public static function castEnvelope(\AMQPEnvelope $c, array $a, Stub $stub, $isN
return $a;
}

private static function extractFlags($flags)
private static function extractFlags(int $flags)
{
$flagsArray = [];

Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/VarDumper/Caster/ArgsStub.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function __construct(array $args, string $function, ?string $class)
}
}

private static function getParameters($function, $class)
private static function getParameters(string $function, ?string $class)
{
if (isset(self::$parameters[$k = $class.'::'.$function])) {
return self::$parameters[$k];
Expand Down
10 changes: 4 additions & 6 deletions src/Symfony/Component/VarDumper/Caster/Caster.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,11 @@ class Caster
/**
* Casts objects to arrays and adds the dynamic property prefix.
*
* @param object $obj The object to cast
* @param string $class The class of the object
* @param bool $hasDebugInfo Whether the __debugInfo method exists on $obj or not
* @param bool $hasDebugInfo Whether the __debugInfo method exists on $obj or not
*
* @return array The array-cast of the object, with prefixed dynamic properties
*/
public static function castObject($obj, $class, $hasDebugInfo = false): array
public static function castObject(object $obj, string $class, bool $hasDebugInfo = false): array
{
$a = $obj instanceof \Closure ? [] : (array) $obj;

Expand Down Expand Up @@ -110,7 +108,7 @@ public static function castObject($obj, $class, $hasDebugInfo = false): array
*
* @return array The filtered array
*/
public static function filter(array $a, $filter, array $listedProperties = [], &$count = 0): array
public static function filter(array $a, int $filter, array $listedProperties = [], ?int &$count = 0): array
{
$count = 0;

Expand Down Expand Up @@ -151,7 +149,7 @@ public static function filter(array $a, $filter, array $listedProperties = [], &
return $a;
}

public static function castPhpIncompleteClass(\__PHP_Incomplete_Class $c, array $a, Stub $stub, $isNested): array
public static function castPhpIncompleteClass(\__PHP_Incomplete_Class $c, array $a, Stub $stub, bool $isNested): array
{
if (isset($a['__PHP_Incomplete_Class_Name'])) {
$stub->class .= '('.$a['__PHP_Incomplete_Class_Name'].')';
Expand Down
36 changes: 18 additions & 18 deletions src/Symfony/Component/VarDumper/Caster/DOMCaster.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class DOMCaster
XML_NAMESPACE_DECL_NODE => 'XML_NAMESPACE_DECL_NODE',
];

public static function castException(\DOMException $e, array $a, Stub $stub, $isNested)
public static function castException(\DOMException $e, array $a, Stub $stub, bool $isNested)
{
$k = Caster::PREFIX_PROTECTED.'code';
if (isset($a[$k], self::$errorCodes[$a[$k]])) {
Expand All @@ -71,7 +71,7 @@ public static function castException(\DOMException $e, array $a, Stub $stub, $is
return $a;
}

public static function castLength($dom, array $a, Stub $stub, $isNested)
public static function castLength($dom, array $a, Stub $stub, bool $isNested)
{
$a += [
'length' => $dom->length,
Expand All @@ -80,7 +80,7 @@ public static function castLength($dom, array $a, Stub $stub, $isNested)
return $a;
}

public static function castImplementation($dom, array $a, Stub $stub, $isNested)
public static function castImplementation($dom, array $a, Stub $stub, bool $isNested)
{
$a += [
Caster::PREFIX_VIRTUAL.'Core' => '1.0',
Expand All @@ -90,7 +90,7 @@ public static function castImplementation($dom, array $a, Stub $stub, $isNested)
return $a;
}

public static function castNode(\DOMNode $dom, array $a, Stub $stub, $isNested)
public static function castNode(\DOMNode $dom, array $a, Stub $stub, bool $isNested)
{
$a += [
'nodeName' => $dom->nodeName,
Expand All @@ -114,7 +114,7 @@ public static function castNode(\DOMNode $dom, array $a, Stub $stub, $isNested)
return $a;
}

public static function castNameSpaceNode(\DOMNameSpaceNode $dom, array $a, Stub $stub, $isNested)
public static function castNameSpaceNode(\DOMNameSpaceNode $dom, array $a, Stub $stub, bool $isNested)
{
$a += [
'nodeName' => $dom->nodeName,
Expand All @@ -130,7 +130,7 @@ public static function castNameSpaceNode(\DOMNameSpaceNode $dom, array $a, Stub
return $a;
}

public static function castDocument(\DOMDocument $dom, array $a, Stub $stub, $isNested, $filter = 0)
public static function castDocument(\DOMDocument $dom, array $a, Stub $stub, bool $isNested, int $filter = 0)
{
$a += [
'doctype' => $dom->doctype,
Expand Down Expand Up @@ -164,7 +164,7 @@ public static function castDocument(\DOMDocument $dom, array $a, Stub $stub, $is
return $a;
}

public static function castCharacterData(\DOMCharacterData $dom, array $a, Stub $stub, $isNested)
public static function castCharacterData(\DOMCharacterData $dom, array $a, Stub $stub, bool $isNested)
{
$a += [
'data' => $dom->data,
Expand All @@ -174,7 +174,7 @@ public static function castCharacterData(\DOMCharacterData $dom, array $a, Stub
return $a;
}

public static function castAttr(\DOMAttr $dom, array $a, Stub $stub, $isNested)
public static function castAttr(\DOMAttr $dom, array $a, Stub $stub, bool $isNested)
{
$a += [
'name' => $dom->name,
Expand All @@ -187,7 +187,7 @@ public static function castAttr(\DOMAttr $dom, array $a, Stub $stub, $isNested)
return $a;
}

public static function castElement(\DOMElement $dom, array $a, Stub $stub, $isNested)
public static function castElement(\DOMElement $dom, array $a, Stub $stub, bool $isNested)
{
$a += [
'tagName' => $dom->tagName,
Expand All @@ -197,7 +197,7 @@ public static function castElement(\DOMElement $dom, array $a, Stub $stub, $isNe
return $a;
}

public static function castText(\DOMText $dom, array $a, Stub $stub, $isNested)
public static function castText(\DOMText $dom, array $a, Stub $stub, bool $isNested)
{
$a += [
'wholeText' => $dom->wholeText,
Expand All @@ -206,7 +206,7 @@ public static function castText(\DOMText $dom, array $a, Stub $stub, $isNested)
return $a;
}

public static function castTypeinfo(\DOMTypeinfo $dom, array $a, Stub $stub, $isNested)
public static function castTypeinfo(\DOMTypeinfo $dom, array $a, Stub $stub, bool $isNested)
{
$a += [
'typeName' => $dom->typeName,
Expand All @@ -216,7 +216,7 @@ public static function castTypeinfo(\DOMTypeinfo $dom, array $a, Stub $stub, $is
return $a;
}

public static function castDomError(\DOMDomError $dom, array $a, Stub $stub, $isNested)
public static function castDomError(\DOMDomError $dom, array $a, Stub $stub, bool $isNested)
{
$a += [
'severity' => $dom->severity,
Expand All @@ -230,7 +230,7 @@ public static function castDomError(\DOMDomError $dom, array $a, Stub $stub, $is
return $a;
}

public static function castLocator(\DOMLocator $dom, array $a, Stub $stub, $isNested)
public static function castLocator(\DOMLocator $dom, array $a, Stub $stub, bool $isNested)
{
$a += [
'lineNumber' => $dom->lineNumber,
Expand All @@ -243,7 +243,7 @@ public static function castLocator(\DOMLocator $dom, array $a, Stub $stub, $isNe
return $a;
}

public static function castDocumentType(\DOMDocumentType $dom, array $a, Stub $stub, $isNested)
public static function castDocumentType(\DOMDocumentType $dom, array $a, Stub $stub, bool $isNested)
{
$a += [
'name' => $dom->name,
Expand All @@ -257,7 +257,7 @@ public static function castDocumentType(\DOMDocumentType $dom, array $a, Stub $s
return $a;
}

public static function castNotation(\DOMNotation $dom, array $a, Stub $stub, $isNested)
public static function castNotation(\DOMNotation $dom, array $a, Stub $stub, bool $isNested)
{
$a += [
'publicId' => $dom->publicId,
Expand All @@ -267,7 +267,7 @@ public static function castNotation(\DOMNotation $dom, array $a, Stub $stub, $is
return $a;
}

public static function castEntity(\DOMEntity $dom, array $a, Stub $stub, $isNested)
public static function castEntity(\DOMEntity $dom, array $a, Stub $stub, bool $isNested)
{
$a += [
'publicId' => $dom->publicId,
Expand All @@ -281,7 +281,7 @@ public static function castEntity(\DOMEntity $dom, array $a, Stub $stub, $isNest
return $a;
}

public static function castProcessingInstruction(\DOMProcessingInstruction $dom, array $a, Stub $stub, $isNested)
public static function castProcessingInstruction(\DOMProcessingInstruction $dom, array $a, Stub $stub, bool $isNested)
{
$a += [
'target' => $dom->target,
Expand All @@ -291,7 +291,7 @@ public static function castProcessingInstruction(\DOMProcessingInstruction $dom,
return $a;
}

public static function castXPath(\DOMXPath $dom, array $a, Stub $stub, $isNested)
public static function castXPath(\DOMXPath $dom, array $a, Stub $stub, bool $isNested)
{
$a += [
'document' => $dom->document,
Expand Down
12 changes: 6 additions & 6 deletions src/Symfony/Component/VarDumper/Caster/DateCaster.php
F987
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class DateCaster
{
private const PERIOD_LIMIT = 3;

public static function castDateTime(\DateTimeInterface $d, array $a, Stub $stub, $isNested, $filter)
public static function castDateTime(\DateTimeInterface $d, array $a, Stub $stub, bool $isNested, int $filter)
{
$prefix = Caster::PREFIX_VIRTUAL;
$location = $d->getTimezone()->getLocation();
Expand All @@ -41,7 +41,7 @@ public static function castDateTime(\DateTimeInterface $d, array $a, Stub $stub,
return $a;
}

public static function castInterval(\DateInterval $interval, array $a, Stub $stub, $isNested, $filter)
public static function castInterval(\DateInterval $interval, array $a, Stub $stub, bool $isNested, int $filter)
{
$now = new \DateTimeImmutable();
$numberOfSeconds = $now->add($interval)->getTimestamp() - $now->getTimestamp();
Expand Down Expand Up @@ -69,7 +69,7 @@ private static function formatInterval(\DateInterval $i)
return $i->format(rtrim($format));
}

public static function castTimeZone(\DateTimeZone $timeZone, array $a, Stub $stub, $isNested, $filter)
public static function castTimeZone(\DateTimeZone $timeZone, array $a, Stub $stub, bool $isNested, int $filter)
{
$location = $timeZone->getLocation();
$formatted = (new \DateTime('now', $timeZone))->format($location ? 'e (P)' : 'P');
Expand All @@ -80,7 +80,7 @@ public static function castTimeZone(\DateTimeZone $timeZone, array $a, Stub $stu
return $filter & Caster::EXCLUDE_VERBOSE ? $z : $z + $a;
}

public static function castPeriod(\DatePeriod $p, array $a, Stub $stub, $isNested, $filter)
public static function castPeriod(\DatePeriod $p, array $a, Stub $stub, bool $isNested, int $filter)
{
$dates = [];
foreach (clone $p as $i => $d) {
Expand Down Expand Up @@ -108,12 +108,12 @@ public static function castPeriod(\DatePeriod $p, array $a, Stub $stub, $isNeste
return $filter & Caster::EXCLUDE_VERBOSE ? $p : $p + $a;
}

private static function formatDateTime(\DateTimeInterface $d, $extra = '')
private static function formatDateTime(\DateTimeInterface $d, string $extra = ''): string
{
return $d->format('Y-m-d H:i:'.self::formatSeconds($d->format('s'), $d->format('u')).$extra);
}

private static function formatSeconds($s, $us)
private static function formatSeconds(string $s, string $us): string
{
return sprintf('%02d.%s', $s, 0 === ($len = \strlen($t = rtrim($us, '0'))) ? '0' : ($len <= 3 ? str_pad($t, 3, '0') : $us));
}
Expand Down
6 changes: 3 additions & 3 deletions src/Symfony/Component/VarDumper/Caster/DoctrineCaster.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
*/
class DoctrineCaster
{
public static function castCommonProxy(CommonProxy $proxy, array $a, Stub $stub, $isNested)
public static function castCommonProxy(CommonProxy $proxy, array $a, Stub $stub, bool $isNested)
{
foreach (['__cloner__', '__initializer__'] as $k) {
if (\array_key_exists($k, $a)) {
Expand All @@ -35,7 +35,7 @@ public static function castCommonProxy(CommonProxy $proxy, array $a, Stub $stub,
return $a;
}

public static function castOrmProxy(OrmProxy $proxy, array $a, Stub $stub, $isNested)
public static function castOrmProxy(OrmProxy $proxy, array $a, Stub $stub, bool $isNested)
{
foreach (['_entityPersister', '_identifier'] as $k) {
if (\array_key_exists($k = "\0Doctrine\\ORM\\Proxy\\Proxy\0".$k, $a)) {
Expand All @@ -47,7 +47,7 @@ public static function castOrmProxy(OrmProxy $proxy, array $a, Stub $stub, $isNe
return $a;
}

public static function castPersistentCollection(PersistentCollection $coll, array $a, Stub $stub, $isNested)
public static function castPersistentCollection(PersistentCollection $coll, array $a, Stub $stub, bool $isNested)
{
foreach (['snapshot', 'association', 'typeClass'] as $k) {
if (\array_key_exists($k = "\0Doctrine\\ORM\\PersistentCollection\0".$k, $a)) {
Expand Down
Loading
0