Problem/Motivation

I have a codebase that fails during a phpcbf run due to an error with nested_parenthesis. When I comment out the code in vendor/drupal/coder/coder_sniffer/DrupalPractice/Sniffs/General/OptionsTSniff.php, the error goes away (temporarily). Once I get all the way through the phpcbf run (without errors) and uncomment the nested_parenthesis code, it no longer causes errors. It sounds like maybe the "other" fixes resolve whatever is causing the nested_parenthesis rules to fail?

The error I see is:

PHP Fatal error:  Uncaught PHP_CodeSniffer\Exceptions\RuntimeException: Undefined index: nested_parenthesis in /vendor/drupal/coder/coder_sniffer/DrupalPractice/Sniffs/General/OptionsTSniff.php on line 69 in /vendor/squizlabs/php_codesniffer/src/Runner.php:606
Stack trace:
#0 /vendor/drupal/coder/coder_sniffer/DrupalPractice/Sniffs/General/OptionsTSniff.php(69): PHP_CodeSniffer\Runner->handleErrors(8, 'Undefined index...', '...', 69, Array)
#1 /vendor/squizlabs/php_codesniffer/src/Files/File.php(496): DrupalPractice\Sniffs\General\OptionsTSniff->process(Object(PHP_CodeSniffer\Files\LocalFile), 88)
#2 /vendor/squizlabs/php_codesniffer/src/Files/LocalFile.php(91): PHP_CodeSniffer\Files\File->process()
#3 /vendor/squizlabs/php_codesniffer/src/Fixer.php(174): PHP_CodeSniffer\Files\LocalFile->proces in /vendor/squizlabs/php_codesniffer/src/Runner.php on line 606

This undefined index seems to be thrown when both the long and short array declarations are used. For example:

$form['example'] = [
  '#options' => array(
    1 => t('Enabled'),
    0 => 'Disabled',
  ),
];

Comments

mikemadison created an issue. See original summary.

mikemadison’s picture

Issue summary: View changes
arkener’s picture

Status: Active » Needs review

This undefined index seems to be thrown when both the long and short array declarations are used. For example:

$form['example'] = [
  '#options' => array(
    1 => t('Enabled'),
    0 => 'Disabled',
  ),
];

This also explains why this error is fixed after a full phpcbf run, as the DisallowLongArraySyntax rule will convert all long arrays to short arrays. I've also just noticed that the OptionT rule doesn't have support for short arrays for which I will be creating a separate issue.

I've added a PR to fix this undefined error: https://github.com/pfrenssen/coder/pull/93

klausi’s picture

Issue summary: View changes
Status: Needs review » Needs work

thanks, 2 very minor things in the pull request then we can merge!

arkener’s picture

Status: Needs work » Needs review

Somehow I completely overlooked these coding standards issues. They've now been fixed.

klausi’s picture

Version: 8.x-3.7 » 8.x-3.x-dev
Status: Needs review » Fixed

Merged, thank you!

  • Arkener authored b5e2bae on 8.x-3.x
    fix(OptionsT): Add check for nested_parenthesis (#3117463 by Arkener)
    
    

Status: Fixed » Closed (fixed)

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