Skip to content

Commit

Permalink
[DX] Remove AllowEmptyConfigurableRectorInterface to ease interface t…
Browse files Browse the repository at this point in the history
…ree, better handle on particular configure() method inside the rule (#4540)
  • Loading branch information
TomasVotruba committed Jul 19, 2023
1 parent 972d760 commit ab13fe4
Show file tree
Hide file tree
Showing 21 changed files with 22 additions and 302 deletions.
4 changes: 0 additions & 4 deletions config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
use Rector\Core\Contract\Rector\RectorInterface;
use Rector\Core\NonPhpFile\NonPhpFileProcessor;
use Rector\Core\PhpParser\NodeTraverser\RectorNodeTraverser;
use Rector\Core\Validation\Collector\EmptyConfigurableRectorCollector;
use Rector\Core\ValueObjectFactory\Application\FileFactory;
use Rector\NodeNameResolver\Contract\NodeNameResolverInterface;
use Rector\NodeNameResolver\NodeNameResolver;
Expand Down Expand Up @@ -182,9 +181,6 @@
->arg('$commands', tagged_iterator(Command::class));
$services->alias(Application::class, ConsoleApplication::class);

$services->set(EmptyConfigurableRectorCollector::class)
->arg('$containerBuilder', service('service_container'));

$services->set(SimpleCallableNodeTraverser::class);

$services->set(BuilderFactory::class);
Expand Down
19 changes: 1 addition & 18 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ parameters:
paths:
- rules/Php70/EregToPcreTransformer.php
- packages/NodeTypeResolver/NodeTypeResolver.php
- rules/Renaming/NodeManipulator/ClassRenamer.php
- packages/NodeTypeResolver/PHPStan/Scope/PHPStanNodeScopeResolver.php

- "#^Cognitive complexity for \"Rector\\\\Php70\\\\EregToPcreTransformer\\:\\:(.*?)\" is (.*?), keep it under 11$#"
Expand Down Expand Up @@ -172,12 +171,6 @@ parameters:
- src/Rector/AbstractRector.php
- src/Rector/AbstractScopeAwareRector.php

# find everything class, better then 10 different finders
-
message: '#Class cognitive complexity is \d+, keep it under 50#'
paths:
- src/PhpParser/Node/BetterNodeFinder.php

-
message: '#Parameter \#2 \$length of function str_split expects int<1, max\>, int given#'
paths:
Expand Down Expand Up @@ -656,8 +649,6 @@ parameters:
- '#Cognitive complexity for "Rector\\(.*?)\:\:refactor\(\)" is (1[0-9]|20), keep it under 11#'
- '#Cognitive complexity for "Rector\\DeadCode\\Rector\\StaticCall\\RemoveParentCallWithoutParentRector\:\:refactor\(\)" is 26, keep it under 11#'

- '#Call to deprecated method findFirstPrevious\(\) of class Rector\\Core\\PhpParser\\Node\\BetterNodeFinder#'

- '#Return type (.*?) should be covariant with return type \(1\|2\|3\|4\|array<PhpParser\\Node>\|PhpParser\\Node\|null\) of method Rector\\Core\\Contract\\Rector(.*?)\:\:(.*?)#'

# false positive
Expand All @@ -680,11 +671,8 @@ parameters:
# for symfony configs check
- '#Symfony\\Component\\DependencyInjection\\Loader\\Configurator\\tagged_iterator not found#'

-
message: '#Parameters should use "PhpParser\\Node\\Expr\\Variable\|array" types as the only types passed to this method#'
path: src/PhpParser/Node/BetterNodeFinder.php

- '#The "Rector\\Core\\ValueObject\\Application\\File" class always calls "hydrateStmtsAndTokens\(\)" setters, better move it to constructor#'
- '#Fetching class constant class of deprecated class Rector\\Core\\Configuration\\Parameter\\ParameterProvider#'

# refactor in next PR
- '#(.*?) has typehint with deprecated class Rector\\Core\\Configuration\\Parameter\\ParameterProvider#'
Expand All @@ -698,10 +686,5 @@ parameters:
paths:
- src/NodeManipulator/PropertyManipulator.php

- '#Fetching class constant class of deprecated class Rector\\Core\\Configuration\\Parameter\\ParameterProvider#'

# handle in next PR
- '#Call to deprecated method findFirstNext\(\) of class Rector\\Core\\PhpParser\\Node\\BetterNodeFinder#'

# remove later
- '#Public method "Rector\\Core\\NodeManipulator\\IfManipulator\:\:createIfStmt\(\)" is never used#'
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
use PhpParser\Node\Stmt\ClassConst;
use PhpParser\NodeTraverser;
use PHPStan\Reflection\ReflectionProvider;
use Rector\Core\Contract\Rector\AllowEmptyConfigurableRectorInterface;
use Rector\Core\Contract\Rector\ConfigurableRectorInterface;
use Rector\Core\Rector\AbstractRector;
use Rector\Core\ValueObject\PhpVersionFeature;
use Rector\VersionBonding\Contract\MinPhpVersionInterface;
Expand All @@ -26,7 +26,7 @@
*
* @see \Rector\Tests\Php55\Rector\String_\StringClassNameToClassConstantRector\StringClassNameToClassConstantRectorTest
*/
final class StringClassNameToClassConstantRector extends AbstractRector implements AllowEmptyConfigurableRectorInterface, MinPhpVersionInterface
final class StringClassNameToClassConstantRector extends AbstractRector implements MinPhpVersionInterface, ConfigurableRectorInterface
{
/**
* @var string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use PhpParser\Node;
use PhpParser\Node\Scalar\DNumber;
use PhpParser\Node\Scalar\LNumber;
use Rector\Core\Contract\Rector\AllowEmptyConfigurableRectorInterface;
use Rector\Core\Contract\Rector\ConfigurableRectorInterface;
use Rector\Core\Rector\AbstractRector;
use Rector\Core\Util\StringUtils;
use Rector\Core\ValueObject\PhpVersionFeature;
Expand All @@ -21,13 +21,14 @@
/**
* @changelog https://wiki.php.net/rfc/numeric_literal_separator
* @changelog https://github.com/nikic/PHP-Parser/pull/615
*
* @see \Rector\Tests\Php74\Rector\LNumber\AddLiteralSeparatorToNumberRector\AddLiteralSeparatorToNumberRectorTest
* @changelog https://twitter.com/seldaek/status/1329064983120982022
*
* Taking the most generic use case to the account: https://wiki.php.net/rfc/numeric_literal_separator#should_it_be_the_role_of_an_ide_to_group_digits
* The final check should be done manually
*/
final class AddLiteralSeparatorToNumberRector extends AbstractRector implements AllowEmptyConfigurableRectorInterface, MinPhpVersionInterface
final class AddLiteralSeparatorToNumberRector extends AbstractRector implements MinPhpVersionInterface, ConfigurableRectorInterface
{
/**
* @api
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
use PHPStan\Type\TypeCombinator;
use Rector\BetterPhpDocParser\PhpDocManipulator\PhpDocTypeChanger;
use Rector\BetterPhpDocParser\ValueObject\PhpDocAttributeKey;
use Rector\Core\Contract\Rector\AllowEmptyConfigurableRectorInterface;
use Rector\Core\Contract\Rector\ConfigurableRectorInterface;
use Rector\Core\NodeAnalyzer\ParamAnalyzer;
use Rector\Core\Rector\AbstractRector;
use Rector\Core\ValueObject\MethodName;
Expand All @@ -41,7 +41,7 @@
*
* @see \Rector\Tests\Php80\Rector\Class_\ClassPropertyAssignToConstructorPromotionRector\ClassPropertyAssignToConstructorPromotionRectorTest
*/
final class ClassPropertyAssignToConstructorPromotionRector extends AbstractRector implements MinPhpVersionInterface, AllowEmptyConfigurableRectorInterface
final class ClassPropertyAssignToConstructorPromotionRector extends AbstractRector implements MinPhpVersionInterface, ConfigurableRectorInterface
{
/**
* @api
Expand Down
4 changes: 2 additions & 2 deletions rules/Strict/Rector/AbstractFalsyScalarRuleFixerRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Rector\Strict\Rector;

use Rector\Core\Contract\Rector\AllowEmptyConfigurableRectorInterface;
use Rector\Core\Contract\Rector\ConfigurableRectorInterface;
use Rector\Core\Rector\AbstractScopeAwareRector;
use Webmozart\Assert\Assert;

Expand All @@ -13,7 +13,7 @@
*
* @internal
*/
abstract class AbstractFalsyScalarRuleFixerRector extends AbstractScopeAwareRector implements AllowEmptyConfigurableRectorInterface
abstract class AbstractFalsyScalarRuleFixerRector extends AbstractScopeAwareRector implements ConfigurableRectorInterface
{
/**
* @api
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use PhpParser\Node\Expr\Empty_;
use PhpParser\Node\Expr\Isset_;
use PHPStan\Analyser\Scope;
use Rector\Core\Contract\Rector\ConfigurableRectorInterface;
use Rector\Strict\NodeFactory\ExactCompareFactory;
use Rector\Strict\Rector\AbstractFalsyScalarRuleFixerRector;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample;
Expand All @@ -20,7 +21,7 @@
/**
* @see \Rector\Tests\Strict\Rector\Empty_\DisallowedEmptyRuleFixerRector\DisallowedEmptyRuleFixerRectorTest
*/
final class DisallowedEmptyRuleFixerRector extends AbstractFalsyScalarRuleFixerRector
final class DisallowedEmptyRuleFixerRector extends AbstractFalsyScalarRuleFixerRector implements ConfigurableRectorInterface
{
public function __construct(
private readonly ExactCompareFactory $exactCompareFactory,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use PhpParser\Node;
use PhpParser\Node\Stmt\Class_;
use PhpParser\Node\Stmt\Interface_;
use Rector\Core\Contract\Rector\AllowEmptyConfigurableRectorInterface;
use Rector\Core\Contract\Rector\ConfigurableRectorInterface;
use Rector\Core\Rector\AbstractRector;
use Rector\Core\Reflection\ReflectionResolver;
use Rector\Core\ValueObject\PhpVersionFeature;
Expand All @@ -23,7 +23,7 @@
/**
* @see \Rector\Tests\Transform\Rector\ClassMethod\ReturnTypeWillChangeRector\ReturnTypeWillChangeRectorTest
*/
final class ReturnTypeWillChangeRector extends AbstractRector implements AllowEmptyConfigurableRectorInterface, MinPhpVersionInterface
final class ReturnTypeWillChangeRector extends AbstractRector implements MinPhpVersionInterface, ConfigurableRectorInterface
{
/**
* @var ClassMethodReference[]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use PhpParser\Node\Name\FullyQualified;
use PhpParser\Node\Stmt\Class_;
use PHPStan\Reflection\ReflectionProvider;
use Rector\Core\Contract\Rector\AllowEmptyConfigurableRectorInterface;
use Rector\Core\Contract\Rector\ConfigurableRectorInterface;
use Rector\Core\Rector\AbstractRector;
use Rector\Core\ValueObject\MethodName;
use Rector\Core\ValueObject\PhpVersionFeature;
Expand All @@ -26,7 +26,7 @@
*
* @see \Rector\Tests\Transform\Rector\Class_\AddAllowDynamicPropertiesAttributeRector\AddAllowDynamicPropertiesAttributeRectorTest
*/
final class AddAllowDynamicPropertiesAttributeRector extends AbstractRector implements AllowEmptyConfigurableRectorInterface, MinPhpVersionInterface
final class AddAllowDynamicPropertiesAttributeRector extends AbstractRector implements MinPhpVersionInterface, ConfigurableRectorInterface
{
/**
* @var array<array-key, string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
use PHPStan\Type\NeverType;
use PHPStan\Type\VoidType;
use Rector\BetterPhpDocParser\PhpDocManipulator\PhpDocTypeChanger;
use Rector\Core\Contract\Rector\AllowEmptyConfigurableRectorInterface;
use Rector\Core\Contract\Rector\ConfigurableRectorInterface;
use Rector\Core\Rector\AbstractRector;
use Rector\Core\Reflection\ReflectionResolver;
use Rector\Core\ValueObject\PhpVersionFeature;
Expand All @@ -27,7 +27,7 @@
/**
* @see \Rector\Tests\TypeDeclaration\Rector\ClassMethod\AddVoidReturnTypeWhereNoReturnRector\AddVoidReturnTypeWhereNoReturnRectorTest
*/
final class AddVoidReturnTypeWhereNoReturnRector extends AbstractRector implements MinPhpVersionInterface, AllowEmptyConfigurableRectorInterface
final class AddVoidReturnTypeWhereNoReturnRector extends AbstractRector implements ConfigurableRectorInterface, MinPhpVersionInterface
{
/**
* @api
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
use PHPStan\Type\Type;
use PHPStan\Type\TypeCombinator;
use PHPStan\Type\UnionType;
use Rector\Core\Contract\Rector\AllowEmptyConfigurableRectorInterface;
use Rector\Core\Contract\Rector\ConfigurableRectorInterface;
use Rector\Core\Rector\AbstractRector;
use Rector\Core\Reflection\ReflectionResolver;
use Rector\Core\ValueObject\PhpVersionFeature;
Expand All @@ -29,7 +29,7 @@
/**
* @see \Rector\Tests\TypeDeclaration\Rector\Property\TypedPropertyFromAssignsRector\TypedPropertyFromAssignsRectorTest
*/
final class TypedPropertyFromAssignsRector extends AbstractRector implements AllowEmptyConfigurableRectorInterface, MinPhpVersionInterface
final class TypedPropertyFromAssignsRector extends AbstractRector implements MinPhpVersionInterface, ConfigurableRectorInterface
{
/**
* @api
Expand Down
9 changes: 2 additions & 7 deletions src/Console/Command/ProcessCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
use Rector\Core\Exception\ShouldNotHappenException;
use Rector\Core\StaticReflection\DynamicSourceLocatorDecorator;
use Rector\Core\Util\MemoryLimiter;
use Rector\Core\Validation\EmptyConfigurableRectorChecker;
use Rector\Core\ValueObject\Configuration;
use Rector\Core\ValueObject\ProcessResult;
use Rector\Core\ValueObjectFactory\ProcessResultFactory;
Expand All @@ -33,7 +32,6 @@ public function __construct(
private readonly ApplicationFileProcessor $applicationFileProcessor,
private readonly ProcessResultFactory $processResultFactory,
private readonly DynamicSourceLocatorDecorator $dynamicSourceLocatorDecorator,
private readonly EmptyConfigurableRectorChecker $emptyConfigurableRectorChecker,
private readonly OutputFormatterCollector $outputFormatterCollector,
private readonly OutputStyleInterface $rectorOutputStyle,
private readonly MemoryLimiter $memoryLimiter,
Expand Down Expand Up @@ -77,15 +75,12 @@ protected function execute(InputInterface $input, OutputInterface $output): int
return ExitCode::FAILURE;
}

// 2. inform user about registering configurable rule without configuration
$this->emptyConfigurableRectorChecker->check();

// MAIN PHASE
// 3. run Rector
// 2. run Rector
$systemErrorsAndFileDiffs = $this->applicationFileProcessor->run($configuration, $input);

// REPORTING PHASE
// 4. reporting phase
// 3. reporting phase
// report diffs and errors
$outputFormat = $configuration->getOutputFormat();
$outputFormatter = $this->outputFormatterCollector->getByName($outputFormat);
Expand Down
9 changes: 0 additions & 9 deletions src/Contract/Rector/AllowEmptyConfigurableRectorInterface.php

This file was deleted.

69 changes: 0 additions & 69 deletions src/Validation/Collector/EmptyConfigurableRectorCollector.php

This file was deleted.

Loading

0 comments on commit ab13fe4

Please sign in to comment.