mirror of
https://github.com/rectorphp/rector.git
synced 2025-01-17 05:18:18 +01:00
Updated Rector to commit 97eb222b6b3954419bc6e22d9640859e97934c4d
97eb222b6b
[DX] Type of class method/class const cannot be checked, use Class_ instead (#6281)
This commit is contained in:
parent
230145ae37
commit
f5ea40a973
@ -7,6 +7,7 @@ use PhpParser\Node;
|
||||
use PhpParser\Node\Expr;
|
||||
use PhpParser\Node\Expr\Array_;
|
||||
use PhpParser\Node\Expr\ArrayItem;
|
||||
use PhpParser\Node\Stmt\Class_;
|
||||
use PhpParser\Node\Stmt\ClassMethod;
|
||||
use PhpParser\Node\Stmt\Return_;
|
||||
use Rector\Contract\Rector\ConfigurableRectorInterface;
|
||||
@ -51,24 +52,31 @@ CODE_SAMPLE
|
||||
*/
|
||||
public function getNodeTypes() : array
|
||||
{
|
||||
return [ClassMethod::class];
|
||||
return [Class_::class];
|
||||
}
|
||||
/**
|
||||
* @param ClassMethod $node
|
||||
* @param Class_ $node
|
||||
*/
|
||||
public function refactor(Node $node) : ?Node
|
||||
{
|
||||
$hasChanged = \false;
|
||||
foreach ($this->typeMethodWraps as $typeMethodWrap) {
|
||||
if (!$this->isName($node, $typeMethodWrap->getMethod())) {
|
||||
continue;
|
||||
}
|
||||
if (!$this->isObjectType($node, $typeMethodWrap->getObjectType())) {
|
||||
continue;
|
||||
}
|
||||
if ($node->stmts === null) {
|
||||
continue;
|
||||
foreach ($node->getMethods() as $classMethod) {
|
||||
if (!$this->isName($classMethod, $typeMethodWrap->getMethod())) {
|
||||
continue;
|
||||
}
|
||||
if ($node->stmts === null) {
|
||||
continue;
|
||||
}
|
||||
$this->wrap($classMethod, $typeMethodWrap->isArrayWrap());
|
||||
$hasChanged = \true;
|
||||
}
|
||||
return $this->wrap($node, $typeMethodWrap->isArrayWrap());
|
||||
}
|
||||
if ($hasChanged) {
|
||||
return $node;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
@ -4,7 +4,8 @@ declare (strict_types=1);
|
||||
namespace Rector\Visibility\Rector\ClassConst;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Stmt\ClassConst;
|
||||
use PhpParser\Node\Stmt\Class_;
|
||||
use PhpParser\Node\Stmt\Interface_;
|
||||
use Rector\Contract\Rector\ConfigurableRectorInterface;
|
||||
use Rector\Privatization\NodeManipulator\VisibilityManipulator;
|
||||
use Rector\Rector\AbstractRector;
|
||||
@ -62,21 +63,27 @@ CODE_SAMPLE
|
||||
*/
|
||||
public function getNodeTypes() : array
|
||||
{
|
||||
return [ClassConst::class];
|
||||
return [Class_::class, Interface_::class];
|
||||
}
|
||||
/**
|
||||
* @param ClassConst $node
|
||||
* @param Class_|Interface_ $node
|
||||
*/
|
||||
public function refactor(Node $node) : ?Node
|
||||
{
|
||||
$hasChanged = \false;
|
||||
foreach ($this->classConstantVisibilityChanges as $classConstantVisibilityChange) {
|
||||
if (!$this->isName($node, $classConstantVisibilityChange->getConstant())) {
|
||||
continue;
|
||||
}
|
||||
if (!$this->isObjectType($node, $classConstantVisibilityChange->getObjectType())) {
|
||||
continue;
|
||||
}
|
||||
$this->visibilityManipulator->changeNodeVisibility($node, $classConstantVisibilityChange->getVisibility());
|
||||
foreach ($node->getConstants() as $classConst) {
|
||||
if (!$this->isName($classConst, $classConstantVisibilityChange->getConstant())) {
|
||||
continue;
|
||||
}
|
||||
$this->visibilityManipulator->changeNodeVisibility($classConst, $classConstantVisibilityChange->getVisibility());
|
||||
$hasChanged = \true;
|
||||
}
|
||||
}
|
||||
if ($hasChanged) {
|
||||
return $node;
|
||||
}
|
||||
return null;
|
||||
|
@ -19,12 +19,12 @@ final class VersionResolver
|
||||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const PACKAGE_VERSION = '13f3067288a5dcf8ef60148620f0a6c92b2132fc';
|
||||
public const PACKAGE_VERSION = '97eb222b6b3954419bc6e22d9640859e97934c4d';
|
||||
/**
|
||||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const RELEASE_DATE = '2024-09-02 12:14:46';
|
||||
public const RELEASE_DATE = '2024-09-02 12:58:19';
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
|
@ -78,7 +78,6 @@ use Rector\NodeTypeResolver\NodeTypeResolver;
|
||||
use Rector\NodeTypeResolver\NodeTypeResolver\CastTypeResolver;
|
||||
use Rector\NodeTypeResolver\NodeTypeResolver\ClassAndInterfaceTypeResolver;
|
||||
use Rector\NodeTypeResolver\NodeTypeResolver\ClassConstFetchTypeResolver;
|
||||
use Rector\NodeTypeResolver\NodeTypeResolver\ClassMethodOrClassConstTypeResolver;
|
||||
use Rector\NodeTypeResolver\NodeTypeResolver\IdentifierTypeResolver;
|
||||
use Rector\NodeTypeResolver\NodeTypeResolver\NameTypeResolver;
|
||||
use Rector\NodeTypeResolver\NodeTypeResolver\NewTypeResolver;
|
||||
@ -225,7 +224,7 @@ final class LazyContainerFactory
|
||||
/**
|
||||
* @var array<class-string<NodeTypeResolverInterface>>
|
||||
*/
|
||||
private const NODE_TYPE_RESOLVER_CLASSES = [CastTypeResolver::class, StaticCallMethodCallTypeResolver::class, ClassAndInterfaceTypeResolver::class, ClassMethodOrClassConstTypeResolver::class, IdentifierTypeResolver::class, NameTypeResolver::class, NewTypeResolver::class, ParamTypeResolver::class, PropertyFetchTypeResolver::class, ClassConstFetchTypeResolver::class, PropertyTypeResolver::class, ScalarTypeResolver::class, TraitTypeResolver::class];
|
||||
private const NODE_TYPE_RESOLVER_CLASSES = [CastTypeResolver::class, StaticCallMethodCallTypeResolver::class, ClassAndInterfaceTypeResolver::class, IdentifierTypeResolver::class, NameTypeResolver::class, NewTypeResolver::class, ParamTypeResolver::class, PropertyFetchTypeResolver::class, ClassConstFetchTypeResolver::class, PropertyTypeResolver::class, ScalarTypeResolver::class, TraitTypeResolver::class];
|
||||
/**
|
||||
* @var array<class-string<PhpParserNodeMapperInterface>>
|
||||
*/
|
||||
|
@ -15,6 +15,8 @@ use PhpParser\Node\Expr\StaticCall;
|
||||
use PhpParser\Node\Expr\Ternary;
|
||||
use PhpParser\Node\NullableType;
|
||||
use PhpParser\Node\Scalar\String_;
|
||||
use PhpParser\Node\Stmt\ClassConst;
|
||||
use PhpParser\Node\Stmt\ClassMethod;
|
||||
use PhpParser\Node\UnionType as NodeUnionType;
|
||||
use PHPStan\Analyser\Scope;
|
||||
use PHPStan\Broker\ClassAutoloadingException;
|
||||
@ -35,6 +37,7 @@ use PHPStan\Type\TypeCombinator;
|
||||
use PHPStan\Type\TypeWithClassName;
|
||||
use PHPStan\Type\UnionType;
|
||||
use Rector\Configuration\RenamedClassesDataCollector;
|
||||
use Rector\Exception\ShouldNotHappenException;
|
||||
use Rector\NodeAnalyzer\ClassAnalyzer;
|
||||
use Rector\NodeTypeResolver\Contract\NodeTypeResolverAwareInterface;
|
||||
use Rector\NodeTypeResolver\Contract\NodeTypeResolverInterface;
|
||||
@ -119,6 +122,13 @@ final class NodeTypeResolver
|
||||
if ($node instanceof ClassConstFetch) {
|
||||
return \false;
|
||||
}
|
||||
// warn about invalid use of this method
|
||||
if ($node instanceof ClassMethod) {
|
||||
throw new ShouldNotHappenException('ClassMethod itself does not have any type. Check the Class_/Interface/Trait_ node instead');
|
||||
}
|
||||
if ($node instanceof ClassConst) {
|
||||
throw new ShouldNotHappenException('Class constant itself does not have any type. Check the Class_/Trait_ instead');
|
||||
}
|
||||
$resolvedType = $this->getType($node);
|
||||
if ($resolvedType instanceof MixedType) {
|
||||
return \false;
|
||||
|
@ -1,45 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace Rector\NodeTypeResolver\NodeTypeResolver;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Stmt\ClassConst;
|
||||
use PhpParser\Node\Stmt\ClassMethod;
|
||||
use PHPStan\Analyser\Scope;
|
||||
use PHPStan\Reflection\ClassReflection;
|
||||
use PHPStan\Type\ObjectType;
|
||||
use PHPStan\Type\ObjectWithoutClassType;
|
||||
use PHPStan\Type\Type;
|
||||
use Rector\NodeTypeResolver\Contract\NodeTypeResolverInterface;
|
||||
use Rector\NodeTypeResolver\Node\AttributeKey;
|
||||
/**
|
||||
* @implements NodeTypeResolverInterface<ClassMethod|ClassConst>
|
||||
*/
|
||||
final class ClassMethodOrClassConstTypeResolver implements NodeTypeResolverInterface
|
||||
{
|
||||
/**
|
||||
* @return array<class-string<Node>>
|
||||
*/
|
||||
public function getNodeClasses() : array
|
||||
{
|
||||
return [ClassMethod::class, ClassConst::class];
|
||||
}
|
||||
/**
|
||||
* @param ClassMethod|ClassConst $node
|
||||
*/
|
||||
public function resolve(Node $node) : Type
|
||||
{
|
||||
$scope = $node->getAttribute(AttributeKey::SCOPE);
|
||||
if (!$scope instanceof Scope) {
|
||||
// anonymous class
|
||||
return new ObjectWithoutClassType();
|
||||
}
|
||||
$classReflection = $scope->getClassReflection();
|
||||
if (!$classReflection instanceof ClassReflection || $classReflection->isAnonymous()) {
|
||||
// anonymous class
|
||||
return new ObjectWithoutClassType();
|
||||
}
|
||||
return new ObjectType($classReflection->getName());
|
||||
}
|
||||
}
|
1
vendor/composer/autoload_classmap.php
vendored
1
vendor/composer/autoload_classmap.php
vendored
@ -1641,7 +1641,6 @@ return array(
|
||||
'Rector\\NodeTypeResolver\\NodeTypeResolver\\CastTypeResolver' => $baseDir . '/src/NodeTypeResolver/NodeTypeResolver/CastTypeResolver.php',
|
||||
'Rector\\NodeTypeResolver\\NodeTypeResolver\\ClassAndInterfaceTypeResolver' => $baseDir . '/src/NodeTypeResolver/NodeTypeResolver/ClassAndInterfaceTypeResolver.php',
|
||||
'Rector\\NodeTypeResolver\\NodeTypeResolver\\ClassConstFetchTypeResolver' => $baseDir . '/src/NodeTypeResolver/NodeTypeResolver/ClassConstFetchTypeResolver.php',
|
||||
'Rector\\NodeTypeResolver\\NodeTypeResolver\\ClassMethodOrClassConstTypeResolver' => $baseDir . '/src/NodeTypeResolver/NodeTypeResolver/ClassMethodOrClassConstTypeResolver.php',
|
||||
'Rector\\NodeTypeResolver\\NodeTypeResolver\\IdentifierTypeResolver' => $baseDir . '/src/NodeTypeResolver/NodeTypeResolver/IdentifierTypeResolver.php',
|
||||
'Rector\\NodeTypeResolver\\NodeTypeResolver\\NameTypeResolver' => $baseDir . '/src/NodeTypeResolver/NodeTypeResolver/NameTypeResolver.php',
|
||||
'Rector\\NodeTypeResolver\\NodeTypeResolver\\NewTypeResolver' => $baseDir . '/src/NodeTypeResolver/NodeTypeResolver/NewTypeResolver.php',
|
||||
|
1
vendor/composer/autoload_static.php
vendored
1
vendor/composer/autoload_static.php
vendored
@ -1860,7 +1860,6 @@ class ComposerStaticInitf022c0913f90a8ce8e0872b4624f9c82
|
||||
'Rector\\NodeTypeResolver\\NodeTypeResolver\\CastTypeResolver' => __DIR__ . '/../..' . '/src/NodeTypeResolver/NodeTypeResolver/CastTypeResolver.php',
|
||||
'Rector\\NodeTypeResolver\\NodeTypeResolver\\ClassAndInterfaceTypeResolver' => __DIR__ . '/../..' . '/src/NodeTypeResolver/NodeTypeResolver/ClassAndInterfaceTypeResolver.php',
|
||||
'Rector\\NodeTypeResolver\\NodeTypeResolver\\ClassConstFetchTypeResolver' => __DIR__ . '/../..' . '/src/NodeTypeResolver/NodeTypeResolver/ClassConstFetchTypeResolver.php',
|
||||
'Rector\\NodeTypeResolver\\NodeTypeResolver\\ClassMethodOrClassConstTypeResolver' => __DIR__ . '/../..' . '/src/NodeTypeResolver/NodeTypeResolver/ClassMethodOrClassConstTypeResolver.php',
|
||||
'Rector\\NodeTypeResolver\\NodeTypeResolver\\IdentifierTypeResolver' => __DIR__ . '/../..' . '/src/NodeTypeResolver/NodeTypeResolver/IdentifierTypeResolver.php',
|
||||
'Rector\\NodeTypeResolver\\NodeTypeResolver\\NameTypeResolver' => __DIR__ . '/../..' . '/src/NodeTypeResolver/NodeTypeResolver/NameTypeResolver.php',
|
||||
'Rector\\NodeTypeResolver\\NodeTypeResolver\\NewTypeResolver' => __DIR__ . '/../..' . '/src/NodeTypeResolver/NodeTypeResolver/NewTypeResolver.php',
|
||||
|
8
vendor/composer/installed.json
vendored
8
vendor/composer/installed.json
vendored
@ -1876,12 +1876,12 @@
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https:\/\/github.com\/rectorphp\/rector-symfony.git",
|
||||
"reference": "d7cc42e17c272184d6dfcfa699e2f16285bb5392"
|
||||
"reference": "49e82cc11057193c840821d8602c1144869b9c8a"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-symfony\/zipball\/d7cc42e17c272184d6dfcfa699e2f16285bb5392",
|
||||
"reference": "d7cc42e17c272184d6dfcfa699e2f16285bb5392",
|
||||
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-symfony\/zipball\/49e82cc11057193c840821d8602c1144869b9c8a",
|
||||
"reference": "49e82cc11057193c840821d8602c1144869b9c8a",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
@ -1911,7 +1911,7 @@
|
||||
"tomasvotruba\/unused-public": "^0.3.10",
|
||||
"tracy\/tracy": "^2.10"
|
||||
},
|
||||
"time": "2024-08-20T12:50:29+00:00",
|
||||
"time": "2024-09-02T10:41:34+00:00",
|
||||
"default-branch": true,
|
||||
"type": "rector-extension",
|
||||
"extra": {
|
||||
|
2
vendor/composer/installed.php
vendored
2
vendor/composer/installed.php
vendored
File diff suppressed because one or more lines are too long
@ -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/rector-build/vendor/rector/rector-doctrine', 'relative_install_path' => '../../rector-doctrine', 'extra' => NULL, 'version' => 'dev-main fb26209'), 'rector/rector-downgrade-php' => array('install_path' => '/home/runner/work/rector-src/rector-src/rector-build/vendor/rector/rector-downgrade-php', 'relative_install_path' => '../../rector-downgrade-php', 'extra' => NULL, 'version' => 'dev-main cfebdb1'), 'rector/rector-phpunit' => array('install_path' => '/home/runner/work/rector-src/rector-src/rector-build/vendor/rector/rector-phpunit', 'relative_install_path' => '../../rector-phpunit', 'extra' => NULL, 'version' => 'dev-main 93a04b0'), 'rector/rector-symfony' => array('install_path' => '/home/runner/work/rector-src/rector-src/rector-build/vendor/rector/rector-symfony', 'relative_install_path' => '../../rector-symfony', 'extra' => NULL, 'version' => 'dev-main d7cc42e'));
|
||||
public const EXTENSIONS = array('rector/rector-doctrine' => array('install_path' => '/home/runner/work/rector-src/rector-src/rector-build/vendor/rector/rector-doctrine', 'relative_install_path' => '../../rector-doctrine', 'extra' => NULL, 'version' => 'dev-main fb26209'), 'rector/rector-downgrade-php' => array('install_path' => '/home/runner/work/rector-src/rector-src/rector-build/vendor/rector/rector-downgrade-php', 'relative_install_path' => '../../rector-downgrade-php', 'extra' => NULL, 'version' => 'dev-main cfebdb1'), 'rector/rector-phpunit' => array('install_path' => '/home/runner/work/rector-src/rector-src/rector-build/vendor/rector/rector-phpunit', 'relative_install_path' => '../../rector-phpunit', 'extra' => NULL, 'version' => 'dev-main 93a04b0'), 'rector/rector-symfony' => array('install_path' => '/home/runner/work/rector-src/rector-src/rector-build/vendor/rector/rector-symfony', 'relative_install_path' => '../../rector-symfony', 'extra' => NULL, 'version' => 'dev-main 49e82cc'));
|
||||
private function __construct()
|
||||
{
|
||||
}
|
||||
|
@ -10,7 +10,6 @@ use PhpParser\Node\Expr\New_;
|
||||
use PhpParser\Node\Expr\Variable;
|
||||
use PhpParser\Node\Identifier;
|
||||
use PhpParser\Node\Name\FullyQualified;
|
||||
use PhpParser\Node\NullableType;
|
||||
use PhpParser\Node\Stmt\ClassMethod;
|
||||
use PhpParser\Node\Stmt\Return_;
|
||||
use PHPStan\Type\ObjectType;
|
||||
|
@ -118,7 +118,7 @@ CODE_SAMPLE
|
||||
return $this->isObjectType($class, new ObjectType('Symfony\\Component\\Form\\AbstractType'));
|
||||
}
|
||||
if ($this->isName($classMethod->name, 'getExtendedType')) {
|
||||
return $this->isObjectType($classMethod, new ObjectType('Symfony\\Component\\Form\\AbstractTypeExtension'));
|
||||
return $this->isObjectType($class, new ObjectType('Symfony\\Component\\Form\\AbstractTypeExtension'));
|
||||
}
|
||||
return \false;
|
||||
}
|
||||
|
@ -134,6 +134,9 @@ CODE_SAMPLE
|
||||
}
|
||||
private function isReturnIntegerType(?Expr $expr) : bool
|
||||
{
|
||||
if ($expr instanceof Int_) {
|
||||
return \true;
|
||||
}
|
||||
if ($expr instanceof Expr) {
|
||||
$returnedType = $this->getType($expr);
|
||||
if ($returnedType instanceof IntegerType) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user