Skip to content

Fix AddMissingVarNameFixer to handle intersection types in @var#33

Merged
TomasVotruba merged 1 commit into
mainfrom
tv-fix-var-name-intersection-type
Jul 2, 2026
Merged

Fix AddMissingVarNameFixer to handle intersection types in @var#33
TomasVotruba merged 1 commit into
mainfrom
tv-fix-var-name-intersection-type

Conversation

@TomasVotruba

Copy link
Copy Markdown
Member

Problem

AddMissingVarNameFixer skipped inline @var annotations with an intersection type:

/** @var MockObject&AbstractIntegration */
/** @phpstan-ignore classConstant.deprecatedClass */
$integration = $this->getMockBuilder(AbstractIntegration::class);

The variable name was never filled in.

Cause

VAR_WITHOUT_NAME_REGEX type char class [\\\\\w\|\[\]-]+ had no &, so intersection types failed to match. (The second docblock line below is not the blocker — getNextMeaningfulToken already skips it; a simple type with a docblock underneath fixed fine.)

Fix

Add & to the type char class. Now the annotation becomes:

/** @var MockObject&AbstractIntegration $integration */

New fixture intersection_type_with_docblock_below.php.inc covers the exact reported case.

phpstan / rector / ecs / phpunit all green.

The type char class in VAR_WITHOUT_NAME_REGEX lacked '&', so inline
@var with an intersection type (e.g. MockObject&AbstractIntegration)
was skipped and never got its variable name filled in.
@TomasVotruba

Copy link
Copy Markdown
Member Author

LGTM 👍

@TomasVotruba TomasVotruba merged commit 1540743 into main Jul 2, 2026
7 checks passed
@TomasVotruba TomasVotruba deleted the tv-fix-var-name-intersection-type branch July 2, 2026 13:10
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.

1 participant