Skip to content

Commit

Permalink
Update stubs and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
phansys committed Oct 24, 2023
1 parent 2b51b2b commit 2b2af4e
Show file tree
Hide file tree
Showing 9 changed files with 213 additions and 11 deletions.
4 changes: 2 additions & 2 deletions resources/functionMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -9993,7 +9993,7 @@
'ReflectionFunctionAbstract::getNumberOfParameters' => ['int'],
'ReflectionFunctionAbstract::getNumberOfRequiredParameters' => ['int'],
'ReflectionFunctionAbstract::getParameters' => ['list<ReflectionParameter>'],
'ReflectionFunctionAbstract::getReturnType' => ['?ReflectionType'],
'ReflectionFunctionAbstract::getReturnType' => ['?ReflectionNamedType'],
'ReflectionFunctionAbstract::getShortName' => ['string'],
'ReflectionFunctionAbstract::getStartLine' => ['int|false'],
'ReflectionFunctionAbstract::getStaticVariables' => ['array'],
Expand Down Expand Up @@ -10051,7 +10051,7 @@
'ReflectionParameter::getDefaultValueConstantName' => ['?string'],
'ReflectionParameter::getName' => ['non-empty-string'],
'ReflectionParameter::getPosition' => ['int'],
'ReflectionParameter::getType' => ['ReflectionType|null'],
'ReflectionParameter::getType' => ['ReflectionNamedType|null'],
'ReflectionParameter::hasType' => ['bool'],
'ReflectionParameter::isArray' => ['bool'],
'ReflectionParameter::isCallable' => ['bool'],
Expand Down
6 changes: 2 additions & 4 deletions resources/functionMap_php80delta.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,7 @@
'PhpToken::getTokenName' => ['string'],
'preg_match_all' => ['0|positive-int|false', 'pattern'=>'string', 'subject'=>'string', '&w_subpatterns='=>'array', 'flags='=>'int', 'offset='=>'int'],
'proc_get_status' => ['array{command: string, pid: int, running: bool, signaled: bool, stopped: bool, exitcode: int, termsig: int, stopsig: int}', 'process'=>'resource'],
'ReflectionFunction::getReturnType' => ['ReflectionNamedType|ReflectionUnionType|null'],
'ReflectionMethod::getReturnType' => ['ReflectionNamedType|ReflectionUnionType|null'],
'ReflectionFunctionAbstract::getReturnType' => ['ReflectionNamedType|ReflectionUnionType|null'],
'ReflectionParameter::getType' => ['ReflectionNamedType|ReflectionUnionType|null'],
'ReflectionProperty::getType' => ['ReflectionNamedType|ReflectionUnionType|null'],
'set_error_handler' => ['?callable', 'callback'=>'null|callable(int,string,string,int):bool', 'error_types='=>'int'],
Expand Down Expand Up @@ -234,8 +233,7 @@
'png2wbmp' => ['bool', 'pngname'=>'string', 'wbmpname'=>'string', 'dest_height'=>'int', 'dest_width'=>'int', 'threshold'=>'int'],
'proc_get_status' => ['array{command: string, pid: int, running: bool, signaled: bool, stopped: bool, exitcode: int, termsig: int, stopsig: int}|false', 'process'=>'resource'],
'read_exif_data' => ['array', 'filename'=>'string', 'sections_needed='=>'string', 'sub_arrays='=>'bool', 'read_thumbnail='=>'bool'],
'ReflectionFunction::getReturnType' => ['?ReflectionNamedType'],
'ReflectionMethod::getReturnType' => ['?ReflectionNamedType'],
'ReflectionFunctionAbstract::getReturnType' => ['?ReflectionNamedType'],
'ReflectionParameter::getType' => ['?ReflectionNamedType'],
'ReflectionProperty::getType' => ['?ReflectionNamedType'],
'restore_include_path' => ['void'],
Expand Down
6 changes: 2 additions & 4 deletions resources/functionMap_php81delta.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@
*/
return [
'new' => [
'ReflectionFunction::getReturnType' => ['ReflectionNamedType|ReflectionUnionType|ReflectionIntersectionType|null'],
'ReflectionMethod::getReturnType' => ['ReflectionNamedType|ReflectionUnionType|ReflectionIntersectionType|null'],
'ReflectionFunctionAbstract::getReturnType' => ['ReflectionNamedType|ReflectionUnionType|ReflectionIntersectionType|null'],
'ReflectionParameter::getType' => ['ReflectionNamedType|ReflectionUnionType|ReflectionIntersectionType|null'],
'ReflectionProperty::getType' => ['ReflectionNamedType|ReflectionUnionType|ReflectionIntersectionType|null'],
],
Expand Down Expand Up @@ -67,8 +66,7 @@
'pg_tty\'1' => ['string'],
'pg_untrace' => ['bool', 'connection='=>'resource'],
'pg_untrace\'1' => ['bool'],
'ReflectionFunction::getReturnType' => ['ReflectionNamedType|ReflectionUnionType|null'],
'ReflectionMethod::getReturnType' => ['ReflectionNamedType|ReflectionUnionType|null'],
'ReflectionFunctionAbstract::getReturnType' => ['ReflectionNamedType|ReflectionUnionType|null'],
'ReflectionParameter::getType' => ['ReflectionNamedType|ReflectionUnionType|null'],
'ReflectionProperty::getType' => ['ReflectionNamedType|ReflectionUnionType|null'],
]
Expand Down
7 changes: 6 additions & 1 deletion stubs/ReflectionMethod.stub
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,15 @@

class ReflectionMethod
{

/**
* @var class-string
*/
public $class;

/**
* @return ReflectionIntersectionType|ReflectionNamedType|ReflectionUnionType|null
*/
public function getReturnType()

Check failure on line 13 in stubs/ReflectionMethod.stub

View workflow job for this annotation

GitHub Actions / Compiler Tests

Method ReflectionMethod::getReturnType() has invalid return type ReflectionIntersectionType.

Check failure on line 13 in stubs/ReflectionMethod.stub

View workflow job for this annotation

GitHub Actions / PHPStan (7.3, ubuntu-latest)

Method ReflectionMethod::getReturnType() has invalid return type ReflectionIntersectionType.

Check failure on line 13 in stubs/ReflectionMethod.stub

View workflow job for this annotation

GitHub Actions / PHPStan (7.3, ubuntu-latest)

Method ReflectionMethod::getReturnType() has invalid return type ReflectionUnionType.

Check failure on line 13 in stubs/ReflectionMethod.stub

View workflow job for this annotation

GitHub Actions / PHPStan (8.0, ubuntu-latest)

Method ReflectionMethod::getReturnType() has invalid return type ReflectionIntersectionType.

Check failure on line 13 in stubs/ReflectionMethod.stub

View workflow job for this annotation

GitHub Actions / PHPStan (7.4, ubuntu-latest)

Method ReflectionMethod::getReturnType() has invalid return type ReflectionIntersectionType.

Check failure on line 13 in stubs/ReflectionMethod.stub

View workflow job for this annotation

GitHub Actions / PHPStan (7.4, ubuntu-latest)

Method ReflectionMethod::getReturnType() has invalid return type ReflectionUnionType.

Check failure on line 13 in stubs/ReflectionMethod.stub

View workflow job for this annotation

GitHub Actions / Tests (7.4, ubuntu-latest)

Method ReflectionMethod::getReturnType() has invalid return type ReflectionIntersectionType.

Check failure on line 13 in stubs/ReflectionMethod.stub

View workflow job for this annotation

GitHub Actions / Tests (7.4, ubuntu-latest)

Method ReflectionMethod::getReturnType() has invalid return type ReflectionUnionType.

Check failure on line 13 in stubs/ReflectionMethod.stub

View workflow job for this annotation

GitHub Actions / Tests (8.0, ubuntu-latest)

Method ReflectionMethod::getReturnType() has invalid return type ReflectionIntersectionType.

Check failure on line 13 in stubs/ReflectionMethod.stub

View workflow job for this annotation

GitHub Actions / PHPStan (7.2, ubuntu-latest)

Method ReflectionMethod::getReturnType() has invalid return type ReflectionIntersectionType.

Check failure on line 13 in stubs/ReflectionMethod.stub

View workflow job for this annotation

GitHub Actions / PHPStan (7.2, ubuntu-latest)

Method ReflectionMethod::getReturnType() has invalid return type ReflectionUnionType.

Check failure on line 13 in stubs/ReflectionMethod.stub

View workflow job for this annotation

GitHub Actions / Tests (7.3, ubuntu-latest)

Method ReflectionMethod::getReturnType() has invalid return type ReflectionIntersectionType.

Check failure on line 13 in stubs/ReflectionMethod.stub

View workflow job for this annotation

GitHub Actions / Tests (7.3, ubuntu-latest)

Method ReflectionMethod::getReturnType() has invalid return type ReflectionUnionType.

Check failure on line 13 in stubs/ReflectionMethod.stub

View workflow job for this annotation

GitHub Actions / PHPStan (8.0, windows-latest)

Method ReflectionMethod::getReturnType() has invalid return type ReflectionIntersectionType.

Check failure on line 13 in stubs/ReflectionMethod.stub

View workflow job for this annotation

GitHub Actions / Tests with old PHPUnit (7.2, ubuntu-latest)

Method ReflectionMethod::getReturnType() has invalid return type ReflectionIntersectionType.

Check failure on line 13 in stubs/ReflectionMethod.stub

View workflow job for this annotation

GitHub Actions / Tests with old PHPUnit (7.2, ubuntu-latest)

Method ReflectionMethod::getReturnType() has invalid return type ReflectionUnionType.
{
}
}
10 changes: 10 additions & 0 deletions tests/PHPStan/Analyser/NodeScopeResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,16 @@ public function dataFileAsserts(): iterable

yield from $this->gatherAssertTypes(__DIR__ . '/../Reflection/data/staticReturnType.php');

if (PHP_VERSION_ID < 70400) {
yield from $this->gatherAssertTypes(__DIR__ . '/../Reflection/data/reflectionNamedType.php');
} elseif (PHP_VERSION_ID < 80000) {
yield from $this->gatherAssertTypes(__DIR__ . '/../Reflection/data/reflectionNamedType74.php');
} elseif (PHP_VERSION_ID < 80100) {
yield from $this->gatherAssertTypes(__DIR__ . '/../Reflection/data/reflectionNamedType80.php');
} else {
yield from $this->gatherAssertTypes(__DIR__ . '/../Reflection/data/reflectionNamedType81.php');
}

yield from $this->gatherAssertTypes(__DIR__ . '/data/minmax.php');
if (PHP_VERSION_ID < 80000) {
yield from $this->gatherAssertTypes(__DIR__ . '/data/minmax-arrays.php');
Expand Down
44 changes: 44 additions & 0 deletions tests/PHPStan/Reflection/data/reflectionNamedType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php declare(strict_types = 1); // lint >= 8.0

namespace Reflection\NamedType;

use function PHPStan\Testing\assertType;

final class Foo
{
private $bar = 'hello';

public function baz(bool $tiny): float
{
return 4.2;
}
}

function qux(bool $switch): array
{
return [];
}

$reflectionMethod = new \ReflectionMethod(Foo::class, 'baz');

assertType(
'ReflectionNamedType|null',
$reflectionMethod->getParameters()[0]->getType()
);

assertType(
'ReflectionNamedType|null',
$reflectionMethod->getReturnType()
);

$reflectionFunction = new \ReflectionFunction('qux');

assertType(
'ReflectionNamedType|null',
$reflectionFunction->getParameters()[0]->getType()
);

assertType(
'ReflectionNamedType|null',
$reflectionFunction->getReturnType()
);
49 changes: 49 additions & 0 deletions tests/PHPStan/Reflection/data/reflectionNamedType74.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php declare(strict_types = 1); // lint >= 8.0

namespace Reflection\NamedType;

use function PHPStan\Testing\assertType;

final class Foo
{
private string $bar = 'hello';

public function baz(bool $tiny): float
{
return 4.2;
}
}

function qux(bool $switch): array
{
return [];
}

assertType(
'ReflectionNamedType|null',
(new \ReflectionProperty(Foo::class, 'bar'))->getType()
);

$reflectionMethod = new \ReflectionMethod(Foo::class, 'baz');

assertType(
'ReflectionNamedType|null',
$reflectionMethod->getParameters()[0]->getType()
);

assertType(
'ReflectionNamedType|null',
$reflectionMethod->getReturnType()
);

$reflectionFunction = new \ReflectionFunction('qux');

assertType(
'ReflectionNamedType|null',
$reflectionFunction->getParameters()[0]->getType()
);

assertType(
'ReflectionNamedType|null',
$reflectionFunction->getReturnType()
);
49 changes: 49 additions & 0 deletions tests/PHPStan/Reflection/data/reflectionNamedType80.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php declare(strict_types = 1); // lint >= 8.0

namespace Reflection\NamedType;

use function PHPStan\Testing\assertType;

final class Foo
{
private string $bar = 'hello';

public function baz(int|bool $tiny): float
{
return 4.2;
}
}

function qux(bool $switch): array
{
return [];
}

assertType(
'ReflectionNamedType|ReflectionUnionType|null',
(new \ReflectionProperty(Foo::class, 'bar'))->getType()
);

$reflectionMethod = new \ReflectionMethod(Foo::class, 'baz');

assertType(
'ReflectionNamedType|ReflectionUnionType|null',
$reflectionMethod->getParameters()[0]->getType()
);

assertType(
'ReflectionNamedType|ReflectionUnionType|null',
$reflectionMethod->getReturnType()
);

$reflectionFunction = new \ReflectionFunction('qux');

assertType(
'ReflectionNamedType|ReflectionUnionType|null',
$reflectionFunction->getParameters()[0]->getType()
);

assertType(
'ReflectionNamedType|ReflectionUnionType|null',
$reflectionFunction->getReturnType()
);
49 changes: 49 additions & 0 deletions tests/PHPStan/Reflection/data/reflectionNamedType81.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php declare(strict_types = 1); // lint >= 8.0

namespace Reflection\NamedType;

use function PHPStan\Testing\assertType;

final class Foo
{
private string $bar = 'hello';

public function baz(int|bool $tiny): float
{
return 4.2;
}
}

function qux(bool $switch): array
{
return [];
}

assertType(
'ReflectionIntersectionType|ReflectionNamedType|ReflectionUnionType|null',
(new \ReflectionProperty(Foo::class, 'bar'))->getType()
);

$reflectionMethod = new \ReflectionMethod(Foo::class, 'baz');

assertType(
'ReflectionIntersectionType|ReflectionNamedType|ReflectionUnionType|null',
$reflectionMethod->getParameters()[0]->getType()
);

assertType(
'ReflectionIntersectionType|ReflectionNamedType|ReflectionUnionType|null',
$reflectionMethod->getReturnType()
);

$reflectionFunction = new \ReflectionFunction('qux');

assertType(
'ReflectionIntersectionType|ReflectionNamedType|ReflectionUnionType|null',
$reflectionFunction->getParameters()[0]->getType()
);

assertType(
'ReflectionIntersectionType|ReflectionNamedType|ReflectionUnionType|null',
$reflectionFunction->getReturnType()
);

0 comments on commit 2b2af4e

Please sign in to comment.