1

ECS = symplify/easy-coding-standard
I am getting an message when running ECS:

Unused variable $validator.
(SlevomatCodingStandard\Sniffs\Variables\UnusedVariableSniff.UnusedVariable)

For this code:

// phpcs:ignore
// @codingStandardsIgnoreLine
foreach ($this->rules as $attribute => $validator) {

I did try using the suppress comments in different setup:

  • only one of them
  • on the same line as the message suggests
  • in different order
  • by targeting specific warning:
    • SlevomatCodingStandard\Sniffs\Variables\UnusedVariableSniff.UnusedVariable
    • SlevomatCodingStandard.Variables.UnusedVariable

Does any one know if ECS supports inline suppress comments?
In the ECS documentation I see it's only possible to suppress whole file.

PS. I know I can use array_keys(), but the goal in this case is to suppress the warnings, as in the future it can be a different one.

Nigel Ren
  • 56,122
  • 11
  • 43
  • 55
simpleman
  • 205
  • 1
  • 2
  • 7

1 Answers1

2

Or... as variant add rule to config file easy-coding-standard.yaml

services:
  SlevomatCodingStandard\Sniffs\Variables\UnusedVariableSniff:
    ignoreUnusedValuesWhenOnlyKeysAreUsedInForeach: true
anydasa
  • 2,616
  • 1
  • 15
  • 13