magento / magento/magento2-phpstorm-plugin
Constants are marked as unused elements
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 463
- Forks
- 98
- Avg merge
- 1h 6m
- Merged PRs (30d)
- 3
Description
Describe the bug
Constants are marked as unused elements if they are used only in di.xml. During refactoring, such constants may be deleted, since the developer may forget to check the actual use of such constants, and even more so if there are many of them. The developer can simply trust the IDE and think that the constant is not really used anywhere and get rid of it.
To Reproduce
- Create any class with a public constant
- Use this constant in
di.xmlas an argument withxsi:type="const" - Go back to your class
- And check that the constant is grayed out and marked as
Unused element
Expected behavior
The constant must be marked as a used element and have the appropriate color
Screenshots
The constant BASE is highlighted in purple and marked as used, actually used in php code and in di.xml, Inlay Hints says that it is used in 5 different places.
The constant BASE_LABEL is highlighted in gray and marked as unused, actually used only in di.xml, Inlay Hints says that it is used in 1 place.
Please complete the following information:
- OS: MacOS
- PhpStorm version: 2023.1.2
- Plugin Version: 5.1.1
Additional context
If you activate Inlay Hints, the number of uses for this constant will be greater than 0, and when you click on 1 usage, the transition to di.xml on the line where this constant is actually used.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing how the plugin resolves PHP constants referenced from di.xml with xsi:type="const", then inspect the usage and unused-element highlighting path. Reproduce the case with a public constant used only in di.xml and compare it with a constant also referenced by PHP code. Done means the di.xml reference is recognized as a usage and the constant is no longer marked unused.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, php
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100