Updated Rector to commit 026398c9e1078cb3ac5cac41767b620872166859

026398c9e1 Remove return type in case of void in RemoveUselessReturnTagRector (#5318)
This commit is contained in:
Tomas Votruba 2023-12-03 19:10:14 +00:00
parent 07dd432ed3
commit ab4ff53673
6 changed files with 7 additions and 116 deletions

View File

@ -3,6 +3,7 @@
declare (strict_types=1);
namespace Rector\DeadCode\PhpDoc;
use PhpParser\Node\Identifier;
use PhpParser\Node\Stmt\ClassMethod;
use PHPStan\Analyser\Scope;
use PHPStan\PhpDocParser\Ast\PhpDoc\ReturnTagValueNode;
@ -63,6 +64,10 @@ final class DeadReturnTagValueNodeAnalyzer
if ($scope instanceof Scope && $scope->isInTrait() && $returnTagValueNode->type instanceof ThisTypeNode) {
return \false;
}
// in case of void, there is no added value in @return tag
if ($returnType instanceof Identifier && $returnType->toString() === 'void') {
return \true;
}
if (!$this->typeComparator->arePhpParserAndPhpStanPhpDocTypesEqual($returnType, $returnTagValueNode->type, $classMethod)) {
return $returnTagValueNode->type instanceof IdentifierTypeNode && (string) $returnTagValueNode->type === 'void';
}

View File

@ -1,51 +0,0 @@
<?php
declare (strict_types=1);
namespace Rector\Php71\Rector\FuncCall;
use PhpParser\Node;
use PhpParser\Node\Expr\FuncCall;
use PhpParser\Node\Expr\Ternary;
use PHPStan\Analyser\Scope;
use Rector\Core\Rector\AbstractScopeAwareRector;
use Rector\Core\ValueObject\PhpVersionFeature;
use Rector\VersionBonding\Contract\MinPhpVersionInterface;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
/**
* @changelog https://3v4l.org/Bndc9
*/
final class CountOnNullRector extends AbstractScopeAwareRector implements MinPhpVersionInterface
{
public function provideMinPhpVersion() : int
{
return PhpVersionFeature::COUNT_ON_NULL;
}
public function getRuleDefinition() : RuleDefinition
{
return new RuleDefinition('Changes count() on null to safe ternary check', [new CodeSample(<<<'CODE_SAMPLE'
$values = null;
$count = count($values);
CODE_SAMPLE
, <<<'CODE_SAMPLE'
$values = null;
$count = $values === null ? 0 : count($values);
CODE_SAMPLE
)]);
}
/**
* @return array<class-string<Node>>
*/
public function getNodeTypes() : array
{
return [FuncCall::class, Ternary::class];
}
/**
* @param FuncCall|Ternary $node
* @return int|\PhpParser\Node\Expr\Ternary|null|\PhpParser\Node\Expr\FuncCall
*/
public function refactorWithScope(Node $node, Scope $scope)
{
\trigger_error(\sprintf('The "%s" rule is now deprecated as often reports false positives and requires custom refactoring of previous code. Use PHPStan to spot nullable arguments and refactor code to fit your use case.', self::class), \E_USER_ERROR);
}
}

View File

@ -1,59 +0,0 @@
<?php
declare (strict_types=1);
namespace Rector\TypeDeclaration\Rector\Property;
use PhpParser\Node;
use PhpParser\Node\Stmt\Class_;
use Rector\Core\Rector\AbstractRector;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
/**
* @api
* @deprecated This rule is deprecated as created invalid code. Use other rules from TYPE_DECLARATION instead
*/
final class TypedPropertyFromStrictGetterMethodReturnTypeRector extends AbstractRector
{
public function getRuleDefinition() : RuleDefinition
{
return new RuleDefinition('Complete property type based on getter strict types', [new CodeSample(<<<'CODE_SAMPLE'
final class SomeClass
{
public $name;
public function getName(): string|null
{
return $this->name;
}
}
CODE_SAMPLE
, <<<'CODE_SAMPLE'
final class SomeClass
{
public ?string $name = null;
public function getName(): string|null
{
return $this->name;
}
}
CODE_SAMPLE
)]);
}
/**
* @return array<class-string<Node>>
*/
public function getNodeTypes() : array
{
return [Class_::class];
}
/**
* @param Class_ $node
*/
public function refactor(Node $node) : ?\PhpParser\Node\Stmt\Class_
{
\trigger_error('This rule is deprecated as created invalid code. Use other rules from TYPE_DECLARATION instead');
\sleep(3);
return null;
}
}

View File

@ -19,12 +19,12 @@ final class VersionResolver
* @api
* @var string
*/
public const PACKAGE_VERSION = 'b8e6818ed04f3aa07218569509bd819db3649820';
public const PACKAGE_VERSION = '026398c9e1078cb3ac5cac41767b620872166859';
/**
* @api
* @var string
*/
public const RELEASE_DATE = '2023-12-03 18:41:40';
public const RELEASE_DATE = '2023-12-03 20:08:03';
/**
* @var int
*/

View File

@ -1808,7 +1808,6 @@ return array(
'Rector\\Php71\\Rector\\BinaryOp\\BinaryOpBetweenNumberAndStringRector' => $baseDir . '/rules/Php71/Rector/BinaryOp/BinaryOpBetweenNumberAndStringRector.php',
'Rector\\Php71\\Rector\\BooleanOr\\IsIterableRector' => $baseDir . '/rules/Php71/Rector/BooleanOr/IsIterableRector.php',
'Rector\\Php71\\Rector\\ClassConst\\PublicConstantVisibilityRector' => $baseDir . '/rules/Php71/Rector/ClassConst/PublicConstantVisibilityRector.php',
'Rector\\Php71\\Rector\\FuncCall\\CountOnNullRector' => $baseDir . '/rules/Php71/Rector/FuncCall/CountOnNullRector.php',
'Rector\\Php71\\Rector\\FuncCall\\RemoveExtraParametersRector' => $baseDir . '/rules/Php71/Rector/FuncCall/RemoveExtraParametersRector.php',
'Rector\\Php71\\Rector\\List_\\ListToArrayDestructRector' => $baseDir . '/rules/Php71/Rector/List_/ListToArrayDestructRector.php',
'Rector\\Php71\\Rector\\TryCatch\\MultiExceptionCatchRector' => $baseDir . '/rules/Php71/Rector/TryCatch/MultiExceptionCatchRector.php',
@ -2340,7 +2339,6 @@ return array(
'Rector\\TypeDeclaration\\Rector\\Property\\AddPropertyTypeDeclarationRector' => $baseDir . '/rules/TypeDeclaration/Rector/Property/AddPropertyTypeDeclarationRector.php',
'Rector\\TypeDeclaration\\Rector\\Property\\TypedPropertyFromAssignsRector' => $baseDir . '/rules/TypeDeclaration/Rector/Property/TypedPropertyFromAssignsRector.php',
'Rector\\TypeDeclaration\\Rector\\Property\\TypedPropertyFromStrictConstructorRector' => $baseDir . '/rules/TypeDeclaration/Rector/Property/TypedPropertyFromStrictConstructorRector.php',
'Rector\\TypeDeclaration\\Rector\\Property\\TypedPropertyFromStrictGetterMethodReturnTypeRector' => $baseDir . '/rules/TypeDeclaration/Rector/Property/TypedPropertyFromStrictGetterMethodReturnTypeRector.php',
'Rector\\TypeDeclaration\\Rector\\Property\\TypedPropertyFromStrictSetUpRector' => $baseDir . '/rules/TypeDeclaration/Rector/Property/TypedPropertyFromStrictSetUpRector.php',
'Rector\\TypeDeclaration\\Rector\\StmtsAwareInterface\\DeclareStrictTypesRector' => $baseDir . '/rules/TypeDeclaration/Rector/StmtsAwareInterface/DeclareStrictTypesRector.php',
'Rector\\TypeDeclaration\\Rector\\While_\\WhileNullableToInstanceofRector' => $baseDir . '/rules/TypeDeclaration/Rector/While_/WhileNullableToInstanceofRector.php',

View File

@ -2026,7 +2026,6 @@ class ComposerStaticInita55c41c7fa52abd86138c6f32df1d185
'Rector\\Php71\\Rector\\BinaryOp\\BinaryOpBetweenNumberAndStringRector' => __DIR__ . '/../..' . '/rules/Php71/Rector/BinaryOp/BinaryOpBetweenNumberAndStringRector.php',
'Rector\\Php71\\Rector\\BooleanOr\\IsIterableRector' => __DIR__ . '/../..' . '/rules/Php71/Rector/BooleanOr/IsIterableRector.php',
'Rector\\Php71\\Rector\\ClassConst\\PublicConstantVisibilityRector' => __DIR__ . '/../..' . '/rules/Php71/Rector/ClassConst/PublicConstantVisibilityRector.php',
'Rector\\Php71\\Rector\\FuncCall\\CountOnNullRector' => __DIR__ . '/../..' . '/rules/Php71/Rector/FuncCall/CountOnNullRector.php',
'Rector\\Php71\\Rector\\FuncCall\\RemoveExtraParametersRector' => __DIR__ . '/../..' . '/rules/Php71/Rector/FuncCall/RemoveExtraParametersRector.php',
'Rector\\Php71\\Rector\\List_\\ListToArrayDestructRector' => __DIR__ . '/../..' . '/rules/Php71/Rector/List_/ListToArrayDestructRector.php',
'Rector\\Php71\\Rector\\TryCatch\\MultiExceptionCatchRector' => __DIR__ . '/../..' . '/rules/Php71/Rector/TryCatch/MultiExceptionCatchRector.php',
@ -2558,7 +2557,6 @@ class ComposerStaticInita55c41c7fa52abd86138c6f32df1d185
'Rector\\TypeDeclaration\\Rector\\Property\\AddPropertyTypeDeclarationRector' => __DIR__ . '/../..' . '/rules/TypeDeclaration/Rector/Property/AddPropertyTypeDeclarationRector.php',
'Rector\\TypeDeclaration\\Rector\\Property\\TypedPropertyFromAssignsRector' => __DIR__ . '/../..' . '/rules/TypeDeclaration/Rector/Property/TypedPropertyFromAssignsRector.php',
'Rector\\TypeDeclaration\\Rector\\Property\\TypedPropertyFromStrictConstructorRector' => __DIR__ . '/../..' . '/rules/TypeDeclaration/Rector/Property/TypedPropertyFromStrictConstructorRector.php',
'Rector\\TypeDeclaration\\Rector\\Property\\TypedPropertyFromStrictGetterMethodReturnTypeRector' => __DIR__ . '/../..' . '/rules/TypeDeclaration/Rector/Property/TypedPropertyFromStrictGetterMethodReturnTypeRector.php',
'Rector\\TypeDeclaration\\Rector\\Property\\TypedPropertyFromStrictSetUpRector' => __DIR__ . '/../..' . '/rules/TypeDeclaration/Rector/Property/TypedPropertyFromStrictSetUpRector.php',
'Rector\\TypeDeclaration\\Rector\\StmtsAwareInterface\\DeclareStrictTypesRector' => __DIR__ . '/../..' . '/rules/TypeDeclaration/Rector/StmtsAwareInterface/DeclareStrictTypesRector.php',
'Rector\\TypeDeclaration\\Rector\\While_\\WhileNullableToInstanceofRector' => __DIR__ . '/../..' . '/rules/TypeDeclaration/Rector/While_/WhileNullableToInstanceofRector.php',