Skip to content

Commit

Permalink
Remove SwapFuncCallArgumentsRector as keeps swaping to infinity, use …
Browse files Browse the repository at this point in the history
…custom rule instead (#4874)
  • Loading branch information
TomasVotruba committed Aug 28, 2023
1 parent 2f38105 commit 9e8ed6c
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 261 deletions.
25 changes: 2 additions & 23 deletions build/target-repository/docs/rector_rules_overview.md
@@ -1,10 +1,10 @@
# 354 Rules Overview
# 353 Rules Overview

<br>

## Categories

- [Arguments](#arguments) (5)
- [Arguments](#arguments) (4)

- [CodeQuality](#codequality) (70)

Expand Down Expand Up @@ -138,27 +138,6 @@ Replaces defined map of arguments in defined methods and their calls.

<br>

### SwapFuncCallArgumentsRector

Reorder arguments in function calls

:wrench: **configure it!**

- class: [`Rector\Arguments\Rector\FuncCall\SwapFuncCallArgumentsRector`](../rules/Arguments/Rector/FuncCall/SwapFuncCallArgumentsRector.php)

```diff
final class SomeClass
{
public function run()
{
- return some_function('one', 'two', 'three');
+ return some_function('three', 'two', 'one');
}
}
```

<br>

## CodeQuality

### AbsolutizeRequireAndIncludePathRector
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

134 changes: 0 additions & 134 deletions rules/Arguments/Rector/FuncCall/SwapFuncCallArgumentsRector.php

This file was deleted.

30 changes: 0 additions & 30 deletions rules/Arguments/ValueObject/SwapFuncCallArguments.php

This file was deleted.

5 changes: 5 additions & 0 deletions rules/Php80/Rector/Class_/AnnotationToAttributeRector.php
Expand Up @@ -32,6 +32,7 @@
use Rector\Php80\ValueObject\DoctrineTagAndAnnotationToAttribute;
use Rector\PhpAttribute\NodeFactory\PhpAttributeGroupFactory;
use Rector\PhpDocParser\PhpDocParser\PhpDocNodeTraverser;
use Rector\RectorGenerator\Exception\ConfigurationException;
use Rector\VersionBonding\Contract\MinPhpVersionInterface;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
Expand Down Expand Up @@ -118,6 +119,10 @@ public function getNodeTypes(): array
*/
public function refactor(Node $node): ?Node
{
if ($this->annotationsToAttributes === []) {
throw new ConfigurationException(sprintf('The "%s" rule requires configuration.', self::class));
}

$phpDocInfo = $this->phpDocInfoFactory->createFromNode($node);
if (! $phpDocInfo instanceof PhpDocInfo) {
return null;
Expand Down
Expand Up @@ -3,10 +3,14 @@
declare(strict_types=1);

use Rector\Config\RectorConfig;

use Rector\Php80\Rector\Class_\AnnotationToAttributeRector;
use Rector\Php80\Rector\Class_\ClassPropertyAssignToConstructorPromotionRector;
use Rector\Php80\ValueObject\AnnotationToAttribute;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->rule(ClassPropertyAssignToConstructorPromotionRector::class);
$rectorConfig->rule(AnnotationToAttributeRector::class);
$rectorConfig->ruleWithConfiguration(AnnotationToAttributeRector::class, [
new AnnotationToAttribute('OldTag', 'NewAttribute'),
]);
};
21 changes: 18 additions & 3 deletions utils/Command/OutsideAnySetCommand.php
Expand Up @@ -35,10 +35,25 @@ protected function execute(InputInterface $input, OutputInterface $output): int

$rectorClassesOutsideAnySet = array_diff($existingRectorClasses, $setDefinedRectorClasses);

sort($rectorClassesOutsideAnySet);
// skip transform rules, as designed for custom use
$filteredRectorClassesOutsideAnySet = array_filter(
$rectorClassesOutsideAnySet,
static function (string $rectorClass): bool {
if (str_contains($rectorClass, '\\Transform\\')) {
return false;
}

$this->symfonyStyle->listing($rectorClassesOutsideAnySet);
$this->symfonyStyle->warning(sprintf('%d rules is outside any set', count($rectorClassesOutsideAnySet)));
// skip renaming rules too, as designed for custom use
return ! str_contains($rectorClass, '\\Renaming\\');
}
);

sort($filteredRectorClassesOutsideAnySet);

$this->symfonyStyle->listing($filteredRectorClassesOutsideAnySet);
$this->symfonyStyle->warning(
sprintf('%d rules is outside any set', count($filteredRectorClassesOutsideAnySet))
);

return self::SUCCESS;
}
Expand Down

0 comments on commit 9e8ed6c

Please sign in to comment.