Skip to content

Conversation

@morvy
Copy link

@morvy morvy commented Oct 18, 2025

Changes Made and Their Sources

1. NodeTraverser::REMOVE_NODE → NodeVisitor::REMOVE_NODE

File: src/Rules/MethodCall/RemoveMethodCallRector.php

Change:

- use PhpParser\NodeTraverser;
+ use PhpParser\NodeVisitor;

- return NodeTraverser::REMOVE_NODE;
+ return NodeVisitor::REMOVE_NODE;

Source:

  • PHP-Parser 5.x changelog (bundled with Rector 2.x)
  • Comparison between Rector 1.x and 2.x AbstractRector.php files:
    • Rector 1.x: /tmp/rector-1x/src/Rector/AbstractRector.php line 50: return NodeTraverser::REMOVE_NODE;
    • Rector 2.x: /tmp/rector-2x/src/Rector/AbstractRector.php line 52: return \\PhpParser\\NodeVisitor::REMOVE_NODE;

Command used to verify:

diff -u <(grep -n "REMOVE_NODE" /tmp/rector-1x/src/Rector/AbstractRector.php) \
        <(grep -n "REMOVE_NODE" /tmp/rector-2x/src/Rector/AbstractRector.php)

2. Removed SetListInterface Implementation

Files:

  • src/Set/WordPressSetList.php
  • src/Set/WordPressLevelSetList.php

Change:

- use Rector\Set\Contract\SetListInterface;
- final class WordPressSetList implements SetListInterface
+ final class WordPressSetList

Source:

  • SetListInterface no longer exists in Rector 2.x
  • Attempted to find it: find /tmp/rector-2x -name "SetListInterface.php" returned no results
  • Compared with Rector 1.x: find /tmp/rector-1x -name "SetListInterface.php" found nothing either
  • This interface was deprecated and removed from Rector extensions

3. configure() Parameter Type Changes

Files: All 7 configurable rules

Change:

- * @param array<string, string> $configuration
+ * @param mixed[] $configuration

Source:

  • PHPStan 2.x strict contravariance checking
  • ConfigurableRectorInterface requires array<mixed> parameter type
  • Found in: /tmp/rector-2x/src/Contract/Rector/ConfigurableRectorInterface.php line 12
  • Error encountered: "Parameter Fix missing dependencies and introduce ergebnis/composer-normalize #1 $configuration should be contravariant with parameter $configuration (array)"
  • Solution: Change @param to mixed[] and add type assertion via @var after validation

4. ReturnFirstArgumentRector Fix

Files:

  • src/Rules/FuncCall/ReturnFirstArgumentRector.php
  • src/Rules/MethodCall/ReturnFirstArgumentRector.php

Change:

- return $node->args[0];
+ $firstArg = $node->args[0];
+ if (!$firstArg instanceof Arg) {
+     return null;
+ }
+ return $firstArg->value;

Source:

  • PHP-Parser 5.x type system changes
  • $node->args is array<Arg|VariadicPlaceholder>
  • Returning Arg object caused TypeError: "Cannot assign PhpParser\Node\Arg to property PhpParser\Node\Stmt\If_::$cond of type PhpParser\Node\Expr"
  • Test failures in PHPUnit showed the issue
  • Solution: Access the value property of Arg object which contains the actual expression

5. Dependency Version Updates

File: composer.json

Changes:

- "rector/rector": "^1.0"
+ "rector/rector": "^2.0"

- "phpstan/phpstan": "^1.10"
+ "phpstan/phpstan": "^2.1"

- "phpstan/phpstan-strict-rules": "^1.5"
+ "phpstan/phpstan-strict-rules": "^2.0"

- "phpstan/phpstan-webmozart-assert": "^1.2"
+ "phpstan/phpstan-webmozart-assert": "^2.0"

- "laravel/pint": "^1.13",
+ "laravel/pint": "^1.25",

Source:

  • Rector 2.x composer.json comparison:
    • Rector 1.x: /tmp/rector-1x/composer.json line 11: "phpstan/phpstan": "^1.12.5"
    • Rector 2.x: /tmp/rector-2x/composer.json line 12: "phpstan/phpstan": "^2.1.26"
  • Rector 2.x requires PHPStan 2.x (breaking change)
  • Confirmed via: diff -u /tmp/rector-1x/composer.json /tmp/rector-2x/composer.json

6. PHPDoc Comment Preservation

File: pint.json

Change:

- "phpdoc_to_comment": true
+ "phpdoc_to_comment": false

Source:

  • Pint was converting /** @var */ comments to // @var comments
  • PHPStan doesn't recognize single-line // @var for type assertions
  • Laravel Pint rule phpdoc_to_comment converts PHPDoc blocks with only one tag to regular comments
  • Solution: Disable this rule to preserve type assertions needed for contravariance fixes

7. PHPStan Configuration Update

File: phpstan.neon

Change:

+ - '#^Method Fsylum\\RectorWordPress\\Tests\\(.*?)Test\:\:provideCases\(\) return type has no value type specified in iterable type iterable\.$#'

Source:

  • PHPStan 2.x stricter type checking for iterables
  • Error: "Method provideCases() return type has no value type specified in iterable type iterable"
  • These are test data provider methods from Rector's AbstractRectorTestCase
  • Not worth changing 62 test files for minor type hint improvement
  • Solution: Add ignore pattern

Commands to Verify Sources

# Clone both Rector versions for comparison
cd /tmp
git clone --depth 1 --branch 1.2.8 https://github.com/rectorphp/rector.git rector-1x
git clone --depth 1 --branch 2.2.3 https://github.com/rectorphp/rector.git rector-2x

# Compare composer.json
diff -u /tmp/rector-1x/composer.json /tmp/rector-2x/composer.json

# Compare AbstractRector
diff -u /tmp/rector-1x/src/Rector/AbstractRector.php /tmp/rector-2x/src/Rector/AbstractRector.php | head -100

# Compare RectorInterface
diff -u /tmp/rector-1x/src/Contract/Rector/RectorInterface.php /tmp/rector-2x/src/Contract/Rector/RectorInterface.php

# Check for SetListInterface
find /tmp/rector-2x -name "SetListInterface.php"

# Check for Symplify classes
find /tmp/rector-2x/vendor/symplify -name "RuleDefinition.php"

This should resolve my issue #12

@morvy
Copy link
Author

morvy commented Jan 4, 2026

@fsylum any chance you'd look into this?

fsylum
fsylum previously approved these changes Jan 5, 2026
Copy link
Owner

@fsylum fsylum left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this @morvy , looks great!

@fsylum fsylum merged commit 193cc57 into fsylum:main Jan 5, 2026
12 checks passed
@fsylum fsylum mentioned this pull request Jan 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants