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

Dane Powell created an issue.

cburschka’s picture

For 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 \Class or by Class, where we want to standardize on the former.

cburschka’s picture

With #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 with use Drupal; which is now flagged).

Now the remaining question is whether we want to apply this rule only to the Drupal class or to all non-namespaced classes (eg \InvalidArgumentException and \ArrayAccess).