Skip to content

Commit 2e473ee

Browse files
committed
Updated Rector to commit 2cd301a878e0d9124e96a243632a2395bf975e5e
rectorphp/rector-src@2cd301a [depre] Deprecate strict-types rules as risky and not practical (#7523)
1 parent 2282ccf commit 2e473ee

File tree

9 files changed

+52
-157
lines changed

9 files changed

+52
-157
lines changed

config/set/strict-booleans.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,7 @@
44
namespace RectorPrefix202510;
55

66
use Rector\Config\RectorConfig;
7-
use Rector\Strict\Rector\BooleanNot\BooleanInBooleanNotRuleFixerRector;
87
use Rector\Strict\Rector\Empty_\DisallowedEmptyRuleFixerRector;
9-
use Rector\Strict\Rector\If_\BooleanInIfConditionRuleFixerRector;
10-
use Rector\Strict\Rector\Ternary\BooleanInTernaryOperatorRuleFixerRector;
11-
use Rector\Strict\Rector\Ternary\DisallowedShortTernaryRuleFixerRector;
128
return static function (RectorConfig $rectorConfig): void {
13-
$rectorConfig->rules([BooleanInBooleanNotRuleFixerRector::class, DisallowedEmptyRuleFixerRector::class, BooleanInIfConditionRuleFixerRector::class, BooleanInTernaryOperatorRuleFixerRector::class, DisallowedShortTernaryRuleFixerRector::class]);
9+
$rectorConfig->rules([DisallowedEmptyRuleFixerRector::class]);
1410
};

rules/Strict/Rector/AbstractFalsyScalarRuleFixerRector.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
use Rector\Rector\AbstractRector;
88
use RectorPrefix202510\Webmozart\Assert\Assert;
99
/**
10-
* @see \Rector\Tests\Strict\Rector\BooleanNot\BooleanInBooleanNotRuleFixerRector\BooleanInBooleanNotRuleFixerRectorTest
11-
*
1210
* @internal
1311
*/
1412
abstract class AbstractFalsyScalarRuleFixerRector extends AbstractRector implements ConfigurableRectorInterface

rules/Strict/Rector/BooleanNot/BooleanInBooleanNotRuleFixerRector.php

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,17 @@
66
use PhpParser\Node;
77
use PhpParser\Node\Expr;
88
use PhpParser\Node\Expr\BooleanNot;
9-
use Rector\PHPStan\ScopeFetcher;
10-
use Rector\Strict\NodeFactory\ExactCompareFactory;
11-
use Rector\Strict\Rector\AbstractFalsyScalarRuleFixerRector;
9+
use Rector\Configuration\Deprecation\Contract\DeprecatedInterface;
10+
use Rector\Exception\ShouldNotHappenException;
11+
use Rector\Rector\AbstractRector;
1212
use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample;
1313
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
1414
/**
15-
* Fixer Rector for PHPStan rule:
16-
* https://github.com/phpstan/phpstan-strict-rules/blob/0705fefc7c9168529fd130e341428f5f10f4f01d/src/Rules/BooleansInConditions/BooleanInBooleanNotRule.php
17-
*
18-
* @see \Rector\Tests\Strict\Rector\BooleanNot\BooleanInBooleanNotRuleFixerRector\BooleanInBooleanNotRuleFixerRectorTest
15+
* @deprecated as risky and requires manual checking
1916
*/
20-
final class BooleanInBooleanNotRuleFixerRector extends AbstractFalsyScalarRuleFixerRector
17+
final class BooleanInBooleanNotRuleFixerRector extends AbstractRector implements DeprecatedInterface
2118
{
22-
/**
23-
* @readonly
24-
*/
25-
private ExactCompareFactory $exactCompareFactory;
26-
public function __construct(ExactCompareFactory $exactCompareFactory)
27-
{
28-
$this->exactCompareFactory = $exactCompareFactory;
29-
}
19+
public const TREAT_AS_NON_EMPTY = 'treat_as_non_empty';
3020
public function getRuleDefinition(): RuleDefinition
3121
{
3222
$errorMessage = \sprintf('Fixer for PHPStan reports by strict type rule - "%s"', 'PHPStan\Rules\BooleansInConditions\BooleanInBooleanNotRule');
@@ -70,11 +60,6 @@ public function getNodeTypes(): array
7060
*/
7161
public function refactor(Node $node): ?Expr
7262
{
73-
$scope = ScopeFetcher::fetch($node);
74-
$exprType = $scope->getNativeType($node->expr);
75-
if ($exprType->isBoolean()->yes()) {
76-
return null;
77-
}
78-
return $this->exactCompareFactory->createIdenticalFalsyCompare($exprType, $node->expr, $this->treatAsNonEmpty);
63+
throw new ShouldNotHappenException('This rule is deprecated as risky and not practical');
7964
}
8065
}

rules/Strict/Rector/If_/BooleanInIfConditionRuleFixerRector.php

Lines changed: 7 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,18 @@
44
namespace Rector\Strict\Rector\If_;
55

66
use PhpParser\Node;
7-
use PhpParser\Node\Expr;
87
use PhpParser\Node\Stmt\If_;
9-
use Rector\PHPStan\ScopeFetcher;
10-
use Rector\Strict\NodeFactory\ExactCompareFactory;
11-
use Rector\Strict\Rector\AbstractFalsyScalarRuleFixerRector;
8+
use Rector\Configuration\Deprecation\Contract\DeprecatedInterface;
9+
use Rector\Exception\ShouldNotHappenException;
10+
use Rector\Rector\AbstractRector;
1211
use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample;
1312
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
1413
/**
15-
* Fixer Rector for PHPStan rules:
16-
* https://github.com/phpstan/phpstan-strict-rules/blob/master/src/Rules/BooleansInConditions/BooleanInIfConditionRule.php
17-
* https://github.com/phpstan/phpstan-strict-rules/blob/master/src/Rules/BooleansInConditions/BooleanInElseIfConditionRule.php
18-
*
19-
* @see \Rector\Tests\Strict\Rector\If_\BooleanInIfConditionRuleFixerRector\BooleanInIfConditionRuleFixerRectorTest
14+
* @deprecated this rule is risky and requires manual checking
2015
*/
21-
final class BooleanInIfConditionRuleFixerRector extends AbstractFalsyScalarRuleFixerRector
16+
final class BooleanInIfConditionRuleFixerRector extends AbstractRector implements DeprecatedInterface
2217
{
23-
/**
24-
* @readonly
25-
*/
26-
private ExactCompareFactory $exactCompareFactory;
27-
public function __construct(ExactCompareFactory $exactCompareFactory)
28-
{
29-
$this->exactCompareFactory = $exactCompareFactory;
30-
}
18+
public const TREAT_AS_NON_EMPTY = 'treat_as_non_empty';
3119
public function getRuleDefinition(): RuleDefinition
3220
{
3321
$errorMessage = \sprintf('Fixer for PHPStan reports by strict type rule - "%s"', 'PHPStan\Rules\BooleansInConditions\BooleanInIfConditionRule');
@@ -71,28 +59,6 @@ public function getNodeTypes(): array
7159
*/
7260
public function refactor(Node $node): ?If_
7361
{
74-
$hasChanged = \false;
75-
$scope = ScopeFetcher::fetch($node);
76-
// 1. if
77-
$ifCondExprType = $scope->getNativeType($node->cond);
78-
$notIdentical = $this->exactCompareFactory->createNotIdenticalFalsyCompare($ifCondExprType, $node->cond, $this->treatAsNonEmpty);
79-
if ($notIdentical !== null) {
80-
$node->cond = $notIdentical;
81-
$hasChanged = \true;
82-
}
83-
// 2. elseifs
84-
foreach ($node->elseifs as $elseif) {
85-
$elseifCondExprType = $scope->getNativeType($elseif->cond);
86-
$notIdentical = $this->exactCompareFactory->createNotIdenticalFalsyCompare($elseifCondExprType, $elseif->cond, $this->treatAsNonEmpty);
87-
if (!$notIdentical instanceof Expr) {
88-
continue;
89-
}
90-
$elseif->cond = $notIdentical;
91-
$hasChanged = \true;
92-
}
93-
if ($hasChanged) {
94-
return $node;
95-
}
96-
return null;
62+
throw new ShouldNotHappenException('This rule is deprecated and will be removed as risky and requires manual checking');
9763
}
9864
}

rules/Strict/Rector/Ternary/BooleanInTernaryOperatorRuleFixerRector.php

Lines changed: 7 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,18 @@
44
namespace Rector\Strict\Rector\Ternary;
55

66
use PhpParser\Node;
7-
use PhpParser\Node\Expr;
87
use PhpParser\Node\Expr\Ternary;
9-
use Rector\PHPStan\ScopeFetcher;
10-
use Rector\Strict\NodeFactory\ExactCompareFactory;
11-
use Rector\Strict\Rector\AbstractFalsyScalarRuleFixerRector;
8+
use Rector\Configuration\Deprecation\Contract\DeprecatedInterface;
9+
use Rector\Exception\ShouldNotHappenException;
10+
use Rector\Rector\AbstractRector;
1211
use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample;
1312
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
1413
/**
15-
* Fixer Rector for PHPStan rule:
16-
* https://github.com/phpstan/phpstan-strict-rules/blob/master/src/Rules/BooleansInConditions/BooleanInTernaryOperatorRule.php
17-
*
18-
* @see \Rector\Tests\Strict\Rector\Ternary\BooleanInTernaryOperatorRuleFixerRector\BooleanInTernaryOperatorRuleFixerRectorTest
14+
* @deprecated as risky and requires manual checking
1915
*/
20-
final class BooleanInTernaryOperatorRuleFixerRector extends AbstractFalsyScalarRuleFixerRector
16+
final class BooleanInTernaryOperatorRuleFixerRector extends AbstractRector implements DeprecatedInterface
2117
{
22-
/**
23-
* @readonly
24-
*/
25-
private ExactCompareFactory $exactCompareFactory;
26-
public function __construct(ExactCompareFactory $exactCompareFactory)
27-
{
28-
$this->exactCompareFactory = $exactCompareFactory;
29-
}
18+
public const TREAT_AS_NON_EMPTY = 'treat_as_non_empty';
3019
public function getRuleDefinition(): RuleDefinition
3120
{
3221
$errorMessage = \sprintf('Fixer for PHPStan reports by strict type rule - "%s"', 'PHPStan\Rules\BooleansInConditions\BooleanInTernaryOperatorRule');
@@ -62,17 +51,6 @@ public function getNodeTypes(): array
6251
*/
6352
public function refactor(Node $node): ?Ternary
6453
{
65-
// skip short ternary
66-
if (!$node->if instanceof Expr) {
67-
return null;
68-
}
69-
$scope = ScopeFetcher::fetch($node);
70-
$exprType = $scope->getNativeType($node->cond);
71-
$expr = $this->exactCompareFactory->createNotIdenticalFalsyCompare($exprType, $node->cond, $this->treatAsNonEmpty);
72-
if (!$expr instanceof Expr) {
73-
return null;
74-
}
75-
$node->cond = $expr;
76-
return $node;
54+
throw new ShouldNotHappenException('This rule is deprecated as risky and not practical');
7755
}
7856
}

rules/Strict/Rector/Ternary/DisallowedShortTernaryRuleFixerRector.php

Lines changed: 7 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -4,32 +4,21 @@
44
namespace Rector\Strict\Rector\Ternary;
55

66
use PhpParser\Node;
7-
use PhpParser\Node\Expr;
8-
use PhpParser\Node\Expr\FuncCall;
97
use PhpParser\Node\Expr\Ternary;
10-
use PHPStan\Analyser\Scope;
11-
use Rector\PHPStan\ScopeFetcher;
12-
use Rector\Strict\NodeFactory\ExactCompareFactory;
13-
use Rector\Strict\Rector\AbstractFalsyScalarRuleFixerRector;
8+
use Rector\Configuration\Deprecation\Contract\DeprecatedInterface;
9+
use Rector\Exception\ShouldNotHappenException;
10+
use Rector\Rector\AbstractRector;
1411
use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample;
1512
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
1613
/**
1714
* Fixer Rector for PHPStan rule:
1815
* https://github.com/phpstan/phpstan-strict-rules/blob/master/src/Rules/DisallowedConstructs/DisallowedShortTernaryRule.php
1916
*
20-
* @see \Rector\Tests\Strict\Rector\Ternary\DisallowedShortTernaryRuleFixerRector\DisallowedShortTernaryRuleFixerRectorTest
17+
* @deprecated as risky and not practical
2118
*/
22-
final class DisallowedShortTernaryRuleFixerRector extends AbstractFalsyScalarRuleFixerRector
19+
final class DisallowedShortTernaryRuleFixerRector extends AbstractRector implements DeprecatedInterface
2320
{
24-
/**
25-
* @readonly
26-
*/
27-
private ExactCompareFactory $exactCompareFactory;
28-
private bool $hasChanged = \false;
29-
public function __construct(ExactCompareFactory $exactCompareFactory)
30-
{
31-
$this->exactCompareFactory = $exactCompareFactory;
32-
}
21+
public const TREAT_AS_NON_EMPTY = 'treat_as_non_empty';
3322
public function getRuleDefinition(): RuleDefinition
3423
{
3524
$errorMessage = sprintf('Fixer for PHPStan reports by strict type rule - "%s"', 'PHPStan\Rules\DisallowedConstructs\DisallowedShortTernaryRule');
@@ -65,42 +54,6 @@ public function getNodeTypes(): array
6554
*/
6655
public function refactor(Node $node): ?Ternary
6756
{
68-
$this->hasChanged = \false;
69-
// skip non-short ternary
70-
if ($node->if instanceof Expr) {
71-
return null;
72-
}
73-
$scope = ScopeFetcher::fetch($node);
74-
// special case for reset() function
75-
if ($node->cond instanceof FuncCall && $this->isName($node->cond, 'reset')) {
76-
$this->refactorResetFuncCall($node, $node->cond, $scope);
77-
if (!$this->hasChanged) {
78-
return null;
79-
}
80-
return $node;
81-
}
82-
$exprType = $scope->getNativeType($node->cond);
83-
$compareExpr = $this->exactCompareFactory->createNotIdenticalFalsyCompare($exprType, $node->cond, $this->treatAsNonEmpty);
84-
if (!$compareExpr instanceof Expr) {
85-
return null;
86-
}
87-
$node->if = $node->cond;
88-
$node->cond = $compareExpr;
89-
return $node;
90-
}
91-
private function refactorResetFuncCall(Ternary $ternary, FuncCall $resetFuncCall, Scope $scope): void
92-
{
93-
$ternary->if = $ternary->cond;
94-
if ($resetFuncCall->isFirstClassCallable()) {
95-
return;
96-
}
97-
$firstArgValue = $resetFuncCall->getArgs()[0]->value;
98-
$firstArgType = $scope->getNativeType($firstArgValue);
99-
$falsyCompareExpr = $this->exactCompareFactory->createNotIdenticalFalsyCompare($firstArgType, $firstArgValue, $this->treatAsNonEmpty);
100-
if (!$falsyCompareExpr instanceof Expr) {
101-
return;
102-
}
103-
$ternary->cond = $falsyCompareExpr;
104-
$this->hasChanged = \true;
57+
throw new ShouldNotHappenException('This rule is deprecated as risky and not practical');
10558
}
10659
}

src/Application/VersionResolver.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ final class VersionResolver
1919
* @api
2020
* @var string
2121
*/
22-
public const PACKAGE_VERSION = '5b5c2cd9f465b32508eede574f3b7fba7465f734';
22+
public const PACKAGE_VERSION = '2cd301a878e0d9124e96a243632a2395bf975e5e';
2323
/**
2424
* @api
2525
* @var string
2626
*/
27-
public const RELEASE_DATE = '2025-10-20 21:28:09';
27+
public const RELEASE_DATE = '2025-10-21 10:32:00';
2828
/**
2929
* @var int
3030
*/

src/Configuration/RectorConfigBuilder.php

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -523,10 +523,28 @@ public function withPhp74Sets(): self
523523
}
524524
// there is no withPhp80Sets() and above,
525525
// as we already use PHP 8.0 and should go with withPhpSets() instead
526-
public function withPreparedSets(bool $deadCode = \false, bool $codeQuality = \false, bool $codingStyle = \false, bool $typeDeclarations = \false, bool $typeDeclarationDocblocks = \false, bool $privatization = \false, bool $naming = \false, bool $instanceOf = \false, bool $earlyReturn = \false, bool $strictBooleans = \false, bool $carbon = \false, bool $rectorPreset = \false, bool $phpunitCodeQuality = \false, bool $doctrineCodeQuality = \false, bool $symfonyCodeQuality = \false, bool $symfonyConfigs = \false): self
526+
public function withPreparedSets(
527+
bool $deadCode = \false,
528+
bool $codeQuality = \false,
529+
bool $codingStyle = \false,
530+
bool $typeDeclarations = \false,
531+
bool $typeDeclarationDocblocks = \false,
532+
bool $privatization = \false,
533+
bool $naming = \false,
534+
bool $instanceOf = \false,
535+
bool $earlyReturn = \false,
536+
/** @deprecated */
537+
bool $strictBooleans = \false,
538+
bool $carbon = \false,
539+
bool $rectorPreset = \false,
540+
bool $phpunitCodeQuality = \false,
541+
bool $doctrineCodeQuality = \false,
542+
bool $symfonyCodeQuality = \false,
543+
bool $symfonyConfigs = \false
544+
): self
527545
{
528546
Notifier::notifyNotSuitableMethodForPHP74(__METHOD__);
529-
$setMap = [SetList::DEAD_CODE => $deadCode, SetList::CODE_QUALITY => $codeQuality, SetList::CODING_STYLE => $codingStyle, SetList::TYPE_DECLARATION => $typeDeclarations, SetList::TYPE_DECLARATION_DOCBLOCKS => $typeDeclarationDocblocks, SetList::PRIVATIZATION => $privatization, SetList::NAMING => $naming, SetList::INSTANCEOF => $instanceOf, SetList::EARLY_RETURN => $earlyReturn, SetList::STRICT_BOOLEANS => $strictBooleans, SetList::CARBON => $carbon, SetList::RECTOR_PRESET => $rectorPreset, PHPUnitSetList::PHPUNIT_CODE_QUALITY => $phpunitCodeQuality, DoctrineSetList::DOCTRINE_CODE_QUALITY => $doctrineCodeQuality, SymfonySetList::SYMFONY_CODE_QUALITY => $symfonyCodeQuality, SymfonySetList::CONFIGS => $symfonyConfigs];
547+
$setMap = [SetList::DEAD_CODE => $deadCode, SetList::CODE_QUALITY => $codeQuality, SetList::CODING_STYLE => $codingStyle, SetList::TYPE_DECLARATION => $typeDeclarations, SetList::TYPE_DECLARATION_DOCBLOCKS => $typeDeclarationDocblocks, SetList::PRIVATIZATION => $privatization, SetList::NAMING => $naming, SetList::INSTANCEOF => $instanceOf, SetList::EARLY_RETURN => $earlyReturn, SetList::CARBON => $carbon, SetList::RECTOR_PRESET => $rectorPreset, PHPUnitSetList::PHPUNIT_CODE_QUALITY => $phpunitCodeQuality, DoctrineSetList::DOCTRINE_CODE_QUALITY => $doctrineCodeQuality, SymfonySetList::SYMFONY_CODE_QUALITY => $symfonyCodeQuality, SymfonySetList::CONFIGS => $symfonyConfigs];
530548
foreach ($setMap as $setPath => $isEnabled) {
531549
if ($isEnabled) {
532550
$this->sets[] = $setPath;

src/Set/ValueObject/SetList.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ final class SetList
2626
*/
2727
public const DEAD_CODE = __DIR__ . '/../../../config/set/dead-code.php';
2828
/**
29+
* @deprecated As too strict and not practical. Use code quality and coding style sets instead.
2930
* @var string
3031
*/
3132
public const STRICT_BOOLEANS = __DIR__ . '/../../../config/set/strict-booleans.php';

0 commit comments

Comments
 (0)