Updated Rector to commit 1d88337fd2a40fec23671eb7e8662d4ad95a3187

1d88337fd2 [TypeDeclaration] Handle Parent ClassMethod has no Return_ stmt on ReturnTypeDeclarationRector (#2980)
This commit is contained in:
Tomas Votruba 2022-10-07 23:55:31 +00:00
parent 07746f72b0
commit 32c7260742
13 changed files with 104 additions and 43 deletions

View File

@ -14,12 +14,14 @@ use PHPStan\Type\Generic\GenericClassStringType;
use PHPStan\Type\MixedType;
use PHPStan\Type\StringType;
use PHPStan\Type\Type;
use PHPStan\Type\VoidType;
use Rector\Core\PhpParser\AstResolver;
use Rector\Core\PhpParser\Node\BetterNodeFinder;
use Rector\Core\Reflection\ReflectionResolver;
use Rector\FamilyTree\Reflection\FamilyRelationsAnalyzer;
use Rector\NodeNameResolver\NodeNameResolver;
use Rector\StaticTypeMapper\PhpDoc\CustomPHPStanDetector;
use Rector\TypeDeclaration\TypeInferer\ReturnTypeInferer;
final class ClassMethodReturnTypeOverrideGuard
{
/**
@ -61,7 +63,12 @@ final class ClassMethodReturnTypeOverrideGuard
* @var \Rector\StaticTypeMapper\PhpDoc\CustomPHPStanDetector
*/
private $customPHPStanDetector;
public function __construct(NodeNameResolver $nodeNameResolver, ReflectionProvider $reflectionProvider, FamilyRelationsAnalyzer $familyRelationsAnalyzer, BetterNodeFinder $betterNodeFinder, AstResolver $astResolver, ReflectionResolver $reflectionResolver, CustomPHPStanDetector $customPHPStanDetector)
/**
* @readonly
* @var \Rector\TypeDeclaration\TypeInferer\ReturnTypeInferer
*/
private $returnTypeInferer;
public function __construct(NodeNameResolver $nodeNameResolver, ReflectionProvider $reflectionProvider, FamilyRelationsAnalyzer $familyRelationsAnalyzer, BetterNodeFinder $betterNodeFinder, AstResolver $astResolver, ReflectionResolver $reflectionResolver, CustomPHPStanDetector $customPHPStanDetector, ReturnTypeInferer $returnTypeInferer)
{
$this->nodeNameResolver = $nodeNameResolver;
$this->reflectionProvider = $reflectionProvider;
@ -70,6 +77,7 @@ final class ClassMethodReturnTypeOverrideGuard
$this->astResolver = $astResolver;
$this->reflectionResolver = $reflectionResolver;
$this->customPHPStanDetector = $customPHPStanDetector;
$this->returnTypeInferer = $returnTypeInferer;
}
public function shouldSkipClassMethod(ClassMethod $classMethod) : bool
{
@ -116,6 +124,7 @@ final class ClassMethodReturnTypeOverrideGuard
*/
private function shouldSkipHasChildHasReturnType(array $childrenClassReflections, ClassMethod $classMethod) : bool
{
$returnType = $this->returnTypeInferer->inferFunctionLike($classMethod);
$methodName = $this->nodeNameResolver->getName($classMethod);
foreach ($childrenClassReflections as $childClassReflection) {
if (!$childClassReflection->hasNativeMethod($methodName)) {
@ -129,6 +138,10 @@ final class ClassMethodReturnTypeOverrideGuard
if ($method->returnType instanceof Node) {
return \true;
}
$childReturnType = $this->returnTypeInferer->inferFunctionLike($method);
if ($returnType instanceof VoidType && !$childReturnType instanceof VoidType) {
return \true;
}
}
return \false;
}

View File

@ -17,12 +17,12 @@ final class VersionResolver
* @api
* @var string
*/
public const PACKAGE_VERSION = '0c2b4f7732587b7ed55b3279a7807c09162ad010';
public const PACKAGE_VERSION = '1d88337fd2a40fec23671eb7e8662d4ad95a3187';
/**
* @api
* @var string
*/
public const RELEASE_DATE = '2022-10-05 21:09:39';
public const RELEASE_DATE = '2022-10-08 01:50:07';
/**
* @var int
*/

2
vendor/autoload.php vendored
View File

@ -9,4 +9,4 @@ if (PHP_VERSION_ID < 50600) {
require_once __DIR__ . '/composer/autoload_real.php';
return ComposerAutoloaderInite61f97ffaa20fa7dbd2d815f3d528466::getLoader();
return ComposerAutoloaderInit28957ac8547a00148356c7b4a02f40aa::getLoader();

View File

@ -39,6 +39,7 @@ return array(
'PHPStan\\PhpDocParser\\Ast\\PhpDoc\\PhpDocTextNode' => $vendorDir . '/phpstan/phpdoc-parser/src/Ast/PhpDoc/PhpDocTextNode.php',
'PHPStan\\PhpDocParser\\Ast\\PhpDoc\\PropertyTagValueNode' => $vendorDir . '/phpstan/phpdoc-parser/src/Ast/PhpDoc/PropertyTagValueNode.php',
'PHPStan\\PhpDocParser\\Ast\\PhpDoc\\ReturnTagValueNode' => $vendorDir . '/phpstan/phpdoc-parser/src/Ast/PhpDoc/ReturnTagValueNode.php',
'PHPStan\\PhpDocParser\\Ast\\PhpDoc\\SelfOutTagValueNode' => $vendorDir . '/phpstan/phpdoc-parser/src/Ast/PhpDoc/SelfOutTagValueNode.php',
'PHPStan\\PhpDocParser\\Ast\\PhpDoc\\TemplateTagValueNode' => $vendorDir . '/phpstan/phpdoc-parser/src/Ast/PhpDoc/TemplateTagValueNode.php',
'PHPStan\\PhpDocParser\\Ast\\PhpDoc\\ThrowsTagValueNode' => $vendorDir . '/phpstan/phpdoc-parser/src/Ast/PhpDoc/ThrowsTagValueNode.php',
'PHPStan\\PhpDocParser\\Ast\\PhpDoc\\TypeAliasImportTagValueNode' => $vendorDir . '/phpstan/phpdoc-parser/src/Ast/PhpDoc/TypeAliasImportTagValueNode.php',

View File

@ -2,7 +2,7 @@
// autoload_real.php @generated by Composer
class ComposerAutoloaderInite61f97ffaa20fa7dbd2d815f3d528466
class ComposerAutoloaderInit28957ac8547a00148356c7b4a02f40aa
{
private static $loader;
@ -22,19 +22,19 @@ class ComposerAutoloaderInite61f97ffaa20fa7dbd2d815f3d528466
return self::$loader;
}
spl_autoload_register(array('ComposerAutoloaderInite61f97ffaa20fa7dbd2d815f3d528466', 'loadClassLoader'), true, true);
spl_autoload_register(array('ComposerAutoloaderInit28957ac8547a00148356c7b4a02f40aa', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
spl_autoload_unregister(array('ComposerAutoloaderInite61f97ffaa20fa7dbd2d815f3d528466', 'loadClassLoader'));
spl_autoload_unregister(array('ComposerAutoloaderInit28957ac8547a00148356c7b4a02f40aa', 'loadClassLoader'));
require __DIR__ . '/autoload_static.php';
call_user_func(\Composer\Autoload\ComposerStaticInite61f97ffaa20fa7dbd2d815f3d528466::getInitializer($loader));
call_user_func(\Composer\Autoload\ComposerStaticInit28957ac8547a00148356c7b4a02f40aa::getInitializer($loader));
$loader->setClassMapAuthoritative(true);
$loader->register(true);
$includeFiles = \Composer\Autoload\ComposerStaticInite61f97ffaa20fa7dbd2d815f3d528466::$files;
$includeFiles = \Composer\Autoload\ComposerStaticInit28957ac8547a00148356c7b4a02f40aa::$files;
foreach ($includeFiles as $fileIdentifier => $file) {
composerRequiree61f97ffaa20fa7dbd2d815f3d528466($fileIdentifier, $file);
composerRequire28957ac8547a00148356c7b4a02f40aa($fileIdentifier, $file);
}
return $loader;
@ -46,7 +46,7 @@ class ComposerAutoloaderInite61f97ffaa20fa7dbd2d815f3d528466
* @param string $file
* @return void
*/
function composerRequiree61f97ffaa20fa7dbd2d815f3d528466($fileIdentifier, $file)
function composerRequire28957ac8547a00148356c7b4a02f40aa($fileIdentifier, $file)
{
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
$GLOBALS['__composer_autoload_files'][$fileIdentifier] = true;

View File

@ -4,7 +4,7 @@
namespace Composer\Autoload;
class ComposerStaticInite61f97ffaa20fa7dbd2d815f3d528466
class ComposerStaticInit28957ac8547a00148356c7b4a02f40aa
{
public static $files = array (
'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php',
@ -294,6 +294,7 @@ class ComposerStaticInite61f97ffaa20fa7dbd2d815f3d528466
'PHPStan\\PhpDocParser\\Ast\\PhpDoc\\PhpDocTextNode' => __DIR__ . '/..' . '/phpstan/phpdoc-parser/src/Ast/PhpDoc/PhpDocTextNode.php',
'PHPStan\\PhpDocParser\\Ast\\PhpDoc\\PropertyTagValueNode' => __DIR__ . '/..' . '/phpstan/phpdoc-parser/src/Ast/PhpDoc/PropertyTagValueNode.php',
'PHPStan\\PhpDocParser\\Ast\\PhpDoc\\ReturnTagValueNode' => __DIR__ . '/..' . '/phpstan/phpdoc-parser/src/Ast/PhpDoc/ReturnTagValueNode.php',
'PHPStan\\PhpDocParser\\Ast\\PhpDoc\\SelfOutTagValueNode' => __DIR__ . '/..' . '/phpstan/phpdoc-parser/src/Ast/PhpDoc/SelfOutTagValueNode.php',
'PHPStan\\PhpDocParser\\Ast\\PhpDoc\\TemplateTagValueNode' => __DIR__ . '/..' . '/phpstan/phpdoc-parser/src/Ast/PhpDoc/TemplateTagValueNode.php',
'PHPStan\\PhpDocParser\\Ast\\PhpDoc\\ThrowsTagValueNode' => __DIR__ . '/..' . '/phpstan/phpdoc-parser/src/Ast/PhpDoc/ThrowsTagValueNode.php',
'PHPStan\\PhpDocParser\\Ast\\PhpDoc\\TypeAliasImportTagValueNode' => __DIR__ . '/..' . '/phpstan/phpdoc-parser/src/Ast/PhpDoc/TypeAliasImportTagValueNode.php',
@ -3087,9 +3088,9 @@ class ComposerStaticInite61f97ffaa20fa7dbd2d815f3d528466
public static function getInitializer(ClassLoader $loader)
{
return \Closure::bind(function () use ($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticInite61f97ffaa20fa7dbd2d815f3d528466::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInite61f97ffaa20fa7dbd2d815f3d528466::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInite61f97ffaa20fa7dbd2d815f3d528466::$classMap;
$loader->prefixLengthsPsr4 = ComposerStaticInit28957ac8547a00148356c7b4a02f40aa::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit28957ac8547a00148356c7b4a02f40aa::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInit28957ac8547a00148356c7b4a02f40aa::$classMap;
}, null, ClassLoader::class);
}

View File

@ -685,17 +685,17 @@
},
{
"name": "phpstan\/phpdoc-parser",
"version": "1.8.0",
"version_normalized": "1.8.0.0",
"version": "1.9.0",
"version_normalized": "1.9.0.0",
"source": {
"type": "git",
"url": "https:\/\/github.com\/phpstan\/phpdoc-parser.git",
"reference": "8dd908dd6156e974b9a0f8bb4cd5ad0707830f04"
"reference": "5f7eb9724b0ae386b922f34b62b3b55fee3b26cd"
},
"dist": {
"type": "zip",
"url": "https:\/\/api.github.com\/repos\/phpstan\/phpdoc-parser\/zipball\/8dd908dd6156e974b9a0f8bb4cd5ad0707830f04",
"reference": "8dd908dd6156e974b9a0f8bb4cd5ad0707830f04",
"url": "https:\/\/api.github.com\/repos\/phpstan\/phpdoc-parser\/zipball\/5f7eb9724b0ae386b922f34b62b3b55fee3b26cd",
"reference": "5f7eb9724b0ae386b922f34b62b3b55fee3b26cd",
"shasum": ""
},
"require": {
@ -710,7 +710,7 @@
"phpunit\/phpunit": "^9.5",
"symfony\/process": "^5.2"
},
"time": "2022-09-04T18:59:06+00:00",
"time": "2022-10-06T11:32:36+00:00",
"type": "library",
"installation-source": "dist",
"autoload": {
@ -727,23 +727,23 @@
"description": "PHPDoc parser with support for nullable, intersection and generic types",
"support": {
"issues": "https:\/\/github.com\/phpstan\/phpdoc-parser\/issues",
"source": "https:\/\/github.com\/phpstan\/phpdoc-parser\/tree\/1.8.0"
"source": "https:\/\/github.com\/phpstan\/phpdoc-parser\/tree\/1.9.0"
},
"install-path": "..\/phpstan\/phpdoc-parser"
},
{
"name": "phpstan\/phpstan",
"version": "1.8.7",
"version_normalized": "1.8.7.0",
"version": "1.8.8",
"version_normalized": "1.8.8.0",
"source": {
"type": "git",
"url": "https:\/\/github.com\/phpstan\/phpstan.git",
"reference": "536ff0ed719b5679e9f09c17aeaee9b31969cb8e"
"reference": "08310ce271984587e2a4cda94e1ac66510a6ea07"
},
"dist": {
"type": "zip",
"url": "https:\/\/api.github.com\/repos\/phpstan\/phpstan\/zipball\/536ff0ed719b5679e9f09c17aeaee9b31969cb8e",
"reference": "536ff0ed719b5679e9f09c17aeaee9b31969cb8e",
"url": "https:\/\/api.github.com\/repos\/phpstan\/phpstan\/zipball\/08310ce271984587e2a4cda94e1ac66510a6ea07",
"reference": "08310ce271984587e2a4cda94e1ac66510a6ea07",
"shasum": ""
},
"require": {
@ -752,7 +752,7 @@
"conflict": {
"phpstan\/phpstan-shim": "*"
},
"time": "2022-10-04T14:09:33+00:00",
"time": "2022-10-06T12:51:57+00:00",
"bin": [
"phpstan",
"phpstan.phar"
@ -775,7 +775,7 @@
],
"support": {
"issues": "https:\/\/github.com\/phpstan\/phpstan\/issues",
"source": "https:\/\/github.com\/phpstan\/phpstan\/tree\/1.8.7"
"source": "https:\/\/github.com\/phpstan\/phpstan\/tree\/1.8.8"
},
"funding": [
{

File diff suppressed because one or more lines are too long

View File

@ -219,6 +219,15 @@ class PhpDocNode implements Node
return $value instanceof \PHPStan\PhpDocParser\Ast\PhpDoc\AssertTagMethodValueNode;
});
}
/**
* @return SelfOutTagValueNode[]
*/
public function getSelfOutTypeTagValues(string $tagName = '@phpstan-this-out') : array
{
return array_filter(array_column($this->getTagsByName($tagName), 'value'), static function (\PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagValueNode $value) : bool {
return $value instanceof \PHPStan\PhpDocParser\Ast\PhpDoc\SelfOutTagValueNode;
});
}
public function __toString() : string
{
$children = array_map(static function (\PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocChildNode $child) : string {

View File

@ -0,0 +1,25 @@
<?php
declare (strict_types=1);
namespace PHPStan\PhpDocParser\Ast\PhpDoc;
use PHPStan\PhpDocParser\Ast\NodeAttributes;
use PHPStan\PhpDocParser\Ast\Type\TypeNode;
use function trim;
class SelfOutTagValueNode implements \PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagValueNode
{
use NodeAttributes;
/** @var TypeNode */
public $type;
/** @var string (may be empty) */
public $description;
public function __construct(TypeNode $type, string $description)
{
$this->type = $type;
$this->description = $description;
}
public function __toString() : string
{
return trim($this->type . ' ' . $this->description);
}
}

View File

@ -173,6 +173,12 @@ class PhpDocParser
case '@psalm-assert-if-false':
$tagValue = $this->parseAssertTagValue($tokens);
break;
case '@phpstan-this-out':
case '@phpstan-self-out':
case '@psalm-this-out':
case '@psalm-self-out':
$tagValue = $this->parseSelfOutTagValue($tokens);
break;
default:
$tagValue = new Ast\PhpDoc\GenericTagValueNode($this->parseOptionalDescription($tokens));
break;
@ -384,6 +390,12 @@ class PhpDocParser
}
return ['parameter' => $parameter];
}
private function parseSelfOutTagValue(\PHPStan\PhpDocParser\Parser\TokenIterator $tokens) : Ast\PhpDoc\SelfOutTagValueNode
{
$type = $this->typeParser->parse($tokens);
$description = $this->parseOptionalDescription($tokens);
return new Ast\PhpDoc\SelfOutTagValueNode($type, $description);
}
private function parseOptionalVariableName(\PHPStan\PhpDocParser\Parser\TokenIterator $tokens) : string
{
if ($tokens->isCurrentTokenType(Lexer::TOKEN_VARIABLE)) {

Binary file not shown.

View File

@ -1,16 +1,16 @@
-----BEGIN PGP SIGNATURE-----
iQIzBAABCgAdFiEE0yaA1ZV9xxFr4pwUzxoQjQ565yAFAmM8Po0ACgkQzxoQjQ56
5yDlIA//af9OYSJV/UdeIwBWSLRR0EpeKDKqPWY/jZDkYlcHnH+BqLTMAXkVo4A1
1RKWBxshA0i4Wnm3U48sC1IynT9HmE/B51zXkOrVEjfciRCK43vrM/TqvT0z/pjk
tcdJY/kdzG5Tlmg4iFs4Or1107w8mzAPcRawGjxsXz0wPNeKiEuSPAsWV1ikghrI
NNMTAR+OEzRnxheB+wqjjhQeSdXdhCtoU43g2vbNr6KH40gKmDcx1/0AIt5+bNS+
3mxtu3PcChhvCnGjCwoxPWCboS7WJ+DnhpIZjHbtN0jWIzHOuR9x8cW8i5HGRBt0
u4njDN1dt3kW1tKLRNEI9CoNsDqhsfzniSYzoIMoxVVabLrm16v12s++4wIw6HrH
uiHmvSiAME/emrIu0PM9mJfRT9md4v3Zk21jT9GOLo90OmTA8JnEQ5m4yJeGwSIl
qJcpTMnV7hwTfjPsQrB+6B0KeZbN7ixsuJOKAVSvmyVLRsea4scfWhSHvUEoYp8m
ariLjImnxNZLUgvTdzt+2HCqn4i88p5veMUtVAaaFoxScEDTmvZbgeXf/Ai9QQ1l
/reZ8D+ZLZa94Np9J8wcOPMloZ+ITZjGIgM2sx1Yo+EwFio73OnCN1rVOWXroZxW
LmCBOXdx4uxxBdY7Qd2jtPvzjy+YmbG4gYFFGd24FUk9AfqZUE4=
=ttXB
iQIzBAABCgAdFiEE0yaA1ZV9xxFr4pwUzxoQjQ565yAFAmM+z2AACgkQzxoQjQ56
5yDa2A/9FpFMEMPXk3jBDJTJXI8zKkK8lpZc6IFB1wrnabflJ5VuC9brB3cCFyQA
rskm2gS5F6p4C+zz1BAPA1C9l0lrKYx6cx61a1EbaQn+gBP3rghqoIH75hUb/r0Y
xydZ+RIEpuAymV4l80mApZ/f0YFtHCdHAkSr0U1BFvsO73zi9kphsWSD493EtVUe
X8HQaL3zRAt1nmNQ7T3yPEO/a3pyptx/A6acFK73+1ADRRA87kTPyLyxTf3FqUIf
3CSkD5wckhF8rCDSB4I8sU9aNEQ8wYNtwKfVsfNw4bM+CyNxOVWvqq2w/V74wS2W
ehypk9PfPmC2fVL8b+TJ8M3vejXNzFLbDOH7kiOn150jNYy7zrdbhmmChTDhzTfi
unXi+guynEHIBVhzF9yxVBeNPaKoVpfN9C5SpfZRapdkhucP/BIpC5vVaf3uNxX+
agze9nHM328RZuA8o0cuXgLvEOpTCVF6L+bIZtWRlpi6lQA8R0Dz64ssMkHUjrWV
lmCYXNPC0p+bBas9rfvokK9KokR10G82xyd7vxhptZU0U3CUSNOhzYtqMa8TAKcz
F/9oZZOoIeMP70Rpzlt13J1EwKsubdRZQ/7GHR5tzYuJ/Sw1ksSv3uYPLhakWMSn
vSwj1HwVMvmfYdSEEmmJZCFGqGF7SXY0o1Ak22h31z5YZZY/Wk8=
=dfub
-----END PGP SIGNATURE-----