Skip to content

Conversation

@samsonasik
Copy link
Member

Fixes rectorphp/rector#9530

it seems unreliable detect true bool type on trait.

@samsonasik
Copy link
Member Author

Fixed 🎉 /cc @calebdw

@samsonasik
Copy link
Member Author

@TomasVotruba ready 👍

@calebdw
Copy link
Contributor

calebdw commented Dec 18, 2025

Thanks for looking into this, but skipping traits indiscriminately doesn't seem like the correct approach...

Maybe this is a bug in phpstan? What does it think the type is?

@samsonasik
Copy link
Member Author

PHPStan seems requires context that the trait used under some class so it can show the type used

https://phpstan.org/r/602e0b7d-009e-43f1-9a86-2be3d0e272f6

without the class that use it, it will show: Trait HasEvents is used zero times and is not analysed., that's seems how it unreliable as detected as true type.

@calebdw
Copy link
Contributor

calebdw commented Dec 18, 2025

without the class that use it, it will show: Trait HasEvents is used zero times and is not analysed., that's seems how it unreliable as detected as true type.

The trait is used in my project and phpstan does analyze it.
Phpstan is dumping the type as class-string|null...

Preventing this rule from running in all traits is going to make this rule much less useful

@samsonasik
Copy link
Member Author

This may requires set traitReflection as well at

$this->privatesAccessor->setPrivateProperty($traitContext, 'classReflection', $traitClassReflection);

but that will cause other tests errors, feel free to create alternative PR :)

@TomasVotruba
Copy link
Member

@samsonasik Looks good, thank you 👍

@TomasVotruba TomasVotruba merged commit 7d158ab into main Dec 18, 2025
58 checks passed
@TomasVotruba TomasVotruba deleted the skip-trait branch December 18, 2025 08:21
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.

Incorrect behavior of RemoveUnusedVariableAssignRector, RemoveDeadReturnRector, RemoveAlwaysTrueIfConditionRector, RemoveUnreachableStatementRector

4 participants