Loading coder_sniffer/DrupalPractice/Sniffs/General/OptionsTSniff.php +10 −6 Original line number Diff line number Diff line Loading @@ -13,7 +13,7 @@ use PHP_CodeSniffer\Files\File; 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 * @package PHP_CodeSniffer Loading Loading @@ -66,8 +66,12 @@ class OptionsTSniff implements Sniff // We only search within the #options array. $arrayToken = $phpcsFile->findNext(T_ARRAY, ($stackPtr + 1)); $statementEnd = $tokens[$arrayToken]['parenthesis_closer']; $nestestParenthesis = $tokens[$arrayToken]['nested_parenthesis']; $nestestParenthesis[$tokens[$arrayToken]['parenthesis_opener']] = $tokens[$arrayToken]['parenthesis_closer']; $nestedParenthesis = []; 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 "=>". $arrow = $phpcsFile->findNext(T_DOUBLE_ARROW, ($stackPtr + 1), $statementEnd, false, null, true); Loading @@ -80,7 +84,7 @@ class OptionsTSniff implements Sniff && strlen($tokens[$arrayValue]['content']) > 5 // Make sure that we don't check stuff in nested arrays within // 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 // of the array value. Loading coder_sniffer/DrupalPractice/Test/General/OptionsTUnitTest.inc +9 −0 Original line number Diff line number Diff line Loading @@ -23,3 +23,12 @@ $form['display']['show_thumbnail'] = array( '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')), ), ]; coder_sniffer/DrupalPractice/Test/General/OptionsTUnitTest.php +4 −1 Original line number Diff line number Diff line Loading @@ -43,7 +43,10 @@ class OptionsTUnitTest extends CoderSniffUnitTest */ protected function getWarningList(string $testFile): array { return [14 => 1]; return [ 14 => 1, 31 => 1, ]; }//end getWarningList() Loading Loading
coder_sniffer/DrupalPractice/Sniffs/General/OptionsTSniff.php +10 −6 Original line number Diff line number Diff line Loading @@ -13,7 +13,7 @@ use PHP_CodeSniffer\Files\File; 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 * @package PHP_CodeSniffer Loading Loading @@ -66,8 +66,12 @@ class OptionsTSniff implements Sniff // We only search within the #options array. $arrayToken = $phpcsFile->findNext(T_ARRAY, ($stackPtr + 1)); $statementEnd = $tokens[$arrayToken]['parenthesis_closer']; $nestestParenthesis = $tokens[$arrayToken]['nested_parenthesis']; $nestestParenthesis[$tokens[$arrayToken]['parenthesis_opener']] = $tokens[$arrayToken]['parenthesis_closer']; $nestedParenthesis = []; 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 "=>". $arrow = $phpcsFile->findNext(T_DOUBLE_ARROW, ($stackPtr + 1), $statementEnd, false, null, true); Loading @@ -80,7 +84,7 @@ class OptionsTSniff implements Sniff && strlen($tokens[$arrayValue]['content']) > 5 // Make sure that we don't check stuff in nested arrays within // 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 // of the array value. Loading
coder_sniffer/DrupalPractice/Test/General/OptionsTUnitTest.inc +9 −0 Original line number Diff line number Diff line Loading @@ -23,3 +23,12 @@ $form['display']['show_thumbnail'] = array( '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')), ), ];
coder_sniffer/DrupalPractice/Test/General/OptionsTUnitTest.php +4 −1 Original line number Diff line number Diff line Loading @@ -43,7 +43,10 @@ class OptionsTUnitTest extends CoderSniffUnitTest */ protected function getWarningList(string $testFile): array { return [14 => 1]; return [ 14 => 1, 31 => 1, ]; }//end getWarningList() Loading