You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
global_namespace_import ignores classes (and constants?) that exist in code but ain't detected by php-cs-fixer. My case relates to PHPStan array shapes (see example below) but the problem is probably general.
I assume php-cs-fixer can understand array shapes because the rule no_unused_imports does not remove the use statement.
Expected behaviour
Either analyse PHPStan array shapes or at least report (non zero exit code?) that a use statement for global class/constant exists but it was not found (by php cs fixer) inside the code.
@javaDeveloperKid please provide expected output, because from the report I just can't tell what's wrong. Used ./php-cs-fixer check --verbose --diff reproducer.php --rules='{"global_namespace_import":{"import_classes":false,"import_constants":false,"import_functions":false},"no_unused_imports":true}' for your snippet and got:
Should it be modified to createdAt: \DateTimeImmutable? 🤷♂️
Expected behaviour
Either analyse PHPStan array shapes or at least report (non zero exit code?) that a use statement for global class/constant exists but it was not found (by php cs fixer) inside the code.
Fixer exits with non-zero code only if dry-run is used and fixable violation is found. The core concept of this tool is to report only what can be fixed, it does not report any kind of "warnings".
So it is related with #7674, FQCN fixer is quite complex as it has to parse a lot of different places, global_namespace_import should really reuse that logic.
Wirone
added
topic/fqcn
Fully Qualified Class Name usage and conversions
and removed
status/input required
For the issue to be confirmed or the PR to be process; additional input of the author is required
labels
Mar 19, 2024
Bug report
Description
global_namespace_import
ignores classes (and constants?) that exist in code but ain't detected by php-cs-fixer. My case relates to PHPStan array shapes (see example below) but the problem is probably general.I assume php-cs-fixer can understand array shapes because the rule
no_unused_imports
does not remove the use statement.Expected behaviour
Either analyse PHPStan array shapes or at least report (non zero exit code?) that a use statement for global class/constant exists but it was not found (by php cs fixer) inside the code.
Runtime version
3.51.0
Used command
fix
Configuration file
Code snippet that reproduces the problem
Expected
The text was updated successfully, but these errors were encountered: