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
Comment #2
mikemadison commentedComment #3
arkener commentedThis undefined index seems to be thrown when both the long and short array declarations are used. For example:
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
Comment #4
klausithanks, 2 very minor things in the pull request then we can merge!
Comment #5
arkener commentedSomehow I completely overlooked these coding standards issues. They've now been fixed.
Comment #6
klausiMerged, thank you!