Use ::class instead of string literals in plugin managers

Created on 17 December 2024, 4 months ago

Problem/Motivation

I found plenty of plugin managers which use string literals for class names.
These should use ::class instead.

Steps to reproduce

Proposed resolution

Use ::class to refer to classes and interfaces.
For now the scope is plugin managers.

In case of name clash of the class alias (e.g. attribute vs annotation) we can use other shortcuts like `Annotation\Something`, where we might import the respective Annotation namespace.

Remaining tasks

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

πŸ“Œ Task
Status

Active

Version

11.0 πŸ”₯

Component

plugin system

Created by

πŸ‡©πŸ‡ͺGermany donquixote

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

Merge Requests

Comments & Activities

  • Issue created by @donquixote
  • Pipeline finished with Failed
    4 months ago
    Total: 161s
    #370590
  • Pipeline finished with Failed
    4 months ago
    Total: 118s
    #370606
  • πŸ‡©πŸ‡ͺGermany donquixote

    In case of name clash of the class alias (e.g. attribute vs annotation) we can use other shortcuts like `Annotation\Something`, where we might import the respective Annotation namespace.

    Too bad...

    Namespaced classes/interfaces/traits should be referenced with use statements

    Alternative is to use an alias.

    An example where the namespace import is used is Drush commands, where we have `use Drush\Attributes as CLI;` and then `#[CLI\Command(...)]`.

  • Pipeline finished with Failed
    4 months ago
    Total: 1437s
    #371132
  • Pipeline finished with Success
    4 months ago
    Total: 1831s
    #371363
  • Pipeline finished with Failed
    4 months ago
    Total: 485s
    #371455
  • πŸ‡¨πŸ‡­Switzerland berdir Switzerland

    > I believe part of the reason that the Annotation class references weren't changed to ::class strings was that they were going to be gone with the removal of annotation discovery anyway, but since not all the plugins have been converted, it's probably going to be a while for that.

    Exactly this. That was done on purpose, as we otherwise have two classes with the same name that we have to alias. That means we also need to adjust the use statements when we remove tem, which will make the cleanup more complex, with more risk of conflicts with other issues.

  • Pipeline finished with Failed
    4 months ago
    Total: 508s
    #372963
  • πŸ‡©πŸ‡ͺGermany donquixote

    Exactly this. That was done on purpose, as we otherwise have two classes with the same name that we have to alias.

    I removed the questionable commit.

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

    Appear to be some open threads. Believe it’s close

  • πŸ‡©πŸ‡ͺGermany donquixote

    I removed imports reordering in those files where no new imports are added.

  • Pipeline finished with Failed
    4 months ago
    Total: 717s
    #385518
  • Looks like everything was addressed. PHP Unit Build job needs a re-run and we're probably there.

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

    So applied the MR and did a search for "$namespaces, $module_handler, 'Drupal\Core\" to make sure those were converted and all instances were.

    @godotislate there is 1 thread I wasn't 100% should be resolved but your comment in #10 made think it maybe could? Could you close it.

    There are 2 threads but really it's 1.

    Rest of the feedback appears to be addressed so going to mark it.

  • @godotislate there is 1 thread I wasn't 100% should be resolved but your comment in #10 made think it maybe could? Could you close it.

    It's not my MR, so I can't close it. But the question was resolved.

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

    Thanks for checking!

  • πŸ‡¬πŸ‡§United Kingdom alexpott πŸ‡ͺπŸ‡ΊπŸŒ

    Committed 84af964 and pushed to 11.x. Thanks!

    • alexpott β†’ committed 84af9646 on 11.x
      Issue #3494360 by donquixote, smustgrave, godotislate, berdir: Use ::...
  • Status changed to Fixed about 2 months ago
  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024