Skip to content

Add configurable PreferInlineTraitRule to spot lazy traits - #330

Merged
TomasVotruba merged 1 commit into
mainfrom
prefer-inline-trait-rule
Sep 29, 2026
Merged

TomasVotruba merged 1 commit into
mainfrom
prefer-inline-trait-rule

Conversation

@TomasVotruba

Copy link
Copy Markdown
Member

Adds an opt-in PHPStan rule that spots traits used only a few times across the project - good candidates to inline into their single user, empowering IDE, Rector and PHPStan.

Uses two collectors to count trait definitions and use SomeTrait; usages across files, then reports traits used at most maxUsage times (default 2).

Disabled by default. Enable via:

parameters:
    symplify:
        inlineTrait: true

This replaces the standalone spot-lazy-traits command in rector/swiss-knife with a native PHPStan rule that runs in the existing analysis pass and resolves real trait FQNs.

Note: pre-existing PHPStan error in CommandMustHaveAsCommandAttributeRule.php:71 is unrelated to this PR and already present on main.

@TomasVotruba
TomasVotruba merged commit cbb35f2 into main Sep 29, 2026
8 checks passed
@TomasVotruba
TomasVotruba deleted the prefer-inline-trait-rule branch September 29, 2026 17:01
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