Active
Project:
Coder
Version:
8.x-3.x-dev
Component:
Review/Rules
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
15 May 2019 at 16:36 UTC
Updated:
5 Jun 2020 at 20:17 UTC
Jump to comment: Most recent
In #2053489: Standardize on \Drupal throughout core, the core maintainers established best practice as always referencing the global Drupal object as \Drupal rather than Drupal, even when in a procedural or other context where it's not strictly necessary from a functional standpoint.
Since \Drupal is the explicit standard, I think Coder should have a sniff to enforce that.
Comments
Comment #2
cburschkaFor namespaced files, there is #3120001: Global namespace classes should be fully namespaced, which will flag any use statement importing a global class (eg
use Drupal;).This does not include non-namespaced files (eg procedural code), where global classes can be referenced without a use statement, by
\Classor byClass, where we want to standardize on the former.Comment #3
cburschkaWith #3120001: Global namespace classes should be fully namespaced merged, this issue's scope is limited to files that do not have a namespace (because files with a namespace can only use
Drupal::in combination withuse Drupal;which is now flagged).Now the remaining question is whether we want to apply this rule only to the
Drupalclass or to all non-namespaced classes (eg\InvalidArgumentExceptionand\ArrayAccess).