rectorphp/rector · error · ShouldNotHappenException

"%s" is deprecated, as data provider docblock typing is not

Error message

"%s" is deprecated, as data provider docblock typing is not relevant to code quality

What it means

Rector\TypeDeclarationDocblocks\Rector\ClassMethod\AddParamArrayDocblockFromDataProviderRector is deprecated: refactor() throws Rector\Exception\ShouldNotHappenException on the first Class_ node. The rule added @param array<...> typing to PHPUnit test methods fed by @dataProvider methods, but how a test's parameters are typed has no effect on production code quality, so the generated docblocks were noise.

Source

Thrown at rules/TypeDeclarationDocblocks/Rector/ClassMethod/AddParamArrayDocblockFromDataProviderRector.php:71

        yield [['Tom', 'John']];
    }
}
CODE_SAMPLE
)]);
    }
    /**
     * @return array<class-string<Node>>
     */
    public function getNodeTypes(): array
    {
        return [Class_::class];
    }
    /**
     * @param Class_ $node
     */
    public function refactor(Node $node): ?Node
    {
        throw new ShouldNotHappenException(sprintf('"%s" is deprecated, as data provider docblock typing is not relevant to code quality', self::class));
    }
}

View on GitHub (pinned to 408fcb0ff1)

Solutions

  1. Remove AddParamArrayDocblockFromDataProviderRector from rector.php.
  2. If a specific test benefits from a @param docblock, add it manually.
  3. Keep provider typing conventions in your test style guide rather than automating them.

Example fix

// before (rector.php)
->withRules([AddParamArrayDocblockFromDataProviderRector::class])

// after (rector.php) - rule removed; no replacement needed
Defensive patterns

Strategy: validation

Validate before calling

use Rector\TypeDeclarationDocblocks\Rector\ClassMethod\AddParamArrayDocblockFromDataProviderRector;

$rules = [/* your list */ AddParamArrayDocblockFromDataProviderRector::class];
if (in_array(AddParamArrayDocblockFromDataProviderRector::class, $rules, true)) {
    throw new InvalidArgumentException('Rule deprecated; data-provider typing is not a code-quality concern');
}

Try / catch

try {
    exit($rectorApplication->run());
} catch (\Rector\Exception\ShouldNotHappenException $e) {
    if (str_contains($e->getMessage(), 'AddParamArrayDocblockFromDataProviderRector')) {
        fwrite(STDERR, 'Remove the rule; it only churned PHPUnit test files.' . PHP_EOL);
        exit(1);
    }
    throw $e;
}

Prevention

When it happens

Trigger: The rule is still listed in rector.php and rector visits any class (typically a PHPUnit test case); refactor() throws on the first Class_ node.

Common situations: Bulk rule lists built to 'type everything'; CI failing on the first test class after a rector upgrade; test-suite configs kept separate that still reference the rule.

Related errors


AI-assisted analysis of rectorphp/rector@408fcb0ff1 (2026-08-21). Data as JSON: /api/errors/6ed28091b14b324a. Report an issue: GitHub.