magento / magento/magento2-phpstorm-plugin

Constants are marked as unused elements

Open
#1,587 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Advanced good first issue Priority: P3
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

  1. Create any class with a public constant
  2. Use this constant in di.xml as an argument with xsi:type="const"
  3. Go back to your class
  4. 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

image

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.

image

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.