mirror of
https://github.com/rectorphp/rector.git
synced 2025-04-21 16:02:23 +02:00
Updated Rector to commit 1aff76b12e87cf836f9cbbaee9fc030355b162ac
1aff76b12e
[Php80] Skip case after default empty on ChangeSwitchToMatchRector (#6805)
This commit is contained in:
parent
d9d4a08c8a
commit
59ca5ad3cd
2
vendor/composer/autoload_classmap.php
vendored
2
vendor/composer/autoload_classmap.php
vendored
@ -1403,7 +1403,6 @@ return array(
|
||||
'Rector\\Doctrine\\CodeQuality\\Rector\\Class_\\YamlToAttributeDoctrineMappingRector' => $vendorDir . '/rector/rector-doctrine/rules/CodeQuality/Rector/Class_/YamlToAttributeDoctrineMappingRector.php',
|
||||
'Rector\\Doctrine\\CodeQuality\\Rector\\Property\\CorrectDefaultTypesOnEntityPropertyRector' => $vendorDir . '/rector/rector-doctrine/rules/CodeQuality/Rector/Property/CorrectDefaultTypesOnEntityPropertyRector.php',
|
||||
'Rector\\Doctrine\\CodeQuality\\Rector\\Property\\ImproveDoctrineCollectionDocTypeInEntityRector' => $vendorDir . '/rector/rector-doctrine/rules/CodeQuality/Rector/Property/ImproveDoctrineCollectionDocTypeInEntityRector.php',
|
||||
'Rector\\Doctrine\\CodeQuality\\Rector\\Property\\MakeEntityDateTimePropertyDateTimeInterfaceRector' => $vendorDir . '/rector/rector-doctrine/rules/CodeQuality/Rector/Property/MakeEntityDateTimePropertyDateTimeInterfaceRector.php',
|
||||
'Rector\\Doctrine\\CodeQuality\\Rector\\Property\\TypedPropertyFromColumnTypeRector' => $vendorDir . '/rector/rector-doctrine/rules/CodeQuality/Rector/Property/TypedPropertyFromColumnTypeRector.php',
|
||||
'Rector\\Doctrine\\CodeQuality\\Rector\\Property\\TypedPropertyFromToManyRelationTypeRector' => $vendorDir . '/rector/rector-doctrine/rules/CodeQuality/Rector/Property/TypedPropertyFromToManyRelationTypeRector.php',
|
||||
'Rector\\Doctrine\\CodeQuality\\Rector\\Property\\TypedPropertyFromToOneRelationTypeRector' => $vendorDir . '/rector/rector-doctrine/rules/CodeQuality/Rector/Property/TypedPropertyFromToOneRelationTypeRector.php',
|
||||
@ -2241,6 +2240,7 @@ return array(
|
||||
'Rector\\Symfony\\BundleClassResolver' => $vendorDir . '/rector/rector-symfony/src/BundleClassResolver.php',
|
||||
'Rector\\Symfony\\CodeQuality\\Enum\\ResponseClass' => $vendorDir . '/rector/rector-symfony/rules/CodeQuality/Enum/ResponseClass.php',
|
||||
'Rector\\Symfony\\CodeQuality\\NodeFactory\\SymfonyClosureFactory' => $vendorDir . '/rector/rector-symfony/rules/CodeQuality/NodeFactory/SymfonyClosureFactory.php',
|
||||
'Rector\\Symfony\\CodeQuality\\Rector\\BinaryOp\\RequestIsMainRector' => $vendorDir . '/rector/rector-symfony/rules/CodeQuality/Rector/BinaryOp/RequestIsMainRector.php',
|
||||
'Rector\\Symfony\\CodeQuality\\Rector\\BinaryOp\\ResponseStatusCodeRector' => $vendorDir . '/rector/rector-symfony/rules/CodeQuality/Rector/BinaryOp/ResponseStatusCodeRector.php',
|
||||
'Rector\\Symfony\\CodeQuality\\Rector\\ClassMethod\\ActionSuffixRemoverRector' => $vendorDir . '/rector/rector-symfony/rules/CodeQuality/Rector/ClassMethod/ActionSuffixRemoverRector.php',
|
||||
'Rector\\Symfony\\CodeQuality\\Rector\\ClassMethod\\ParamTypeFromRouteRequiredRegexRector' => $vendorDir . '/rector/rector-symfony/rules/CodeQuality/Rector/ClassMethod/ParamTypeFromRouteRequiredRegexRector.php',
|
||||
|
2
vendor/composer/autoload_static.php
vendored
2
vendor/composer/autoload_static.php
vendored
@ -1622,7 +1622,6 @@ class ComposerStaticInit463a5eb4f43b9fdf649399cc7beca233
|
||||
'Rector\\Doctrine\\CodeQuality\\Rector\\Class_\\YamlToAttributeDoctrineMappingRector' => __DIR__ . '/..' . '/rector/rector-doctrine/rules/CodeQuality/Rector/Class_/YamlToAttributeDoctrineMappingRector.php',
|
||||
'Rector\\Doctrine\\CodeQuality\\Rector\\Property\\CorrectDefaultTypesOnEntityPropertyRector' => __DIR__ . '/..' . '/rector/rector-doctrine/rules/CodeQuality/Rector/Property/CorrectDefaultTypesOnEntityPropertyRector.php',
|
||||
'Rector\\Doctrine\\CodeQuality\\Rector\\Property\\ImproveDoctrineCollectionDocTypeInEntityRector' => __DIR__ . '/..' . '/rector/rector-doctrine/rules/CodeQuality/Rector/Property/ImproveDoctrineCollectionDocTypeInEntityRector.php',
|
||||
'Rector\\Doctrine\\CodeQuality\\Rector\\Property\\MakeEntityDateTimePropertyDateTimeInterfaceRector' => __DIR__ . '/..' . '/rector/rector-doctrine/rules/CodeQuality/Rector/Property/MakeEntityDateTimePropertyDateTimeInterfaceRector.php',
|
||||
'Rector\\Doctrine\\CodeQuality\\Rector\\Property\\TypedPropertyFromColumnTypeRector' => __DIR__ . '/..' . '/rector/rector-doctrine/rules/CodeQuality/Rector/Property/TypedPropertyFromColumnTypeRector.php',
|
||||
'Rector\\Doctrine\\CodeQuality\\Rector\\Property\\TypedPropertyFromToManyRelationTypeRector' => __DIR__ . '/..' . '/rector/rector-doctrine/rules/CodeQuality/Rector/Property/TypedPropertyFromToManyRelationTypeRector.php',
|
||||
'Rector\\Doctrine\\CodeQuality\\Rector\\Property\\TypedPropertyFromToOneRelationTypeRector' => __DIR__ . '/..' . '/rector/rector-doctrine/rules/CodeQuality/Rector/Property/TypedPropertyFromToOneRelationTypeRector.php',
|
||||
@ -2460,6 +2459,7 @@ class ComposerStaticInit463a5eb4f43b9fdf649399cc7beca233
|
||||
'Rector\\Symfony\\BundleClassResolver' => __DIR__ . '/..' . '/rector/rector-symfony/src/BundleClassResolver.php',
|
||||
'Rector\\Symfony\\CodeQuality\\Enum\\ResponseClass' => __DIR__ . '/..' . '/rector/rector-symfony/rules/CodeQuality/Enum/ResponseClass.php',
|
||||
'Rector\\Symfony\\CodeQuality\\NodeFactory\\SymfonyClosureFactory' => __DIR__ . '/..' . '/rector/rector-symfony/rules/CodeQuality/NodeFactory/SymfonyClosureFactory.php',
|
||||
'Rector\\Symfony\\CodeQuality\\Rector\\BinaryOp\\RequestIsMainRector' => __DIR__ . '/..' . '/rector/rector-symfony/rules/CodeQuality/Rector/BinaryOp/RequestIsMainRector.php',
|
||||
'Rector\\Symfony\\CodeQuality\\Rector\\BinaryOp\\ResponseStatusCodeRector' => __DIR__ . '/..' . '/rector/rector-symfony/rules/CodeQuality/Rector/BinaryOp/ResponseStatusCodeRector.php',
|
||||
'Rector\\Symfony\\CodeQuality\\Rector\\ClassMethod\\ActionSuffixRemoverRector' => __DIR__ . '/..' . '/rector/rector-symfony/rules/CodeQuality/Rector/ClassMethod/ActionSuffixRemoverRector.php',
|
||||
'Rector\\Symfony\\CodeQuality\\Rector\\ClassMethod\\ParamTypeFromRouteRequiredRegexRector' => __DIR__ . '/..' . '/rector/rector-symfony/rules/CodeQuality/Rector/ClassMethod/ParamTypeFromRouteRequiredRegexRector.php',
|
||||
|
16
vendor/composer/installed.json
vendored
16
vendor/composer/installed.json
vendored
@ -1687,12 +1687,12 @@
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https:\/\/github.com\/rectorphp\/rector-doctrine.git",
|
||||
"reference": "1da0aa0cbb301491186a6f8e447d3d8d48387a02"
|
||||
"reference": "105ae614b20c6d5e536e45ad41c49e57c80fba5d"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-doctrine\/zipball\/1da0aa0cbb301491186a6f8e447d3d8d48387a02",
|
||||
"reference": "1da0aa0cbb301491186a6f8e447d3d8d48387a02",
|
||||
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-doctrine\/zipball\/105ae614b20c6d5e536e45ad41c49e57c80fba5d",
|
||||
"reference": "105ae614b20c6d5e536e45ad41c49e57c80fba5d",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
@ -1715,7 +1715,7 @@
|
||||
"tomasvotruba\/class-leak": "^2.0",
|
||||
"tracy\/tracy": "^2.10"
|
||||
},
|
||||
"time": "2025-03-16T14:47:31+00:00",
|
||||
"time": "2025-03-23T23:33:29+00:00",
|
||||
"default-branch": true,
|
||||
"type": "rector-extension",
|
||||
"extra": {
|
||||
@ -1864,12 +1864,12 @@
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https:\/\/github.com\/rectorphp\/rector-symfony.git",
|
||||
"reference": "00c1f259413b81b5075df372d56446f3e41d7891"
|
||||
"reference": "900dcbf2838a6524acabf3b3640c49469bc8daec"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-symfony\/zipball\/00c1f259413b81b5075df372d56446f3e41d7891",
|
||||
"reference": "00c1f259413b81b5075df372d56446f3e41d7891",
|
||||
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-symfony\/zipball\/900dcbf2838a6524acabf3b3640c49469bc8daec",
|
||||
"reference": "900dcbf2838a6524acabf3b3640c49469bc8daec",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
@ -1897,7 +1897,7 @@
|
||||
"tomasvotruba\/unused-public": "^2.0",
|
||||
"tracy\/tracy": "^2.10"
|
||||
},
|
||||
"time": "2025-03-21T10:27:25+00:00",
|
||||
"time": "2025-03-24T14:14:08+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 1da0aa0'), '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 b55c3bc'), '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 3158fa9'), '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 00c1f25'));
|
||||
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 105ae61'), '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 b55c3bc'), '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 3158fa9'), '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 900dcbf'));
|
||||
private function __construct()
|
||||
{
|
||||
}
|
||||
|
@ -3,6 +3,12 @@
|
||||
declare (strict_types=1);
|
||||
namespace Rector\Doctrine\Bundle230\Rector\Class_;
|
||||
|
||||
use PhpParser\Node\Name;
|
||||
use PhpParser\Node\Stmt\ClassMethod;
|
||||
use PhpParser\Node\Stmt\Expression;
|
||||
use PhpParser\Node\Expr\StaticCall;
|
||||
use PhpParser\Node\Identifier;
|
||||
use PhpParser\Node\Arg;
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Expr\ClassConstFetch;
|
||||
use PhpParser\Node\Stmt\Class_;
|
||||
@ -19,7 +25,13 @@ use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
*/
|
||||
final class AddAnnotationToRepositoryRector extends AbstractRector
|
||||
{
|
||||
/**
|
||||
* @readonly
|
||||
*/
|
||||
private DocBlockUpdater $docBlockUpdater;
|
||||
/**
|
||||
* @readonly
|
||||
*/
|
||||
private PhpDocInfoFactory $phpDocInfoFactory;
|
||||
public function __construct(DocBlockUpdater $docBlockUpdater, PhpDocInfoFactory $phpDocInfoFactory)
|
||||
{
|
||||
@ -73,7 +85,7 @@ CODE_SAMPLE
|
||||
}
|
||||
private function isRepositoryClass(Class_ $class) : bool
|
||||
{
|
||||
if ($class->extends instanceof Node\Name) {
|
||||
if ($class->extends instanceof Name) {
|
||||
return $this->getName($class->extends) === 'Doctrine\\Bundle\\DoctrineBundle\\Repository\\ServiceEntityRepository';
|
||||
}
|
||||
return \false;
|
||||
@ -81,15 +93,15 @@ CODE_SAMPLE
|
||||
private function getEntityClassFromConstructor(Class_ $class) : ?string
|
||||
{
|
||||
$method = $class->getMethod(MethodName::CONSTRUCT);
|
||||
if ($method === null || $method->stmts === null) {
|
||||
if (!$method instanceof ClassMethod || $method->stmts === null) {
|
||||
return null;
|
||||
}
|
||||
foreach ($method->stmts as $stmt) {
|
||||
if (!$stmt instanceof Node\Stmt\Expression) {
|
||||
if (!$stmt instanceof Expression) {
|
||||
continue;
|
||||
}
|
||||
$expr = $stmt->expr;
|
||||
if (!$expr instanceof Node\Expr\StaticCall) {
|
||||
if (!$expr instanceof StaticCall) {
|
||||
continue;
|
||||
}
|
||||
if (!$this->isParentConstructorCall($expr)) {
|
||||
@ -100,7 +112,7 @@ CODE_SAMPLE
|
||||
continue;
|
||||
}
|
||||
$entityClass = $entityClassNode->class;
|
||||
return $entityClass instanceof Node\Name ? $entityClass->toString() : null;
|
||||
return $entityClass instanceof Name ? $entityClass->toString() : null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@ -115,8 +127,8 @@ CODE_SAMPLE
|
||||
{
|
||||
return $this->phpDocInfoFactory->createFromNodeOrEmpty($class)->hasByName('@extends');
|
||||
}
|
||||
private function isParentConstructorCall(Node\Expr\StaticCall $expr) : bool
|
||||
private function isParentConstructorCall(StaticCall $staticCall) : bool
|
||||
{
|
||||
return $expr->class instanceof Node\Name && $expr->class->toString() === 'parent' && $expr->name instanceof Node\Identifier && $expr->name->toString() === '__construct' && isset($expr->args[1]) && $expr->args[1] instanceof Node\Arg && $expr->args[1]->value instanceof ClassConstFetch;
|
||||
return $staticCall->class instanceof Name && $staticCall->class->toString() === 'parent' && $staticCall->name instanceof Identifier && $staticCall->name->toString() === '__construct' && isset($staticCall->args[1]) && $staticCall->args[1] instanceof Arg && $staticCall->args[1]->value instanceof ClassConstFetch;
|
||||
}
|
||||
}
|
||||
|
@ -1,143 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace Rector\Doctrine\CodeQuality\Rector\Property;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Stmt\Class_;
|
||||
use PhpParser\Node\Stmt\Property;
|
||||
use PHPStan\Type\ObjectType;
|
||||
use PHPStan\Type\TypeCombinator;
|
||||
use PHPStan\Type\UnionType;
|
||||
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfo;
|
||||
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory;
|
||||
use Rector\Comments\NodeDocBlock\DocBlockUpdater;
|
||||
use Rector\Configuration\Deprecation\Contract\DeprecatedInterface;
|
||||
use Rector\Doctrine\NodeAnalyzer\DoctrineEntityDetector;
|
||||
use Rector\NodeTypeResolver\PhpDoc\NodeAnalyzer\DocBlockClassRenamer;
|
||||
use Rector\NodeTypeResolver\ValueObject\OldToNewType;
|
||||
use Rector\Rector\AbstractRector;
|
||||
use Rector\StaticTypeMapper\ValueObject\Type\FullyQualifiedObjectType;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
/**
|
||||
* @see related to maker bundle https://symfony.com/doc/current/bundles/SymfonyMakerBundle/index.html
|
||||
*
|
||||
* @see \Rector\Doctrine\Tests\CodeQuality\Rector\Property\MakeEntityDateTimePropertyDateTimeInterfaceRector\MakeEntityDateTimePropertyDateTimeInterfaceRectorTest
|
||||
*
|
||||
* @deprecated see https://github.com/rectorphp/rector-doctrine/issues/356 for reasoning
|
||||
*/
|
||||
final class MakeEntityDateTimePropertyDateTimeInterfaceRector extends AbstractRector implements DeprecatedInterface
|
||||
{
|
||||
/**
|
||||
* @readonly
|
||||
*/
|
||||
private DocBlockClassRenamer $docBlockClassRenamer;
|
||||
/**
|
||||
* @readonly
|
||||
*/
|
||||
private DocBlockUpdater $docBlockUpdater;
|
||||
/**
|
||||
* @readonly
|
||||
*/
|
||||
private PhpDocInfoFactory $phpDocInfoFactory;
|
||||
/**
|
||||
* @readonly
|
||||
*/
|
||||
private DoctrineEntityDetector $doctrineEntityDetector;
|
||||
public function __construct(DocBlockClassRenamer $docBlockClassRenamer, DocBlockUpdater $docBlockUpdater, PhpDocInfoFactory $phpDocInfoFactory, DoctrineEntityDetector $doctrineEntityDetector)
|
||||
{
|
||||
$this->docBlockClassRenamer = $docBlockClassRenamer;
|
||||
$this->docBlockUpdater = $docBlockUpdater;
|
||||
$this->phpDocInfoFactory = $phpDocInfoFactory;
|
||||
$this->doctrineEntityDetector = $doctrineEntityDetector;
|
||||
}
|
||||
public function getRuleDefinition() : RuleDefinition
|
||||
{
|
||||
return new RuleDefinition('Make maker bundle generate DateTime property accept DateTimeInterface too', [new CodeSample(<<<'CODE_SAMPLE'
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
/**
|
||||
* @ORM\Entity()
|
||||
*/
|
||||
class User
|
||||
{
|
||||
/**
|
||||
* @var DateTime|null
|
||||
*/
|
||||
private $bornAt;
|
||||
|
||||
public function setBornAt(DateTimeInterface $bornAt)
|
||||
{
|
||||
$this->bornAt = $bornAt;
|
||||
}
|
||||
}
|
||||
CODE_SAMPLE
|
||||
, <<<'CODE_SAMPLE'
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
/**
|
||||
* @ORM\Entity()
|
||||
*/
|
||||
class User
|
||||
{
|
||||
/**
|
||||
* @var DateTimeInterface|null
|
||||
*/
|
||||
private $bornAt;
|
||||
|
||||
public function setBornAt(DateTimeInterface $bornAt)
|
||||
{
|
||||
$this->bornAt = $bornAt;
|
||||
}
|
||||
}
|
||||
CODE_SAMPLE
|
||||
)]);
|
||||
}
|
||||
/**
|
||||
* @return array<class-string<Node>>
|
||||
*/
|
||||
public function getNodeTypes() : array
|
||||
{
|
||||
return [Class_::class];
|
||||
}
|
||||
/**
|
||||
* @param Class_ $node
|
||||
*/
|
||||
public function refactor(Node $node) : ?Node
|
||||
{
|
||||
if (!$this->doctrineEntityDetector->detect($node)) {
|
||||
return null;
|
||||
}
|
||||
$hasChanged = \false;
|
||||
foreach ($node->getProperties() as $property) {
|
||||
$phpDocInfo = $this->phpDocInfoFactory->createFromNode($property);
|
||||
if (!$phpDocInfo instanceof PhpDocInfo) {
|
||||
continue;
|
||||
}
|
||||
$varType = $phpDocInfo->getVarType();
|
||||
if ($varType instanceof UnionType) {
|
||||
$varType = TypeCombinator::removeNull($varType);
|
||||
}
|
||||
if (!$varType->equals(new ObjectType('DateTime'))) {
|
||||
continue;
|
||||
}
|
||||
$this->changePropertyType($property, 'DateTime', 'DateTimeInterface');
|
||||
$hasChanged = \true;
|
||||
}
|
||||
if ($hasChanged) {
|
||||
return $node;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
private function changePropertyType(Property $property, string $oldClass, string $newClass) : void
|
||||
{
|
||||
$phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($property);
|
||||
$oldToNewTypes = [new OldToNewType(new FullyQualifiedObjectType($oldClass), new FullyQualifiedObjectType($newClass))];
|
||||
$hasChanged = $this->docBlockClassRenamer->renamePhpDocType($phpDocInfo, $oldToNewTypes, $property);
|
||||
if (!$hasChanged) {
|
||||
return;
|
||||
}
|
||||
$this->docBlockUpdater->updateRefactoredNodeWithPhpDocInfo($property);
|
||||
}
|
||||
}
|
@ -7,6 +7,9 @@ use PhpParser\Node\Name;
|
||||
use PhpParser\Node\Stmt\Class_;
|
||||
use PHPStan\Reflection\ReflectionProvider;
|
||||
use Rector\NodeAnalyzer\DoctrineEntityAnalyzer;
|
||||
/**
|
||||
* @api Part of external API
|
||||
*/
|
||||
final class DoctrineEntityDetector
|
||||
{
|
||||
/**
|
||||
|
@ -4,6 +4,7 @@ declare (strict_types=1);
|
||||
namespace RectorPrefix202503;
|
||||
|
||||
use Rector\Config\RectorConfig;
|
||||
use Rector\Symfony\CodeQuality\Rector\BinaryOp\RequestIsMainRector;
|
||||
use Rector\Symfony\CodeQuality\Rector\BinaryOp\ResponseStatusCodeRector;
|
||||
use Rector\Symfony\CodeQuality\Rector\Class_\EventListenerToEventSubscriberRector;
|
||||
use Rector\Symfony\CodeQuality\Rector\Class_\InlineClassRoutePrefixRector;
|
||||
@ -27,6 +28,8 @@ return static function (RectorConfig $rectorConfig) : void {
|
||||
ParamTypeFromRouteRequiredRegexRector::class,
|
||||
ActionSuffixRemoverRector::class,
|
||||
LoadValidatorMetadataToAnnotationRector::class,
|
||||
// request method
|
||||
RequestIsMainRector::class,
|
||||
// tests
|
||||
AssertSameResponseCodeWithDebugContentsRector::class,
|
||||
// routing
|
||||
|
101
vendor/rector/rector-symfony/rules/CodeQuality/Rector/BinaryOp/RequestIsMainRector.php
vendored
Normal file
101
vendor/rector/rector-symfony/rules/CodeQuality/Rector/BinaryOp/RequestIsMainRector.php
vendored
Normal file
@ -0,0 +1,101 @@
|
||||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace Rector\Symfony\CodeQuality\Rector\BinaryOp;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Expr;
|
||||
use PhpParser\Node\Expr\BinaryOp;
|
||||
use PhpParser\Node\Expr\ClassConstFetch;
|
||||
use PhpParser\Node\Expr\MethodCall;
|
||||
use PHPStan\Reflection\ReflectionProvider;
|
||||
use PHPStan\Type\ObjectType;
|
||||
use Rector\Rector\AbstractRector;
|
||||
use Rector\Symfony\Enum\SymfonyClass;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
/**
|
||||
* @see \Rector\Symfony\Tests\CodeQuality\Rector\BinaryOp\RequestIsMainRector\RequestIsMainRectorTest
|
||||
*/
|
||||
final class RequestIsMainRector extends AbstractRector
|
||||
{
|
||||
/**
|
||||
* @readonly
|
||||
*/
|
||||
private ReflectionProvider $reflectionProvider;
|
||||
public function __construct(ReflectionProvider $reflectionProvider)
|
||||
{
|
||||
$this->reflectionProvider = $reflectionProvider;
|
||||
}
|
||||
public function getRuleDefinition() : RuleDefinition
|
||||
{
|
||||
return new RuleDefinition('Turns status code numbers to constants', [new CodeSample(<<<'CODE_SAMPLE'
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpKernel\HttpKernel;
|
||||
|
||||
class SomeController
|
||||
{
|
||||
public function index(Request $request): bool
|
||||
{
|
||||
return $request->getRequestType() === HttpKernel::MASTER_REQUEST;
|
||||
}
|
||||
}
|
||||
CODE_SAMPLE
|
||||
, <<<'CODE_SAMPLE'
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpKernel\HttpKernel;
|
||||
|
||||
class SomeController
|
||||
{
|
||||
public function index(Request $request): bool
|
||||
{
|
||||
return $request->isMasterRequestType();
|
||||
}
|
||||
}
|
||||
CODE_SAMPLE
|
||||
)]);
|
||||
}
|
||||
/**
|
||||
* @return array<class-string<Node>>
|
||||
*/
|
||||
public function getNodeTypes() : array
|
||||
{
|
||||
return [BinaryOp::class];
|
||||
}
|
||||
/**
|
||||
* @param BinaryOp $node
|
||||
*/
|
||||
public function refactor(Node $node) : ?Node
|
||||
{
|
||||
if (!$node->left instanceof MethodCall) {
|
||||
return null;
|
||||
}
|
||||
$methodCall = $node->left;
|
||||
if (!$this->isRequestGetRequestType($methodCall)) {
|
||||
return null;
|
||||
}
|
||||
if (!$this->isHttpKernelMainRequestClassConstFetch($node->right)) {
|
||||
return null;
|
||||
}
|
||||
$requestClassReflection = $this->reflectionProvider->getClass(SymfonyClass::REQUEST);
|
||||
$methodName = $requestClassReflection->hasMethod('isMainRequest') ? 'isMainRequest' : 'isMasterRequest';
|
||||
return new MethodCall($methodCall->var, $methodName);
|
||||
}
|
||||
private function isRequestGetRequestType(MethodCall $methodCall) : bool
|
||||
{
|
||||
if (!$this->isName($methodCall->name, 'getRequestType')) {
|
||||
return \false;
|
||||
}
|
||||
return $this->isObjectType($methodCall->var, new ObjectType(SymfonyClass::REQUEST));
|
||||
}
|
||||
private function isHttpKernelMainRequestClassConstFetch(Expr $expr) : bool
|
||||
{
|
||||
if (!$expr instanceof ClassConstFetch) {
|
||||
return \false;
|
||||
}
|
||||
if (!$this->isNames($expr->class, [SymfonyClass::HTTP_KERNEL_INTERFACE, SymfonyClass::HTTP_KERNEL])) {
|
||||
return \false;
|
||||
}
|
||||
return $this->isNames($expr->name, ['MASTER_REQUEST', 'MAIN_REQUEST']);
|
||||
}
|
||||
}
|
@ -61,4 +61,16 @@ final class SymfonyClass
|
||||
* @var string
|
||||
*/
|
||||
public const TOKEN_STORAGE_INTERFACE = 'Symfony\\Component\\Security\\Core\\Authentication\\Token\\Storage\\TokenStorageInterface';
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public const HTTP_KERNEL_INTERFACE = 'Symfony\\Component\\HttpKernel\\HttpKernelInterface';
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public const HTTP_KERNEL = 'Symfony\\Component\\HttpKernel\\HttpKernel';
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public const REQUEST = 'Symfony\\Component\\HttpFoundation\\Request';
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user