Skip to content
Snippets Groups Projects
Unverified Commit b5e2bae1 authored by Mitch Portier's avatar Mitch Portier Committed by GitHub
Browse files

fix(OptionsT): Add check for nested_parenthesis (#3117463 by Arkener)

parent 03b2b9e2
Branches
Tags
No related merge requests found
...@@ -13,7 +13,7 @@ use PHP_CodeSniffer\Files\File; ...@@ -13,7 +13,7 @@ use PHP_CodeSniffer\Files\File;
use PHP_CodeSniffer\Sniffs\Sniff; use PHP_CodeSniffer\Sniffs\Sniff;
/** /**
* Checks that values in #otions form arrays are translated. * Checks that values in #options form arrays are translated.
* *
* @category PHP * @category PHP
* @package PHP_CodeSniffer * @package PHP_CodeSniffer
...@@ -64,10 +64,14 @@ class OptionsTSniff implements Sniff ...@@ -64,10 +64,14 @@ class OptionsTSniff implements Sniff
} }
// We only search within the #options array. // We only search within the #options array.
$arrayToken = $phpcsFile->findNext(T_ARRAY, ($stackPtr + 1)); $arrayToken = $phpcsFile->findNext(T_ARRAY, ($stackPtr + 1));
$statementEnd = $tokens[$arrayToken]['parenthesis_closer']; $statementEnd = $tokens[$arrayToken]['parenthesis_closer'];
$nestestParenthesis = $tokens[$arrayToken]['nested_parenthesis']; $nestedParenthesis = [];
$nestestParenthesis[$tokens[$arrayToken]['parenthesis_opener']] = $tokens[$arrayToken]['parenthesis_closer']; if (isset($tokens[$arrayToken]['nested_parenthesis']) === true) {
$nestedParenthesis = $tokens[$arrayToken]['nested_parenthesis'];
}
$nestedParenthesis[$tokens[$arrayToken]['parenthesis_opener']] = $tokens[$arrayToken]['parenthesis_closer'];
// Go through the array by examining stuff after "=>". // Go through the array by examining stuff after "=>".
$arrow = $phpcsFile->findNext(T_DOUBLE_ARROW, ($stackPtr + 1), $statementEnd, false, null, true); $arrow = $phpcsFile->findNext(T_DOUBLE_ARROW, ($stackPtr + 1), $statementEnd, false, null, true);
...@@ -80,7 +84,7 @@ class OptionsTSniff implements Sniff ...@@ -80,7 +84,7 @@ class OptionsTSniff implements Sniff
&& strlen($tokens[$arrayValue]['content']) > 5 && strlen($tokens[$arrayValue]['content']) > 5
// Make sure that we don't check stuff in nested arrays within // Make sure that we don't check stuff in nested arrays within
// t() for example. // t() for example.
&& $tokens[$arrayValue]['nested_parenthesis'] === $nestestParenthesis && $tokens[$arrayValue]['nested_parenthesis'] === $nestedParenthesis
) { ) {
// We need to make sure that the string is the one and only part // We need to make sure that the string is the one and only part
// of the array value. // of the array value.
......
...@@ -23,3 +23,12 @@ $form['display']['show_thumbnail'] = array( ...@@ -23,3 +23,12 @@ $form['display']['show_thumbnail'] = array(
'0' => t('No', array(), array('context' => 'test')), '0' => t('No', array(), array('context' => 'test')),
), ),
); );
$form['display']['status'] = [
'#title' => t('Status', array(), array('context' => 'test')),
'#type' => 'select',
'#options' => array(
'1' => 'Enabled',
'0' => t('Disabled', array(), array('context' => 'test')),
),
];
...@@ -43,7 +43,10 @@ class OptionsTUnitTest extends CoderSniffUnitTest ...@@ -43,7 +43,10 @@ class OptionsTUnitTest extends CoderSniffUnitTest
*/ */
protected function getWarningList(string $testFile): array protected function getWarningList(string $testFile): array
{ {
return [14 => 1]; return [
14 => 1,
31 => 1,
];
}//end getWarningList() }//end getWarningList()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment