Skip to content

Commit

Permalink
[TypeDeclaration] Add return static property support on ReturnTypeFro…
Browse files Browse the repository at this point in the history
…mStrictTypedPropertyRector (#5050)

* [TypeDeclaration] Add return static property support on ReturnTypeFromStrictTypedPropertyRector

* Fixed 🎉

* trigger CI
  • Loading branch information
samsonasik committed Sep 19, 2023
1 parent 76611f6 commit 5ee831f
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromStrictTypedPropertyRector\Fixture;

class ReturnStaticProperty
{
/**
* @var Service[]
*/
private static array $registry = [];

/**
* find registered Service.
*
* @return Service[]
*/
public static function getRegisteredServices()
{
return self::$registry;
}
}

?>
-----
<?php

namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromStrictTypedPropertyRector\Fixture;

class ReturnStaticProperty
{
/**
* @var Service[]
*/
private static array $registry = [];

/**
* find registered Service.
*
* @return Service[]
*/
public static function getRegisteredServices(): array
{
return self::$registry;
}
}

?>
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use PhpParser\Node;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\PropertyFetch;
use PhpParser\Node\Expr\StaticPropertyFetch;
use PhpParser\Node\Stmt\ClassMethod;
use PhpParser\Node\Stmt\Return_;
use PHPStan\Analyser\Scope;
Expand Down Expand Up @@ -129,7 +130,7 @@ private function resolveReturnPropertyType(ClassMethod $classMethod): array
return [];
}

if (! $return->expr instanceof PropertyFetch) {
if (! $return->expr instanceof PropertyFetch && ! $return->expr instanceof StaticPropertyFetch) {
return [];
}

Expand Down

0 comments on commit 5ee831f

Please sign in to comment.