Problem/Motivation

The sniff DrupalPractice.CodeAnalysis.VariableAnalysis.UnusedVariable fails on settings.php files, since they often declare variables such as $databases. We might all agree that settings.php is indeed a bit wrong in the way it handles variables, but given that it's the convention it seems like Coder shouldn't throw false positives on it.

Example where I believe this is failing inappropriately:

Steps to reproduce

Declare any variable such as $databases in settings.php and run phpcs on it with DrupalPractice ruleset.

Proposed resolution

Either exclude settings.php from this sniff somehow, or document a recommended workaround. Individuals can add // phpcs:ignore on their own but this seems hacky.

Remaining tasks

User interface changes

API changes

Data model changes

Comments

Dane Powell created an issue. See original summary.

danepowell’s picture

Issue summary: View changes
danepowell’s picture

Ahah... I think I figured out what's going on here. If you modify an existing array variable it works fine, it's only if you declare a new variable that the sniff complains, and I think everything you'd want to modify in settings.php is an array.

So instead of:

$databases = [
  'default' => [
    'default' => [
      // my custom db info
    ],
  ],
];

... one should instead do:

$databases['default']['default'] = [
  // my custom db info
];
danepowell’s picture

Status: Active » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.