Skip to content

[DeadCode] Keep parent-delegating constructor when its docblock refines parameter types#8111

Merged
TomasVotruba merged 1 commit into
mainfrom
fix-keep-param-refining-delegating-ctor
Jun 29, 2026
Merged

[DeadCode] Keep parent-delegating constructor when its docblock refines parameter types#8111
TomasVotruba merged 1 commit into
mainfrom
fix-keep-param-refining-delegating-ctor

Conversation

@TomasVotruba

Copy link
Copy Markdown
Member

Bug

RemoveParentDelegatingConstructorRector removes a constructor that only calls parent::__construct(...) with the same arguments — but it ignores the docblock. When the child constructor exists purely to refine parameter types via PHPDoc, removing it silently drops that type information.

Reported from webonyx/graphql-php, which had to skip the rule on CustomScalarType.php (commit 5da64b9, "Ignore overzealous rector"):

class CustomScalarType extends ScalarType
{
    /**
     * @param array<string, mixed> $config
     *
     * @phpstan-param CustomScalarConfig $config
     */
    public function __construct(array $config)
    {
        parent::__construct($config);
    }
}

The native signature (array $config) matches the parent, so the rule considered the constructor redundant and removed it — along with the @param array<string, mixed> / @phpstan-param CustomScalarConfig refinement. Callers would then be type-checked against the parent's looser array type.

Fix

Skip removal when the constructor's docblock declares any parameter-type tag (@param, @phpstan-param, @psalm-param), since that refines types beyond the native signature.

Added fixture skip_param_refining_docblock.php.inc (no-change), which is fully removed without the guard.

@TomasVotruba

Copy link
Copy Markdown
Member Author

LGTM 👍

@TomasVotruba TomasVotruba merged commit 7026838 into main Jun 29, 2026
65 checks passed
@TomasVotruba TomasVotruba deleted the fix-keep-param-refining-delegating-ctor branch June 29, 2026 10:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant