mirror of
https://github.com/rectorphp/rector.git
synced 2024-06-03 09:50:49 +00:00
[TypeDeclaration] Handle object|static return on ReturnTypeDeclarationRector (#840)
* [TypeDeclaration] Handle object|static return on ReturnTypeDeclarationRector
* Fixed 🎉
* clean up
* clean up
* [ci-review] Rector Rectify
* clean up
* final touch: clean up
* phpstan
Co-authored-by: GitHub Action <action@github.com>
This commit is contained in:
parent
2c84f127e9
commit
ee95517c5d
|
@ -25,6 +25,7 @@ use Rector\Core\Exception\ShouldNotHappenException;
|
|||
use Rector\Core\Php\PhpVersionProvider;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\Core\ValueObject\PhpVersionFeature;
|
||||
use Rector\NodeNameResolver\NodeNameResolver;
|
||||
use Rector\PHPStanStaticTypeMapper\Contract\TypeMapperInterface;
|
||||
use Rector\PHPStanStaticTypeMapper\DoctrineTypeAnalyzer;
|
||||
use Rector\PHPStanStaticTypeMapper\PHPStanStaticTypeMapper;
|
||||
|
@ -47,7 +48,8 @@ final class UnionTypeMapper implements TypeMapperInterface
|
|||
private PhpVersionProvider $phpVersionProvider,
|
||||
private UnionTypeAnalyzer $unionTypeAnalyzer,
|
||||
private BoolUnionTypeAnalyzer $boolUnionTypeAnalyzer,
|
||||
private UnionTypeCommonTypeNarrower $unionTypeCommonTypeNarrower
|
||||
private UnionTypeCommonTypeNarrower $unionTypeCommonTypeNarrower,
|
||||
private NodeNameResolver $nodeNameResolver
|
||||
) {
|
||||
}
|
||||
|
||||
|
@ -185,6 +187,14 @@ final class UnionTypeMapper implements TypeMapperInterface
|
|||
return null;
|
||||
}
|
||||
|
||||
private function hasObjectAndStaticType(PhpParserUnionType $phpParserUnionType): bool
|
||||
{
|
||||
$typeNames = $this->nodeNameResolver->getNames($phpParserUnionType->types);
|
||||
$diff = array_diff(['object', 'static'], $typeNames);
|
||||
|
||||
return $diff === [];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Name|FullyQualified|PhpParserUnionType|null
|
||||
*/
|
||||
|
@ -201,6 +211,10 @@ final class UnionTypeMapper implements TypeMapperInterface
|
|||
return null;
|
||||
}
|
||||
|
||||
if ($this->hasObjectAndStaticType($phpParserUnionType)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $phpParserUnionType;
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
<?php
|
||||
|
||||
namespace Rector\Tests\TypeDeclaration\Rector\FunctionLike\ReturnTypeDeclarationRector\FixtureForPhp80;
|
||||
|
||||
class SkipStaticObject
|
||||
{
|
||||
/**
|
||||
* @var object
|
||||
*/
|
||||
protected $obj;
|
||||
|
||||
public function get($obj = null)
|
||||
{
|
||||
if (func_num_args() === 0) {
|
||||
return $this->obj;
|
||||
}
|
||||
|
||||
$this->obj = $obj;
|
||||
return $this;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user