Skip to content

Constants are marked as unused elements #1587

@DmitryFurs

Description

@DmitryFurs

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

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions