Skip to content

Commit

Permalink
Add types
Browse files Browse the repository at this point in the history
  • Loading branch information
BenMorel committed Feb 20, 2025
1 parent d324678 commit 034135f
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 37 deletions.
32 changes: 9 additions & 23 deletions src/Internal/GenericExporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ final class GenericExporter
/**
* @var ObjectExporter[]
*/
private $objectExporters = [];
private array $objectExporters = [];

/**
* The visited objects, to detect circular references.
Expand All @@ -34,52 +34,38 @@ final class GenericExporter

/**
* @psalm-readonly
*
* @var bool
*/
public $addTypeHints;
public bool $addTypeHints;

/**
* @psalm-readonly
*
* @var bool
*/
public $skipDynamicProperties;
public bool $skipDynamicProperties;

/**
* @psalm-readonly
*
* @var bool
*/
public $inlineArray;
public bool $inlineArray;

/**
* @psalm-readonly
*
* @var bool
*/
public $inlineScalarList;
public bool $inlineScalarList;

/**
* @psalm-readonly
*
* @var bool
*/
public $closureSnapshotUses;
public bool $closureSnapshotUses;

/**
* @psalm-readonly
*
* @var bool
*/
public $trailingCommaInArray;
public bool $trailingCommaInArray;

/**
* @psalm-readonly
*
* @var int
*/
public $indentLevel;
public int $indentLevel;

public function __construct(int $options, int $indentLevel = 0)
{
Expand Down Expand Up @@ -126,7 +112,7 @@ public function __construct(int $options, int $indentLevel = 0)
*
* @throws ExportException
*/
public function export($var, array $path, array $parentIds) : array
public function export(mixed $var, array $path, array $parentIds) : array
{
switch ($type = gettype($var)) {
case 'boolean':
Expand Down
5 changes: 1 addition & 4 deletions src/Internal/ObjectExporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@
*/
abstract class ObjectExporter
{
/**
* @var GenericExporter
*/
protected $exporter;
protected GenericExporter $exporter;

/**
* @param GenericExporter $exporter
Expand Down
5 changes: 1 addition & 4 deletions src/Internal/ObjectExporter/ClosureExporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,7 @@ public function export(object $object, \ReflectionObject $reflectionObject, arra
return [$code];
}

/**
* @return Parser
*/
private function getParser()
private function getParser(): Parser
{
if ($this->parser === null) {
$this->parser = (new ParserFactory)->createForHostVersion();
Expand Down
2 changes: 1 addition & 1 deletion src/VarExporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ final class VarExporter
*
* @throws ExportException
*/
public static function export($var, int $options = 0, int $indentLevel = 0) : string
public static function export(mixed $var, int $options = 0, int $indentLevel = 0) : string
{
$exporter = new GenericExporter($options, $indentLevel);
$lines = $exporter->export($var, [], []);
Expand Down
4 changes: 2 additions & 2 deletions tests/AbstractTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ abstract class AbstractTestCase extends TestCase
*
* @return void
*/
public function assertExportEquals(string $expected, $var, int $options = 0) : void
public function assertExportEquals(string $expected, mixed $var, int $options = 0) : void
{
// test the string output of export()

Expand Down Expand Up @@ -61,7 +61,7 @@ public function assertExportEquals(string $expected, $var, int $options = 0) : v
*
* @return void
*/
public function assertExportThrows(string $expectedMessage, $var, int $options = 0) : void
public function assertExportThrows(string $expectedMessage, mixed $var, int $options = 0) : void
{
$expectedMessageRegExp = '/' . implode('.*', array_map(fn(string $str) => preg_quote($str, '/'), explode('*', $expectedMessage))) . '/';

Expand Down
4 changes: 1 addition & 3 deletions tests/VarExporterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -356,10 +356,8 @@ public function testExportObjectWithCircularReference(): void

/**
* @dataProvider providerExportIndented
*
* @param mixed $var
*/
public function testExportIndented($var, string $expected, int $options): void
public function testExportIndented(mixed $var, string $expected, int $options): void
{
$template = <<<'TPL'
public function foo()
Expand Down

0 comments on commit 034135f

Please sign in to comment.