Skip to content

Commit 9b39ca3

Browse files
committed
[VarDumper] Add types to private properties
Signed-off-by: Alexander M. Turek <me@derrabus.de>
1 parent 407db3a commit 9b39ca3

22 files changed

+67
-63
lines changed

src/Symfony/Component/VarDumper/Caster/ArgsStub.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
*/
2121
class ArgsStub extends EnumStub
2222
{
23-
private static $parameters = [];
23+
private static array $parameters = [];
2424

2525
public function __construct(array $args, string $function, ?string $class)
2626
{

src/Symfony/Component/VarDumper/Caster/ExceptionCaster.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class ExceptionCaster
4444
\E_STRICT => 'E_STRICT',
4545
];
4646

47-
private static $framesCache = [];
47+
private static array $framesCache = [];
4848

4949
public static function castError(\Error $e, array $a, Stub $stub, bool $isNested, int $filter = 0)
5050
{

src/Symfony/Component/VarDumper/Caster/LinkStub.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ class LinkStub extends ConstStub
2020
{
2121
public $inVendor = false;
2222

23-
private static $vendorRoots;
24-
private static $composerRoots;
23+
private static array $vendorRoots;
24+
private static array $composerRoots = [];
2525

2626
public function __construct(string $label, int $line = 0, string $href = null)
2727
{
@@ -65,7 +65,7 @@ public function __construct(string $label, int $line = 0, string $href = null)
6565

6666
private function getComposerRoot(string $file, bool &$inVendor)
6767
{
68-
if (null === self::$vendorRoots) {
68+
if (!isset(self::$vendorRoots)) {
6969
self::$vendorRoots = [];
7070

7171
foreach (get_declared_classes() as $class) {

src/Symfony/Component/VarDumper/Caster/MemcachedCaster.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
*/
2121
class MemcachedCaster
2222
{
23-
private static $optionConstants;
24-
private static $defaultOptions;
23+
private static array $optionConstants;
24+
private static array $defaultOptions;
2525

2626
public static function castMemcached(\Memcached $c, array $a, Stub $stub, bool $isNested)
2727
{

src/Symfony/Component/VarDumper/Cloner/AbstractCloner.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,10 +193,15 @@ abstract class AbstractCloner implements ClonerInterface
193193
protected $maxString = -1;
194194
protected $minDepth = 1;
195195

196-
private $casters = [];
196+
private array $casters = [];
197+
198+
/**
199+
* @var callable|null
200+
*/
197201
private $prevErrorHandler;
198-
private $classInfo = [];
199-
private $filter = 0;
202+
203+
private array $classInfo = [];
204+
private int $filter = 0;
200205

201206
/**
202207
* @param callable[]|null $casters A map of casters

src/Symfony/Component/VarDumper/Cloner/Data.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@
1919
*/
2020
class Data implements \ArrayAccess, \Countable, \IteratorAggregate
2121
{
22-
private $data;
23-
private $position = 0;
24-
private $key = 0;
25-
private $maxDepth = 20;
26-
private $maxItemsPerDepth = -1;
27-
private $useRefHandles = -1;
28-
private $context = [];
22+
private array $data;
23+
private int $position = 0;
24+
private int|string $key = 0;
25+
private int $maxDepth = 20;
26+
private int $maxItemsPerDepth = -1;
27+
private int $useRefHandles = -1;
28+
private array $context = [];
2929

3030
/**
3131
* @param array $data An array as returned by ClonerInterface::cloneVar()

src/Symfony/Component/VarDumper/Cloner/Stub.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class Stub
3939
public $position = 0;
4040
public $attr = [];
4141

42-
private static $defaultProperties = [];
42+
private static array $defaultProperties = [];
4343

4444
/**
4545
* @internal

src/Symfony/Component/VarDumper/Cloner/VarCloner.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
*/
1717
class VarCloner extends AbstractCloner
1818
{
19-
private static $gid;
20-
private static $arrayCache = [];
19+
private static string $gid;
20+
private static array $arrayCache = [];
2121

2222
/**
2323
* {@inheritdoc}
@@ -44,9 +44,7 @@ protected function doClone(mixed $var): array
4444
$stub = null; // Stub capturing the main properties of an original item value
4545
// or null if the original value is used directly
4646

47-
if (!$gid = self::$gid) {
48-
$gid = self::$gid = md5(random_bytes(6)); // Unique string used to detect the special $GLOBALS variable
49-
}
47+
$gid = self::$gid ??= md5(random_bytes(6)); // Unique string used to detect the special $GLOBALS variable
5048
$arrayStub = new Stub();
5149
$arrayStub->type = Stub::TYPE_ARRAY;
5250
$fromObjCast = false;

src/Symfony/Component/VarDumper/Command/Descriptor/CliDescriptor.php

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,12 @@
2727
*/
2828
class CliDescriptor implements DumpDescriptorInterface
2929
{
30-
private $dumper;
31-
private $lastIdentifier;
32-
private $supportsHref;
30+
private CliDumper $dumper;
31+
private mixed $lastIdentifier = null;
3332

3433
public function __construct(CliDumper $dumper)
3534
{
3635
$this->dumper = $dumper;
37-
$this->supportsHref = method_exists(OutputFormatterStyle::class, 'setHref');
3836
}
3937

4038
public function describe(OutputInterface $output, Data $data, array $context, int $clientId): void
@@ -66,8 +64,7 @@ public function describe(OutputInterface $output, Data $data, array $context, in
6664
if (isset($context['source'])) {
6765
$source = $context['source'];
6866
$sourceInfo = sprintf('%s on line %d', $source['name'], $source['line']);
69-
$fileLink = $source['file_link'] ?? null;
70-
if ($this->supportsHref && $fileLink) {
67+
if ($fileLink = $source['file_link'] ?? null) {
7168
$sourceInfo = sprintf('<href=%s>%s</>', $fileLink, $sourceInfo);
7269
}
7370
$rows[] = ['source', $sourceInfo];
@@ -77,11 +74,6 @@ public function describe(OutputInterface $output, Data $data, array $context, in
7774

7875
$io->table([], $rows);
7976

80-
if (!$this->supportsHref && isset($fileLink)) {
81-
$io->writeln(['<info>Open source in your IDE/browser:</info>', $fileLink]);
82-
$io->newLine();
83-
}
84-
8577
$this->dumper->dump($data);
8678
$io->newLine();
8779
}

src/Symfony/Component/VarDumper/Command/Descriptor/HtmlDescriptor.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
*/
2525
class HtmlDescriptor implements DumpDescriptorInterface
2626
{
27-
private $dumper;
28-
private $initialized = false;
27+
private HtmlDumper $dumper;
28+
private bool $initialized = false;
2929

3030
public function __construct(HtmlDumper $dumper)
3131
{

0 commit comments

Comments
 (0)