Skip to content

AnnotationToAttributeRector fails with rector 2.8: PhpDocNodeTraverser was removed #114

Open

Description

@AndyScherzinger

🤖 Description is full AI - for transparency

Description

AnnotationToAttributeRector cannot run with rector/rector 2.8, which removed Rector\PhpDocParser\PhpDocParser\PhpDocNodeTraverser. The rule imports that class in src/Rector/AnnotationToAttributeRector.php and instantiates it in createAttributeGroups():

  • line 45: use Rector\PhpDocParser\PhpDocParser\PhpDocNodeTraverser;
  • line 183: $phpDocNodeTraverser = new PhpDocNodeTraverser();
  • line 228: return PhpDocNodeTraverser::NODE_REMOVE;

Because composer.json requires rector/rector: ^2.0.4, Composer resolves 2.8.x by default, and every analysed file then fails with a system error. Rector aborts the whole run once 50 of them accumulate, so the result is not a few skipped files but no analysis at all:

 [ERROR] Could not process "lib/Activity/SettingCheck.php" file, due to:
         "System error: "Class "Rector\PhpDocParser\PhpDocParser\PhpDocNodeTraverser" not found"
         Run Rector with "--debug" option and post the report here: https://github.com/rectorphp/rector/issues/new". On line: 183

 [ERROR] Could not process some files, due to:
         "Reached system errors count limit of 50, exiting...".

Steps to reproduce

  1. In a project using this package, require rector/rector:2.8.3 alongside nextcloud/rector:v0.5.2 (the default resolution today, since ^2.0.4 allows it).
  2. Run vendor/bin/rector --dry-run over any PHP file.
  3. Every file fails with the system error above.

Minimal check without running Rector at all:

rector/rector 2.8.3 → class_exists('Rector\PhpDocParser\PhpDocParser\PhpDocNodeTraverser') === false
rector/rector 2.7.0 → true

Expected behavior

The rule runs against supported Rector versions, or composer.json states the versions it actually supports so Composer cannot resolve an incompatible one.

Screenshots or output

In rector 2.7.0 the class is at src/PhpDocParser/PhpDocParser/PhpDocNodeTraverser.php. In 2.8.3 that file no longer exists. The nearest equivalents are:

  • PHPStan\PhpDocParser\Ast\NodeTraverser (vendored with rector 2.8.3), with the same constant values but REMOVE_NODE where the old class had NODE_REMOVE, and a visitor-based API rather than traverseWithCallable().
  • Rector\PhpDocParser\PhpDocParser\PhpDocNodeVisitor\CallablePhpDocNodeVisitor, which still exists in 2.8.3 and takes a callable, so the callback in createAttributeGroups() could likely be kept as is.

I have not attempted the port, so please treat the above as a pointer rather than a proposed patch. Note the constant rename in particular — a mechanical find and replace of the class name alone would silently change behaviour at the NODE_REMOVE call site.

Environment details

  • version of this package: v0.5.2 (and current main, whose last commit predates rector 2.8)
  • rector/rector: 2.8.0 through 2.8.3 (2.8.0 released 2026-10-26)
  • PHP version: 8.3.6
  • OS: Ubuntu (WSL2) and ubuntu-latest GitHub runners

Additional context

This breaks CI for consumers rather than just local runs. In nextcloud/tables the Rector job started failing on main after an automated dependency bump re-resolved the bin lock from rector 2.7.0 to 2.8.3, which made every open pull request show a red check unrelated to its own changes. I have worked around it there by holding rector at ~2.7.0 (nextcloud/tables#3209), but that is a stopgap: any project using this package with the published ^2.0.4 constraint hits the same wall as soon as its lock is refreshed.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions