Some Drupal.Classes.FullyQualifiedNamespace not caught by 2715741 issue

Created on 26 April 2017, over 7 years ago
Updated 15 February 2023, over 1 year ago

Problem/Motivation

When using "phpcs" I found some "hint" errors I believe are related to FullyQualifiedNamespace problem.

For example, I found this in 'core/lib/Drupal/Core/Entity/entity.api.php' file:
925 | ERROR | [ ] Expected type hint "EntityInterface"; found
| | "Drupal\Core\Entity\EntityInterface" for
| | $entity

But the file does not have any "use Drupal\Core\Entity\EntityInterface;" statement.

Taking a closer look in this file I realize that another class sometimes uses a FQN sometimes don't.

Example:
"if ($entity instanceof \Drupal\Core\Entity\ContentEntityInterface && !$entity->foo->value) {"

and
"if ($entity instanceof ContentEntityInterface && $entity->isTranslatable()) {"

Then I started looking for similar problems in other places and got:

find . -type f \( -name '*.inc' -or -name '*.module' -or -name '*.php' \) -exec grep -e '\((\|, \|instanceof \)Drupal\\Core' {} \+ | cut -f1 -d':' | uniq
./core/modules/tour/tour.api.php
./core/modules/quickedit/quickedit.api.php
./core/lib/Drupal/Core/Database/database.api.php
./core/lib/Drupal/Core/Database/StatementInterface.php
./core/lib/Drupal/Core/StreamWrapper/StreamWrapperManagerInterface.php
./core/lib/Drupal/Core/Entity/entity.api.php

I propose to use the "use Drupal\Core\;" statement to fix this problem.

Steps to reproduce

TBA

Proposed resolution

Either adjust Drupal.Classes.FullyQualifiedNamespace to identify problems in *.api.php or create a new sniff?

Remaining tasks

Determine what sniff reported the errors above
TBA

📌 Task
Status

Active

Version

10.1

Component
Other 

Last updated about 3 hours ago

Created by

🇧🇷Brazil hgunicamp

Live updates comments and jobs are added and updated live.
  • Coding standards

    It involves compliance with, or the content of coding standards. Requires broad community agreement.

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.

  • The Needs Review Queue Bot tested this issue. It either no longer applies to Drupal core, or fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

    Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.

    Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

  • Status changed to Active over 1 year ago
  • 🇳🇿New Zealand quietone

    This does not need work on the patch right now. A solution needs to be discussed, see the IS and #11.

Production build 0.71.5 2024