Import classes used in annotations

Created on 17 March 2016, about 9 years ago
Updated 11 April 2024, about 1 year ago

This came out of a bug report against code sniffer: #2625312: Drupal.Classes.UnusedUseStatement doesn't recognize annotations β†’

When you use annotations in a class, some IDEs provide autocomplete against the annotation itself. PHPStorm will even detect the property type (string, array, etc) and fill in quotes or braces. However, PHPStorm needs the annotation class to be imported. This in turn throws a standards error for an unused import.

It looks like Symfony 2 imports classes that are used in annotations, but Doctrine doesn't. I don't see any downside to importing them, given that the annotation classes are probably loaded on a given request anyways.

Could we either:

  • Flip the standard around, so that all annotations should be imported to a class
  • Remove the inspection for unused imports for any class that has 'Annotation' in it's namespace?
✨ Feature request
Status

Closed: outdated

Component

Coding Standards

Created by

πŸ‡¨πŸ‡¦Canada deviantintegral

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡ΊπŸ‡ΈUnited States dww

    We reviewed this in the coding standards meeting this week.

    • Seems that the "problem" has mostly solved itself.
    • Meanwhile, core is moving to replace all annotations with attributes.
    • So there was broad agreement to close this one as outdated.

    Thanks,
    -Derek

  • πŸ‡©πŸ‡ͺGermany hermann77

    Fix for PHPStorm: install "Drupal Symfony Bridge" Plugin

Production build 0.71.5 2024