Skip to content

Commit

Permalink
Merge branch refs/heads/1.12.x into 2.0.x
Browse files Browse the repository at this point in the history
  • Loading branch information
phpstan-bot authored Oct 7, 2024
2 parents fca1268 + ee802d6 commit 28e2f26
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
use PhpParser\Node\Expr\MethodCall;
use PHPStan\Analyser\Scope;
use PHPStan\Reflection\MethodReflection;
use PHPStan\Type\Accessory\AccessoryArrayListType;
use PHPStan\Type\ArrayType;
use PHPStan\Type\DynamicMethodReturnTypeExtension;
use PHPStan\Type\Generic\GenericObjectType;
use PHPStan\Type\MixedType;
use PHPStan\Type\IntegerType;
use PHPStan\Type\Type;
use ReflectionAttribute;
use function count;
Expand Down Expand Up @@ -42,7 +43,7 @@ public function getTypeFromMethodCall(MethodReflection $methodReflection, Method
$argType = $scope->getType($methodCall->getArgs()[0]->value);
$classType = $argType->getClassStringObjectType();

return new ArrayType(new MixedType(), new GenericObjectType(ReflectionAttribute::class, [$classType]));
return AccessoryArrayListType::intersectWith(new ArrayType(new IntegerType(), new GenericObjectType(ReflectionAttribute::class, [$classType])));

Check failure on line 46 in src/Type/Php/ReflectionGetAttributesMethodReturnTypeExtension.php

View workflow job for this annotation

GitHub Actions / PHPStan with result cache (8.1)

Call to an undefined static method PHPStan\Type\Accessory\AccessoryArrayListType::intersectWith().

Check failure on line 46 in src/Type/Php/ReflectionGetAttributesMethodReturnTypeExtension.php

View workflow job for this annotation

GitHub Actions / PHPStan with result cache (8.2)

Call to an undefined static method PHPStan\Type\Accessory\AccessoryArrayListType::intersectWith().

Check failure on line 46 in src/Type/Php/ReflectionGetAttributesMethodReturnTypeExtension.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.0, ubuntu-latest)

Call to an undefined static method PHPStan\Type\Accessory\AccessoryArrayListType::intersectWith().

Check failure on line 46 in src/Type/Php/ReflectionGetAttributesMethodReturnTypeExtension.php

View workflow job for this annotation

GitHub Actions / PHPStan with result cache (8.3)

Call to an undefined static method PHPStan\Type\Accessory\AccessoryArrayListType::intersectWith().

Check failure on line 46 in src/Type/Php/ReflectionGetAttributesMethodReturnTypeExtension.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.0, windows-latest)

Call to an undefined static method PHPStan\Type\Accessory\AccessoryArrayListType::intersectWith().

Check failure on line 46 in src/Type/Php/ReflectionGetAttributesMethodReturnTypeExtension.php

View workflow job for this annotation

GitHub Actions / PHPStan with result cache (8.4)

Call to an undefined static method PHPStan\Type\Accessory\AccessoryArrayListType::intersectWith().

Check failure on line 46 in src/Type/Php/ReflectionGetAttributesMethodReturnTypeExtension.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.1, ubuntu-latest)

Call to an undefined static method PHPStan\Type\Accessory\AccessoryArrayListType::intersectWith().

Check failure on line 46 in src/Type/Php/ReflectionGetAttributesMethodReturnTypeExtension.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.1, windows-latest)

Call to an undefined static method PHPStan\Type\Accessory\AccessoryArrayListType::intersectWith().

Check failure on line 46 in src/Type/Php/ReflectionGetAttributesMethodReturnTypeExtension.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.2, ubuntu-latest)

Call to an undefined static method PHPStan\Type\Accessory\AccessoryArrayListType::intersectWith().

Check failure on line 46 in src/Type/Php/ReflectionGetAttributesMethodReturnTypeExtension.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.2, windows-latest)

Call to an undefined static method PHPStan\Type\Accessory\AccessoryArrayListType::intersectWith().

Check failure on line 46 in src/Type/Php/ReflectionGetAttributesMethodReturnTypeExtension.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.3, ubuntu-latest)

Call to an undefined static method PHPStan\Type\Accessory\AccessoryArrayListType::intersectWith().

Check failure on line 46 in src/Type/Php/ReflectionGetAttributesMethodReturnTypeExtension.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.3, windows-latest)

Call to an undefined static method PHPStan\Type\Accessory\AccessoryArrayListType::intersectWith().

Check failure on line 46 in src/Type/Php/ReflectionGetAttributesMethodReturnTypeExtension.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.4, ubuntu-latest)

Call to an undefined static method PHPStan\Type\Accessory\AccessoryArrayListType::intersectWith().

Check failure on line 46 in src/Type/Php/ReflectionGetAttributesMethodReturnTypeExtension.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.4, windows-latest)

Call to an undefined static method PHPStan\Type\Accessory\AccessoryArrayListType::intersectWith().
}

}
2 changes: 1 addition & 1 deletion stubs/ReflectionClass.stub
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class ReflectionClass
public function newInstanceWithoutConstructor();

/**
* @return array<ReflectionAttribute<object>>
* @return list<ReflectionAttribute<object>>
*/
public function getAttributes(?string $name = null, int $flags = 0)
{
Expand Down
2 changes: 1 addition & 1 deletion stubs/ReflectionClassConstant.stub
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
class ReflectionClassConstant
{
/**
* @return array<ReflectionAttribute<object>>
* @return list<ReflectionAttribute<object>>
*/
public function getAttributes(?string $name = null, int $flags = 0)
{
Expand Down
2 changes: 1 addition & 1 deletion stubs/ReflectionFunctionAbstract.stub
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ abstract class ReflectionFunctionAbstract
public function getFileName () {}

/**
* @return array<ReflectionAttribute<object>>
* @return list<ReflectionAttribute<object>>
*/
public function getAttributes(?string $name = null, int $flags = 0)
{
Expand Down
2 changes: 1 addition & 1 deletion stubs/ReflectionParameter.stub
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
class ReflectionParameter
{
/**
* @return array<ReflectionAttribute<object>>
* @return list<ReflectionAttribute<object>>
*/
public function getAttributes(?string $name = null, int $flags = 0)
{
Expand Down
2 changes: 1 addition & 1 deletion stubs/ReflectionProperty.stub
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
class ReflectionProperty
{
/**
* @return array<ReflectionAttribute<object>>
* @return list<ReflectionAttribute<object>>
*/
public function getAttributes(?string $name = null, int $flags = 0)
{
Expand Down
34 changes: 17 additions & 17 deletions tests/PHPStan/Analyser/nsrt/reflectionclass-issue-5511-php8.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,38 +36,38 @@ function testGetAttributes(
$classStr = $reflectionClass->getAttributes($str);
$classNonsense = $reflectionClass->getAttributes("some random string");

assertType('array<ReflectionAttribute<object>>', $classAll);
assertType('array<ReflectionAttribute<Issue5511\Abc>>', $classAbc1);
assertType('array<ReflectionAttribute<Issue5511\Abc>>', $classAbc2);
assertType('array<ReflectionAttribute<Issue5511\Abc>>', $classGCN);
assertType('array<ReflectionAttribute<object>>', $classCN);
assertType('array<ReflectionAttribute<object>>', $classStr);
assertType('array<ReflectionAttribute<*ERROR*>>', $classNonsense);
assertType('list<ReflectionAttribute<object>>', $classAll);
assertType('list<ReflectionAttribute<Issue5511\Abc>>', $classAbc1);
assertType('list<ReflectionAttribute<Issue5511\Abc>>', $classAbc2);
assertType('list<ReflectionAttribute<Issue5511\Abc>>', $classGCN);
assertType('list<ReflectionAttribute<object>>', $classCN);
assertType('list<ReflectionAttribute<object>>', $classStr);
assertType('list<ReflectionAttribute<*ERROR*>>', $classNonsense);

$methodAll = $reflectionMethod->getAttributes();
$methodAbc = $reflectionMethod->getAttributes(Abc::class);
assertType('array<ReflectionAttribute<object>>', $methodAll);
assertType('array<ReflectionAttribute<Issue5511\Abc>>', $methodAbc);
assertType('list<ReflectionAttribute<object>>', $methodAll);
assertType('list<ReflectionAttribute<Issue5511\Abc>>', $methodAbc);

$paramAll = $reflectionParameter->getAttributes();
$paramAbc = $reflectionParameter->getAttributes(Abc::class);
assertType('array<ReflectionAttribute<object>>', $paramAll);
assertType('array<ReflectionAttribute<Issue5511\Abc>>', $paramAbc);
assertType('list<ReflectionAttribute<object>>', $paramAll);
assertType('list<ReflectionAttribute<Issue5511\Abc>>', $paramAbc);

$propAll = $reflectionProperty->getAttributes();
$propAbc = $reflectionProperty->getAttributes(Abc::class);
assertType('array<ReflectionAttribute<object>>', $propAll);
assertType('array<ReflectionAttribute<Issue5511\Abc>>', $propAbc);
assertType('list<ReflectionAttribute<object>>', $propAll);
assertType('list<ReflectionAttribute<Issue5511\Abc>>', $propAbc);

$constAll = $reflectionClassConstant->getAttributes();
$constAbc = $reflectionClassConstant->getAttributes(Abc::class);
assertType('array<ReflectionAttribute<object>>', $constAll);
assertType('array<ReflectionAttribute<Issue5511\Abc>>', $constAbc);
assertType('list<ReflectionAttribute<object>>', $constAll);
assertType('list<ReflectionAttribute<Issue5511\Abc>>', $constAbc);

$funcAll = $reflectionFunction->getAttributes();
$funcAbc = $reflectionFunction->getAttributes(Abc::class);
assertType('array<ReflectionAttribute<object>>', $funcAll);
assertType('array<ReflectionAttribute<Issue5511\Abc>>', $funcAbc);
assertType('list<ReflectionAttribute<object>>', $funcAll);
assertType('list<ReflectionAttribute<Issue5511\Abc>>', $funcAbc);
}

/**
Expand Down

0 comments on commit 28e2f26

Please sign in to comment.