Updated Rector to commit 20ec11e73d8998f9ad7533c8f179ee7be8e2abdf

20ec11e73d [Docblock] Move DocBlockUpdater service usage from AbstractRector to PhpDocTypeChanger (#4215)
This commit is contained in:
Tomas Votruba 2023-06-14 04:39:10 +00:00
parent 50725c3d53
commit 4c28e357ca
37 changed files with 90 additions and 92 deletions

View File

@ -3,7 +3,9 @@
declare (strict_types=1);
namespace Rector\BetterPhpDocParser\PhpDocManipulator;
use PhpParser\Node\FunctionLike;
use PhpParser\Node\Param;
use PhpParser\Node\Stmt;
use PhpParser\Node\Stmt\ClassMethod;
use PhpParser\Node\Stmt\Property;
use PHPStan\PhpDocParser\Ast\ConstExpr\ConstFetchNode;
@ -28,6 +30,7 @@ use Rector\BetterPhpDocParser\ValueObject\Type\BracketsAwareIntersectionTypeNode
use Rector\BetterPhpDocParser\ValueObject\Type\BracketsAwareUnionTypeNode;
use Rector\BetterPhpDocParser\ValueObject\Type\SpacingAwareArrayTypeNode;
use Rector\BetterPhpDocParser\ValueObject\Type\SpacingAwareCallableTypeNode;
use Rector\Comments\NodeDocBlock\DocBlockUpdater;
use Rector\NodeNameResolver\NodeNameResolver;
use Rector\NodeTypeResolver\Node\AttributeKey;
use Rector\NodeTypeResolver\TypeComparator\TypeComparator;
@ -71,6 +74,11 @@ final class PhpDocTypeChanger
* @var \Rector\BetterPhpDocParser\Guard\NewPhpDocFromPHPStanTypeGuard
*/
private $newPhpDocFromPHPStanTypeGuard;
/**
* @readonly
* @var \Rector\Comments\NodeDocBlock\DocBlockUpdater
*/
private $docBlockUpdater;
/**
* @var array<class-string<Node>>
*/
@ -79,7 +87,7 @@ final class PhpDocTypeChanger
* @var string[]
*/
private const ALLOWED_IDENTIFIER_TYPENODE_TYPES = ['class-string'];
public function __construct(StaticTypeMapper $staticTypeMapper, TypeComparator $typeComparator, ParamPhpDocNodeFactory $paramPhpDocNodeFactory, NodeNameResolver $nodeNameResolver, CommentsMerger $commentsMerger, PhpDocInfoFactory $phpDocInfoFactory, NewPhpDocFromPHPStanTypeGuard $newPhpDocFromPHPStanTypeGuard)
public function __construct(StaticTypeMapper $staticTypeMapper, TypeComparator $typeComparator, ParamPhpDocNodeFactory $paramPhpDocNodeFactory, NodeNameResolver $nodeNameResolver, CommentsMerger $commentsMerger, PhpDocInfoFactory $phpDocInfoFactory, NewPhpDocFromPHPStanTypeGuard $newPhpDocFromPHPStanTypeGuard, DocBlockUpdater $docBlockUpdater)
{
$this->staticTypeMapper = $staticTypeMapper;
$this->typeComparator = $typeComparator;
@ -88,8 +96,9 @@ final class PhpDocTypeChanger
$this->commentsMerger = $commentsMerger;
$this->phpDocInfoFactory = $phpDocInfoFactory;
$this->newPhpDocFromPHPStanTypeGuard = $newPhpDocFromPHPStanTypeGuard;
$this->docBlockUpdater = $docBlockUpdater;
}
public function changeVarType(PhpDocInfo $phpDocInfo, Type $newType) : void
public function changeVarType(Stmt $stmt, PhpDocInfo $phpDocInfo, Type $newType) : void
{
// better skip, could crash hard
if ($phpDocInfo->hasInvalidTag('@var')) {
@ -118,8 +127,9 @@ final class PhpDocTypeChanger
$varTagValueNode = new VarTagValueNode($newPHPStanPhpDocTypeNode, '', '');
$phpDocInfo->addTagValueNode($varTagValueNode);
}
$this->docBlockUpdater->updateRefactoredNodeWithPhpDocInfo($stmt);
}
public function changeReturnType(PhpDocInfo $phpDocInfo, Type $newType) : bool
public function changeReturnType(FunctionLike $functionLike, PhpDocInfo $phpDocInfo, Type $newType) : bool
{
// better not touch this, can crash
if ($phpDocInfo->hasInvalidTag('@return')) {
@ -144,9 +154,10 @@ final class PhpDocTypeChanger
$returnTagValueNode = new ReturnTagValueNode($newPHPStanPhpDocTypeNode, '');
$phpDocInfo->addTagValueNode($returnTagValueNode);
}
$this->docBlockUpdater->updateRefactoredNodeWithPhpDocInfo($functionLike);
return \true;
}
public function changeParamType(PhpDocInfo $phpDocInfo, Type $newType, Param $param, string $paramName) : void
public function changeParamType(FunctionLike $functionLike, PhpDocInfo $phpDocInfo, Type $newType, Param $param, string $paramName) : void
{
// better skip, could crash hard
if ($phpDocInfo->hasInvalidTag('@param')) {
@ -174,6 +185,7 @@ final class PhpDocTypeChanger
$paramTagValueNode = $this->paramPhpDocNodeFactory->create($phpDocTypeNode, $param);
$phpDocInfo->addTagValueNode($paramTagValueNode);
}
$this->docBlockUpdater->updateRefactoredNodeWithPhpDocInfo($functionLike);
}
public function isAllowed(TypeNode $typeNode) : bool
{
@ -220,17 +232,18 @@ final class PhpDocTypeChanger
$param->setAttribute(AttributeKey::PHP_DOC_INFO, $phpDocInfo);
$phpDocInfo = $classMethod->getAttribute(AttributeKey::PHP_DOC_INFO);
$paramType = $this->staticTypeMapper->mapPHPStanPhpDocTypeToPHPStanType($varTagValueNode, $property);
$this->changeParamType($phpDocInfo, $paramType, $param, $paramVarName);
$this->changeParamType($classMethod, $phpDocInfo, $paramType, $param, $paramVarName);
$this->processKeepComments($property, $param);
}
/**
* @api doctrine
*/
public function changeVarTypeNode(PhpDocInfo $phpDocInfo, TypeNode $typeNode) : void
public function changeVarTypeNode(Stmt $stmt, PhpDocInfo $phpDocInfo, TypeNode $typeNode) : void
{
// add completely new one
$varTagValueNode = new VarTagValueNode($typeNode, '', '');
$phpDocInfo->addTagValueNode($varTagValueNode);
$this->docBlockUpdater->updateRefactoredNodeWithPhpDocInfo($stmt);
}
private function processKeepComments(Property $property, Param $param) : void
{
@ -238,6 +251,7 @@ final class PhpDocTypeChanger
$varTagValueNode = $phpDocInfo->getVarTagValueNode();
$toBeRemoved = !$varTagValueNode instanceof VarTagValueNode;
$this->commentsMerger->keepComments($param, [$property]);
$this->docBlockUpdater->updateRefactoredNodeWithPhpDocInfo($property);
$phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($param);
$varTagValueNode = $phpDocInfo->getVarTagValueNode();
if (!$toBeRemoved) {
@ -250,5 +264,6 @@ final class PhpDocTypeChanger
return;
}
$phpDocInfo->removeByType(VarTagValueNode::class);
$this->docBlockUpdater->updateRefactoredNodeWithPhpDocInfo($property);
}
}

View File

@ -37,6 +37,6 @@ final class PropertyTypeDecorator
$propertyType = $this->typeNormalizer->generalizeConstantBoolTypes($propertyType);
$phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($property);
$phpDocInfo->makeMultiLined();
$this->phpDocTypeChanger->changeVarType($phpDocInfo, $propertyType);
$this->phpDocTypeChanger->changeVarType($property, $phpDocInfo, $propertyType);
}
}

View File

@ -93,7 +93,7 @@ CODE_SAMPLE
if ($this->typeComparator->isSubtype($constType, $phpDocInfo->getVarType())) {
return null;
}
$this->phpDocTypeChanger->changeVarType($phpDocInfo, $constType);
$this->phpDocTypeChanger->changeVarType($node, $phpDocInfo, $constType);
if (!$phpDocInfo->hasChanged()) {
return null;
}

View File

@ -234,7 +234,7 @@ CODE_SAMPLE
}
$paramType = $this->staticTypeMapper->mapPHPStanPhpDocTypeToPHPStanType($varTagValueNode, $property);
$classMethodPhpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($classMethod);
$this->phpDocTypeChanger->changeParamType($classMethodPhpDocInfo, $paramType, $param, $paramName);
$this->phpDocTypeChanger->changeParamType($classMethod, $classMethodPhpDocInfo, $paramType, $param, $paramName);
} else {
$paramType = $this->staticTypeMapper->mapPhpParserNodePHPStanType($param->type);
}

View File

@ -56,7 +56,7 @@ final class PropertyTypeDecorator
return;
}
if ($changeVarTypeFallback) {
$this->phpDocTypeChanger->changeVarType($phpDocInfo, $unionType);
$this->phpDocTypeChanger->changeVarType($property, $phpDocInfo, $unionType);
}
return;
}
@ -73,7 +73,7 @@ final class PropertyTypeDecorator
if (!$changeVarTypeFallback) {
return;
}
$this->phpDocTypeChanger->changeVarType($phpDocInfo, $unionType);
$this->phpDocTypeChanger->changeVarType($property, $phpDocInfo, $unionType);
}
private function isDocBlockRequired(UnionType $unionType) : bool
{

View File

@ -135,7 +135,7 @@ CODE_SAMPLE
$this->usePhpdoc = $usePhpdoc;
}
/**
* @param \PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Function_|\PhpParser\Node\Expr\Closure|\PhpParser\Node $node
* @param \PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Function_|\PhpParser\Node\Expr\Closure $node
*/
private function changePhpDocToVoidIfNotNever($node) : bool
{
@ -143,7 +143,7 @@ CODE_SAMPLE
if ($phpDocInfo->getReturnType() instanceof NeverType) {
return \false;
}
return $this->phpDocTypeChanger->changeReturnType($phpDocInfo, new VoidType());
return $this->phpDocTypeChanger->changeReturnType($node, $phpDocInfo, new VoidType());
}
/**
* @param \PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Function_|\PhpParser\Node\Expr\Closure $functionLike

View File

@ -116,7 +116,7 @@ CODE_SAMPLE
if ($returnExprTypeNode instanceof SpacingAwareArrayTypeNode) {
return null;
}
$hasChanged = $this->phpDocTypeChanger->changeReturnType($phpDocInfo, $returnExprType);
$hasChanged = $this->phpDocTypeChanger->changeReturnType($node, $phpDocInfo, $returnExprType);
if (!$hasChanged) {
return null;
}

View File

@ -110,7 +110,7 @@ CODE_SAMPLE
if (!$updatedPhpDocType instanceof Type) {
return null;
}
$hasReturnTypeChanged = $this->phpDocTypeChanger->changeReturnType($phpDocInfo, $updatedPhpDocType);
$hasReturnTypeChanged = $this->phpDocTypeChanger->changeReturnType($node, $phpDocInfo, $updatedPhpDocType);
if ($hasReturnTypeChanged) {
return $node;
}

View File

@ -153,12 +153,15 @@ CODE_SAMPLE
}
return $node instanceof ClassMethod && $this->classMethodReturnTypeOverrideGuard->shouldSkipClassMethod($node, $scope);
}
private function changeReturnType(Node $node, Type $exprType) : void
/**
* @param \PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Function_|\PhpParser\Node\Expr\Closure $node
*/
private function changeReturnType($node, Type $exprType) : void
{
$phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($node);
$exprType = $this->narrowConstantArrayType($exprType);
if (!$this->typeComparator->isSubtype($phpDocInfo->getReturnType(), $exprType)) {
$this->phpDocTypeChanger->changeReturnType($phpDocInfo, $exprType);
$this->phpDocTypeChanger->changeReturnType($node, $phpDocInfo, $exprType);
}
}
/**

View File

@ -96,7 +96,7 @@ CODE_SAMPLE
continue;
}
$paramName = $this->getName($param);
$this->phpDocTypeChanger->changeParamType($functionLikePhpDocInfo, $genericParamType, $param, $paramName);
$this->phpDocTypeChanger->changeParamType($node, $functionLikePhpDocInfo, $genericParamType, $param, $paramName);
}
if ($functionLikePhpDocInfo->hasChanged()) {
return $node;

View File

@ -115,7 +115,7 @@ CODE_SAMPLE
$phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($property);
// public property can be anything
if ($property->isPublic()) {
$this->phpDocTypeChanger->changeVarType($phpDocInfo, $propertyType);
$this->phpDocTypeChanger->changeVarType($property, $phpDocInfo, $propertyType);
$hasChanged = \true;
continue;
}

View File

@ -109,7 +109,7 @@ CODE_SAMPLE
if (!$updatedPhpDocType instanceof Type) {
return null;
}
$this->phpDocTypeChanger->changeVarType($phpDocInfo, $updatedPhpDocType);
$this->phpDocTypeChanger->changeVarType($node, $phpDocInfo, $updatedPhpDocType);
if (!$phpDocInfo->hasChanged()) {
return null;
}

View File

@ -19,12 +19,12 @@ final class VersionResolver
* @api
* @var string
*/
public const PACKAGE_VERSION = '255161870edc4a8bd94630863256caae38ca3bcd';
public const PACKAGE_VERSION = '20ec11e73d8998f9ad7533c8f179ee7be8e2abdf';
/**
* @api
* @var string
*/
public const RELEASE_DATE = '2023-06-13 21:16:53';
public const RELEASE_DATE = '2023-06-14 04:35:12';
/**
* @var int
*/

View File

@ -52,11 +52,11 @@ final class PropertyTypeDecorator
if ($phpParserType !== null) {
$property->type = $phpParserType;
if ($type instanceof GenericObjectType) {
$this->phpDocTypeChanger->changeVarType($phpDocInfo, $type);
$this->phpDocTypeChanger->changeVarType($property, $phpDocInfo, $type);
}
return;
}
}
$this->phpDocTypeChanger->changeVarType($phpDocInfo, $type);
$this->phpDocTypeChanger->changeVarType($property, $phpDocInfo, $type);
}
}

View File

@ -18,7 +18,6 @@ use PHPStan\Type\ObjectType;
use PHPStan\Type\Type;
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory;
use Rector\ChangesReporting\ValueObject\RectorWithLineChange;
use Rector\Comments\NodeDocBlock\DocBlockUpdater;
use Rector\Core\Application\ChangedNodeScopeRefresher;
use Rector\Core\Configuration\CurrentNodeProvider;
use Rector\Core\Console\Output\RectorOutputStyle;
@ -138,10 +137,6 @@ CODE_SAMPLE;
* @var \Rector\Core\FileSystem\FilePathHelper
*/
private $filePathHelper;
/**
* @var \Rector\Comments\NodeDocBlock\DocBlockUpdater
*/
private $docBlockUpdater;
/**
* @var \Rector\Core\PhpParser\NodeTraverser\NodeConnectingTraverser
*/
@ -153,7 +148,7 @@ CODE_SAMPLE;
/**
* @required
*/
public function autowire(NodeNameResolver $nodeNameResolver, NodeTypeResolver $nodeTypeResolver, SimpleCallableNodeTraverser $simpleCallableNodeTraverser, NodeFactory $nodeFactory, PhpDocInfoFactory $phpDocInfoFactory, StaticTypeMapper $staticTypeMapper, CurrentRectorProvider $currentRectorProvider, CurrentNodeProvider $currentNodeProvider, Skipper $skipper, ValueResolver $valueResolver, BetterNodeFinder $betterNodeFinder, NodeComparator $nodeComparator, CurrentFileProvider $currentFileProvider, RectifiedAnalyzer $rectifiedAnalyzer, CreatedByRuleDecorator $createdByRuleDecorator, ChangedNodeScopeRefresher $changedNodeScopeRefresher, RectorOutputStyle $rectorOutputStyle, FilePathHelper $filePathHelper, DocBlockUpdater $docBlockUpdater, NodeConnectingTraverser $nodeConnectingTraverser) : void
public function autowire(NodeNameResolver $nodeNameResolver, NodeTypeResolver $nodeTypeResolver, SimpleCallableNodeTraverser $simpleCallableNodeTraverser, NodeFactory $nodeFactory, PhpDocInfoFactory $phpDocInfoFactory, StaticTypeMapper $staticTypeMapper, CurrentRectorProvider $currentRectorProvider, CurrentNodeProvider $currentNodeProvider, Skipper $skipper, ValueResolver $valueResolver, BetterNodeFinder $betterNodeFinder, NodeComparator $nodeComparator, CurrentFileProvider $currentFileProvider, RectifiedAnalyzer $rectifiedAnalyzer, CreatedByRuleDecorator $createdByRuleDecorator, ChangedNodeScopeRefresher $changedNodeScopeRefresher, RectorOutputStyle $rectorOutputStyle, FilePathHelper $filePathHelper, NodeConnectingTraverser $nodeConnectingTraverser) : void
{
$this->nodeNameResolver = $nodeNameResolver;
$this->nodeTypeResolver = $nodeTypeResolver;
@ -173,7 +168,6 @@ CODE_SAMPLE;
$this->changedNodeScopeRefresher = $changedNodeScopeRefresher;
$this->rectorOutputStyle = $rectorOutputStyle;
$this->filePathHelper = $filePathHelper;
$this->docBlockUpdater = $docBlockUpdater;
$this->nodeConnectingTraverser = $nodeConnectingTraverser;
}
/**
@ -359,11 +353,6 @@ CODE_SAMPLE;
{
$nodes = $node instanceof Node ? [$node] : $node;
foreach ($nodes as $node) {
/**
* Early refresh Doc Comment of Node before refresh Scope to ensure doc node is latest update
* to make PHPStan type can be correctly detected
*/
$this->docBlockUpdater->updateRefactoredNodeWithPhpDocInfo($node);
$this->changedNodeScopeRefresher->refresh($node, $mutatingScope, $filePath);
}
}

2
vendor/autoload.php vendored
View File

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

View File

@ -2,7 +2,7 @@
// autoload_real.php @generated by Composer
class ComposerAutoloaderInita7771349b9c54579a836d56ab4b8fc15
class ComposerAutoloaderInitac1ee29834c5c9efc1a0259806818a4c
{
private static $loader;
@ -22,17 +22,17 @@ class ComposerAutoloaderInita7771349b9c54579a836d56ab4b8fc15
return self::$loader;
}
spl_autoload_register(array('ComposerAutoloaderInita7771349b9c54579a836d56ab4b8fc15', 'loadClassLoader'), true, true);
spl_autoload_register(array('ComposerAutoloaderInitac1ee29834c5c9efc1a0259806818a4c', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
spl_autoload_unregister(array('ComposerAutoloaderInita7771349b9c54579a836d56ab4b8fc15', 'loadClassLoader'));
spl_autoload_unregister(array('ComposerAutoloaderInitac1ee29834c5c9efc1a0259806818a4c', 'loadClassLoader'));
require __DIR__ . '/autoload_static.php';
call_user_func(\Composer\Autoload\ComposerStaticInita7771349b9c54579a836d56ab4b8fc15::getInitializer($loader));
call_user_func(\Composer\Autoload\ComposerStaticInitac1ee29834c5c9efc1a0259806818a4c::getInitializer($loader));
$loader->setClassMapAuthoritative(true);
$loader->register(true);
$filesToLoad = \Composer\Autoload\ComposerStaticInita7771349b9c54579a836d56ab4b8fc15::$files;
$filesToLoad = \Composer\Autoload\ComposerStaticInitac1ee29834c5c9efc1a0259806818a4c::$files;
$requireFile = \Closure::bind(static function ($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 ComposerStaticInita7771349b9c54579a836d56ab4b8fc15
class ComposerStaticInitac1ee29834c5c9efc1a0259806818a4c
{
public static $files = array (
'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php',
@ -3092,9 +3092,9 @@ class ComposerStaticInita7771349b9c54579a836d56ab4b8fc15
public static function getInitializer(ClassLoader $loader)
{
return \Closure::bind(function () use ($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticInita7771349b9c54579a836d56ab4b8fc15::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInita7771349b9c54579a836d56ab4b8fc15::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInita7771349b9c54579a836d56ab4b8fc15::$classMap;
$loader->prefixLengthsPsr4 = ComposerStaticInitac1ee29834c5c9efc1a0259806818a4c::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInitac1ee29834c5c9efc1a0259806818a4c::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInitac1ee29834c5c9efc1a0259806818a4c::$classMap;
}, null, ClassLoader::class);
}

View File

@ -1921,12 +1921,12 @@
"source": {
"type": "git",
"url": "https:\/\/github.com\/rectorphp\/rector-doctrine.git",
"reference": "9f8970b4078cc5a02daefa963c008463e29e81c7"
"reference": "6524db4198bef708130382cc85de1c976daf156b"
},
"dist": {
"type": "zip",
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-doctrine\/zipball\/9f8970b4078cc5a02daefa963c008463e29e81c7",
"reference": "9f8970b4078cc5a02daefa963c008463e29e81c7",
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-doctrine\/zipball\/6524db4198bef708130382cc85de1c976daf156b",
"reference": "6524db4198bef708130382cc85de1c976daf156b",
"shasum": ""
},
"require": {
@ -1941,7 +1941,7 @@
"phpunit\/phpunit": "^10.0",
"rector\/phpstan-rules": "^0.6",
"rector\/rector-generator": "^0.6",
"rector\/rector-src": "dev-main",
"rector\/rector-src": "dev-main#238f451bb852f30a4b43f8da735d920d95162d3f",
"symplify\/easy-ci": "^11.2",
"symplify\/easy-coding-standard": "^11.2",
"symplify\/phpstan-extensions": "^11.1",
@ -1951,7 +1951,7 @@
"tomasvotruba\/type-coverage": "^0.2",
"tomasvotruba\/unused-public": "^0.1"
},
"time": "2023-06-12T10:31:32+00:00",
"time": "2023-06-14T04:29:55+00:00",
"default-branch": true,
"type": "rector-extension",
"extra": {
@ -1986,12 +1986,12 @@
"source": {
"type": "git",
"url": "https:\/\/github.com\/rectorphp\/rector-downgrade-php.git",
"reference": "376bf4399b9c1fd985f03f0859ae31c1b7a3de35"
"reference": "83deae657a2b27fe57f2d0b362d3320e13058c20"
},
"dist": {
"type": "zip",
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-downgrade-php\/zipball\/376bf4399b9c1fd985f03f0859ae31c1b7a3de35",
"reference": "376bf4399b9c1fd985f03f0859ae31c1b7a3de35",
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-downgrade-php\/zipball\/83deae657a2b27fe57f2d0b362d3320e13058c20",
"reference": "83deae657a2b27fe57f2d0b362d3320e13058c20",
"shasum": ""
},
"require": {
@ -2004,7 +2004,7 @@
"phpunit\/phpunit": "^10.1",
"rector\/phpstan-rules": "^0.6",
"rector\/rector-generator": "^0.6",
"rector\/rector-src": "dev-main",
"rector\/rector-src": "dev-main#238f451bb852f30a4b43f8da735d920d95162d3f",
"symplify\/easy-ci": "^11.2",
"symplify\/easy-coding-standard": "^11.2",
"symplify\/phpstan-extensions": "^11.2",
@ -2015,7 +2015,7 @@
"tomasvotruba\/type-coverage": "^0.2",
"tomasvotruba\/unused-public": "^0.1"
},
"time": "2023-06-13T17:22:16+00:00",
"time": "2023-06-14T04:30:05+00:00",
"default-branch": true,
"type": "rector-extension",
"extra": {
@ -2125,12 +2125,12 @@
"source": {
"type": "git",
"url": "https:\/\/github.com\/rectorphp\/rector-symfony.git",
"reference": "563f5555ca94405a4905cc219bfba04cbd99a8ca"
"reference": "872e4779416df738c3c955938dd79b366ba2eb74"
},
"dist": {
"type": "zip",
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-symfony\/zipball\/563f5555ca94405a4905cc219bfba04cbd99a8ca",
"reference": "563f5555ca94405a4905cc219bfba04cbd99a8ca",
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-symfony\/zipball\/872e4779416df738c3c955938dd79b366ba2eb74",
"reference": "872e4779416df738c3c955938dd79b366ba2eb74",
"shasum": ""
},
"require": {
@ -2145,7 +2145,7 @@
"phpunit\/phpunit": "^10.0",
"rector\/phpstan-rules": "^0.6",
"rector\/rector-generator": "^0.6",
"rector\/rector-src": "dev-main",
"rector\/rector-src": "dev-main#238f451bb852f30a4b43f8da735d920d95162d3f",
"symfony\/routing": "^6.1",
"symfony\/security-core": "^6.2",
"symfony\/security-http": "^6.1",
@ -2160,7 +2160,7 @@
"tomasvotruba\/type-coverage": "^0.2",
"tomasvotruba\/unused-public": "^0.1"
},
"time": "2023-06-12T11:03:45+00:00",
"time": "2023-06-14T04:29:57+00:00",
"default-branch": true,
"type": "rector-extension",
"extra": {

File diff suppressed because one or more lines are too long

View File

@ -9,7 +9,7 @@ namespace Rector\RectorInstaller;
*/
final class GeneratedConfig
{
public const EXTENSIONS = array('rector/rector-doctrine' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-doctrine', 'relative_install_path' => '../../rector-doctrine', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 9f8970b'), 'rector/rector-downgrade-php' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-downgrade-php', 'relative_install_path' => '../../rector-downgrade-php', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 376bf43'), 'rector/rector-phpunit' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-phpunit', 'relative_install_path' => '../../rector-phpunit', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 2d6ed10'), 'rector/rector-symfony' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-symfony', 'relative_install_path' => '../../rector-symfony', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 563f555'));
public const EXTENSIONS = array('rector/rector-doctrine' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-doctrine', 'relative_install_path' => '../../rector-doctrine', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 6524db4'), 'rector/rector-downgrade-php' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-downgrade-php', 'relative_install_path' => '../../rector-downgrade-php', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 83deae6'), 'rector/rector-phpunit' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-phpunit', 'relative_install_path' => '../../rector-phpunit', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 2d6ed10'), 'rector/rector-symfony' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-symfony', 'relative_install_path' => '../../rector-symfony', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 872e477'));
private function __construct()
{
}

View File

@ -15,7 +15,7 @@
"symplify\/phpstan-extensions": "^11.1",
"symplify\/easy-coding-standard": "^11.2",
"symplify\/rule-doc-generator": "^11.1",
"rector\/rector-src": "dev-main",
"rector\/rector-src": "dev-main#238f451bb852f30a4b43f8da735d920d95162d3f",
"doctrine\/orm": "^2.10",
"phpstan\/phpstan-webmozart-assert": "^1.0",
"phpstan\/phpstan-strict-rules": "^1.1",

View File

@ -174,7 +174,7 @@ CODE_SAMPLE
}
/** @var string $parameterName */
$parameterName = $this->getName($param);
$this->phpDocTypeChanger->changeParamType($phpDocInfo, $collectionObjectType, $param, $parameterName);
$this->phpDocTypeChanger->changeParamType($classMethod, $phpDocInfo, $collectionObjectType, $param, $parameterName);
return $classMethod;
}
private function resolveCollectionSetterAssignType(ClassMethod $classMethod) : ?Type
@ -211,14 +211,14 @@ CODE_SAMPLE
return null;
}
$newVarType = $this->collectionTypeFactory->createType($collectionObjectType);
$this->phpDocTypeChanger->changeVarType($phpDocInfo, $newVarType);
$this->phpDocTypeChanger->changeVarType($property, $phpDocInfo, $newVarType);
} else {
$collectionObjectType = $this->collectionTypeResolver->resolveFromOneToManyProperty($property);
if (!$collectionObjectType instanceof FullyQualifiedObjectType) {
return null;
}
$newVarType = $this->collectionTypeFactory->createType($collectionObjectType);
$this->phpDocTypeChanger->changeVarType($phpDocInfo, $newVarType);
$this->phpDocTypeChanger->changeVarType($property, $phpDocInfo, $newVarType);
}
return $property;
}
@ -235,7 +235,7 @@ CODE_SAMPLE
}
$fullyQualifiedObjectType = new FullyQualifiedObjectType($targetEntityClassName);
$newVarType = $this->collectionTypeFactory->createType($fullyQualifiedObjectType);
$this->phpDocTypeChanger->changeVarType($phpDocInfo, $newVarType);
$this->phpDocTypeChanger->changeVarType($property, $phpDocInfo, $newVarType);
return $property;
}
}

View File

@ -120,7 +120,7 @@ CODE_SAMPLE
$node->type = $typeNode;
return $node;
}
$this->phpDocTypeChanger->changeVarType($phpDocInfo, $propertyType);
$this->phpDocTypeChanger->changeVarType($node, $phpDocInfo, $propertyType);
return $node;
}
}

View File

@ -101,7 +101,7 @@ CODE_SAMPLE
}
$phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($node);
// always decorate with collection generic type
$this->phpDocTypeChanger->changeVarType($phpDocInfo, $propertyType);
$this->phpDocTypeChanger->changeVarType($node, $phpDocInfo, $propertyType);
if ($this->phpVersionProvider->isAtLeastPhpVersion(PhpVersion::PHP_74)) {
if ($propertyType instanceof UnionType) {
$this->propertyTypeDecorator->decoratePropertyUnionType($propertyType, $typeNode, $node, $phpDocInfo);

View File

@ -121,6 +121,6 @@ CODE_SAMPLE
$property->type = $typeNode;
return;
}
$this->phpDocTypeChanger->changeVarType($phpDocInfo, $propertyType);
$this->phpDocTypeChanger->changeVarType($property, $phpDocInfo, $propertyType);
}
}

View File

@ -13,7 +13,7 @@
"phpunit\/phpunit": "^10.1",
"rector\/phpstan-rules": "^0.6",
"rector\/rector-generator": "^0.6",
"rector\/rector-src": "dev-main",
"rector\/rector-src": "dev-main#238f451bb852f30a4b43f8da735d920d95162d3f",
"symplify\/easy-ci": "^11.2",
"symplify\/easy-coding-standard": "^11.2",
"symplify\/phpstan-extensions": "^11.2",

View File

@ -119,6 +119,6 @@ CODE_SAMPLE
throw new ShouldNotHappenException();
}
$phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($functionLike);
$this->phpDocTypeChanger->changeParamType($phpDocInfo, $type, $param, $paramName);
$this->phpDocTypeChanger->changeParamType($functionLike, $phpDocInfo, $type, $param, $paramName);
}
}

View File

@ -59,7 +59,7 @@ final class NativeParamToPhpDocDecorator
$paramName = $this->nodeNameResolver->getName($param);
$mappedCurrentParamType = $this->staticTypeMapper->mapPhpParserNodePHPStanType($param->type);
$correctedNullableParamType = $this->correctNullableType($param, $mappedCurrentParamType);
$this->phpDocTypeChanger->changeParamType($phpDocInfo, $correctedNullableParamType, $param, $paramName);
$this->phpDocTypeChanger->changeParamType($classMethod, $phpDocInfo, $correctedNullableParamType, $param, $paramName);
}
private function isParamNullable(Param $param) : bool
{

View File

@ -8,7 +8,6 @@ use PhpParser\Node\Param;
use PhpParser\Node\Stmt\ClassLike;
use PhpParser\Node\Stmt\ClassMethod;
use PHPStan\Reflection\ClassReflection;
use Rector\Comments\NodeDocBlock\DocBlockUpdater;
use Rector\Core\Contract\Rector\AllowEmptyConfigurableRectorInterface;
use Rector\Core\Rector\AbstractRector;
use Rector\Core\Reflection\ReflectionResolver;
@ -58,16 +57,11 @@ final class DowngradeParameterTypeWideningRector extends AbstractRector implemen
* @var \Rector\DowngradePhp72\NodeAnalyzer\SealedClassAnalyzer
*/
private $sealedClassAnalyzer;
/**
* @readonly
* @var \Rector\Comments\NodeDocBlock\DocBlockUpdater
*/
private $docBlockUpdater;
/**
* @var array<string, string[]>
*/
private $unsafeTypesToMethods = [];
public function __construct(NativeParamToPhpDocDecorator $nativeParamToPhpDocDecorator, ReflectionResolver $reflectionResolver, AutowiredClassMethodOrPropertyAnalyzer $autowiredClassMethodOrPropertyAnalyzer, BuiltInMethodAnalyzer $builtInMethodAnalyzer, OverrideFromAnonymousClassMethodAnalyzer $overrideFromAnonymousClassMethodAnalyzer, SealedClassAnalyzer $sealedClassAnalyzer, DocBlockUpdater $docBlockUpdater)
public function __construct(NativeParamToPhpDocDecorator $nativeParamToPhpDocDecorator, ReflectionResolver $reflectionResolver, AutowiredClassMethodOrPropertyAnalyzer $autowiredClassMethodOrPropertyAnalyzer, BuiltInMethodAnalyzer $builtInMethodAnalyzer, OverrideFromAnonymousClassMethodAnalyzer $overrideFromAnonymousClassMethodAnalyzer, SealedClassAnalyzer $sealedClassAnalyzer)
{
$this->nativeParamToPhpDocDecorator = $nativeParamToPhpDocDecorator;
$this->reflectionResolver = $reflectionResolver;
@ -75,7 +69,6 @@ final class DowngradeParameterTypeWideningRector extends AbstractRector implemen
$this->builtInMethodAnalyzer = $builtInMethodAnalyzer;
$this->overrideFromAnonymousClassMethodAnalyzer = $overrideFromAnonymousClassMethodAnalyzer;
$this->sealedClassAnalyzer = $sealedClassAnalyzer;
$this->docBlockUpdater = $docBlockUpdater;
}
public function getRuleDefinition() : RuleDefinition
{
@ -127,7 +120,6 @@ CODE_SAMPLE
$classMethod = $this->processRemoveParamTypeFromMethod($ancestorOverridableAnonymousClass, $method);
if ($classMethod instanceof ClassMethod) {
$hasChanged = \true;
$this->docBlockUpdater->updateRefactoredNodeWithPhpDocInfo($classMethod);
continue;
}
continue;
@ -135,7 +127,6 @@ CODE_SAMPLE
$classReflection = $this->reflectionResolver->resolveClassAndAnonymousClass($node);
$classMethod = $this->processRemoveParamTypeFromMethod($classReflection, $method);
if ($classMethod instanceof ClassMethod) {
$this->docBlockUpdater->updateRefactoredNodeWithPhpDocInfo($classMethod);
$hasChanged = \true;
}
}

View File

@ -233,6 +233,6 @@ CODE_SAMPLE
$type = $this->staticTypeMapper->mapPhpParserNodePHPStanType($param->type);
$paramName = $this->getName($param->var) ?? '';
$phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($functionLike);
$this->phpDocTypeChanger->changeParamType($phpDocInfo, $type, $param, $paramName);
$this->phpDocTypeChanger->changeParamType($functionLike, $phpDocInfo, $type, $param, $paramName);
}
}

View File

@ -182,7 +182,7 @@ CODE_SAMPLE
/** @var Node $returnType */
$returnType = $classMethod->returnType;
$type = $this->staticTypeMapper->mapPhpParserNodePHPStanType($returnType);
$this->phpDocTypeChanger->changeReturnType($phpDocInfo, $type);
$this->phpDocTypeChanger->changeReturnType($classMethod, $phpDocInfo, $type);
$this->returnTagRemover->removeReturnTagIfUseless($phpDocInfo, $classMethod);
}
/**

View File

@ -204,6 +204,6 @@ CODE_SAMPLE
return;
}
$propertyDocInfo = $this->phpDocInfoFactory->createEmpty($property);
$this->phpDocTypeChanger->changeVarTypeNode($propertyDocInfo, $paramTagValueNode->type);
$this->phpDocTypeChanger->changeVarTypeNode($property, $propertyDocInfo, $paramTagValueNode->type);
}
}

View File

@ -44,6 +44,6 @@ final class PropertyDecorator
return;
}
$newType = $this->staticTypeMapper->mapPhpParserNodePHPStanType($typeNode);
$this->phpDocTypeChanger->changeVarType($phpDocInfo, $newType);
$this->phpDocTypeChanger->changeVarType($property, $phpDocInfo, $newType);
}
}

View File

@ -120,7 +120,7 @@ final class PhpDocFromTypeDeclarationDecorator
$functionLike->returnType = $this->staticTypeMapper->mapPHPStanTypeToPhpParserNode($returnType, TypeKind::RETURN);
return;
}
$this->phpDocTypeChanger->changeReturnType($phpDocInfo, $returnType);
$this->phpDocTypeChanger->changeReturnType($functionLike, $phpDocInfo, $returnType);
$functionLike->returnType = null;
if (!$functionLike instanceof ClassMethod) {
return;
@ -239,7 +239,7 @@ final class PhpDocFromTypeDeclarationDecorator
{
$phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($functionLike);
$paramName = $this->nodeNameResolver->getName($param);
$this->phpDocTypeChanger->changeParamType($phpDocInfo, $type, $param, $paramName);
$this->phpDocTypeChanger->changeParamType($functionLike, $phpDocInfo, $type, $param, $paramName);
$param->type = null;
}
/**

View File

@ -15,7 +15,7 @@
"phpunit\/phpunit": "^10.0",
"rector\/phpstan-rules": "^0.6",
"rector\/rector-generator": "^0.6",
"rector\/rector-src": "dev-main",
"rector\/rector-src": "dev-main#238f451bb852f30a4b43f8da735d920d95162d3f",
"symfony\/routing": "^6.1",
"symfony\/security-core": "^6.2",
"symfony\/security-http": "^6.1",

View File

@ -131,7 +131,7 @@ final class GetSubscribedEventsClassMethodFactory
}
$returnType = new ArrayType(new StringType(), new MixedType(\true));
$phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($classMethod);
$this->phpDocTypeChanger->changeReturnType($phpDocInfo, $returnType);
$this->phpDocTypeChanger->changeReturnType($classMethod, $phpDocInfo, $returnType);
}
/**
* @param ServiceDefinition[] $methodNamesWithPriorities