Loading coder_sniffer/Drupal/Sniffs/Arrays/ArraySniff.php +12 −3 Original line number Diff line number Diff line Loading @@ -28,6 +28,14 @@ class ArraySniff implements Sniff { /** * The limit that the length of a line should not exceed. * * @var integer */ public $lineLimit = 80; /** * Returns an array of tokens this test wants to listen for. * Loading Loading @@ -103,13 +111,14 @@ class ArraySniff implements Sniff if ($isInlineArray === true) { // Check if this array contains at least 3 elements and exceeds the 80 // character line length. if ($tokens[$tokens[$stackPtr][$parenthesisCloser]]['column'] > 80) { if ($tokens[$tokens[$stackPtr][$parenthesisCloser]]['column'] > $this->lineLimit) { $comma1 = $phpcsFile->findNext(T_COMMA, ($stackPtr + 1), $tokens[$stackPtr][$parenthesisCloser]); if ($comma1 !== false) { $comma2 = $phpcsFile->findNext(T_COMMA, ($comma1 + 1), $tokens[$stackPtr][$parenthesisCloser]); if ($comma2 !== false) { $error = 'If the line declaring an array spans longer than 80 characters, each element should be broken into its own line'; $phpcsFile->addError($error, $stackPtr, 'LongLineDeclaration'); $error = 'If the line declaring an array spans longer than %s characters, each element should be broken into its own line'; $data = [$this->lineLimit]; $phpcsFile->addError($error, $stackPtr, 'LongLineDeclaration', $data); } } } Loading coder_sniffer/Drupal/Test/Arrays/ArrayUnitTest.1.inc 0 → 100644 +18 −0 Original line number Diff line number Diff line <?php /** * @file * Tests array declarations. * phpcs:set Drupal.Arrays.Array lineLimit 100 */ $array = array( 'data' => 'my-data', 'animal' => 'squirrel', 'inline' => array(), 'inline1' => array('thisisaverylongstring', 'thisisaverylongstring'), 'inline2' => array('thisisaverylongstring', 'thisisaverylongstring', 'thisisaverylongstring'), 'inline3' => array('thisisaverylongstring', 'thisisaverylongstring', 'thisisaverylongstring', 'thisisaverylongstring'), 'inline4' => array('thisisaverylongstringwithallotoftext', 'thisisaverylongstringwithallotoftext'), 'inline_long_ok' => array('one', 'two', 'three', 'four', 'five', 'six', 'seven'), 'inline_long_nok' => array('one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten'), ); coder_sniffer/Drupal/Test/Arrays/ArrayUnitTest.php +37 −20 Original line number Diff line number Diff line Loading @@ -14,10 +14,14 @@ class ArrayUnitTest extends CoderSniffUnitTest * The key of the array should represent the line number and the value * should represent the number of errors that should occur on that line. * * @param string $testFile The name of the file being tested. * * @return array(int => int) */ public function getErrorList() public function getErrorList($testFile=null) { switch ($testFile) { case 'ArrayUnitTest.inc': return [ 13 => 1, 33 => 1, Loading @@ -25,6 +29,12 @@ class ArrayUnitTest extends CoderSniffUnitTest 88 => 1, 92 => 1, ]; case 'ArrayUnitTest.1.inc': return [ 14 => 1, 17 => 1, ]; } }//end getErrorList() Loading @@ -35,10 +45,14 @@ class ArrayUnitTest extends CoderSniffUnitTest * The key of the array should represent the line number and the value * should represent the number of warnings that should occur on that line. * * @param string $testFile The name of the file being tested. * * @return array(int => int) */ public function getWarningList() public function getWarningList($testFile=null) { switch ($testFile) { case 'ArrayUnitTest.inc': return [ 17 => 1, 22 => 1, Loading @@ -50,6 +64,9 @@ class ArrayUnitTest extends CoderSniffUnitTest 59 => 1, 76 => 1, ]; case 'ArrayUnitTest.1.inc': return []; } }//end getWarningList() Loading Loading
coder_sniffer/Drupal/Sniffs/Arrays/ArraySniff.php +12 −3 Original line number Diff line number Diff line Loading @@ -28,6 +28,14 @@ class ArraySniff implements Sniff { /** * The limit that the length of a line should not exceed. * * @var integer */ public $lineLimit = 80; /** * Returns an array of tokens this test wants to listen for. * Loading Loading @@ -103,13 +111,14 @@ class ArraySniff implements Sniff if ($isInlineArray === true) { // Check if this array contains at least 3 elements and exceeds the 80 // character line length. if ($tokens[$tokens[$stackPtr][$parenthesisCloser]]['column'] > 80) { if ($tokens[$tokens[$stackPtr][$parenthesisCloser]]['column'] > $this->lineLimit) { $comma1 = $phpcsFile->findNext(T_COMMA, ($stackPtr + 1), $tokens[$stackPtr][$parenthesisCloser]); if ($comma1 !== false) { $comma2 = $phpcsFile->findNext(T_COMMA, ($comma1 + 1), $tokens[$stackPtr][$parenthesisCloser]); if ($comma2 !== false) { $error = 'If the line declaring an array spans longer than 80 characters, each element should be broken into its own line'; $phpcsFile->addError($error, $stackPtr, 'LongLineDeclaration'); $error = 'If the line declaring an array spans longer than %s characters, each element should be broken into its own line'; $data = [$this->lineLimit]; $phpcsFile->addError($error, $stackPtr, 'LongLineDeclaration', $data); } } } Loading
coder_sniffer/Drupal/Test/Arrays/ArrayUnitTest.1.inc 0 → 100644 +18 −0 Original line number Diff line number Diff line <?php /** * @file * Tests array declarations. * phpcs:set Drupal.Arrays.Array lineLimit 100 */ $array = array( 'data' => 'my-data', 'animal' => 'squirrel', 'inline' => array(), 'inline1' => array('thisisaverylongstring', 'thisisaverylongstring'), 'inline2' => array('thisisaverylongstring', 'thisisaverylongstring', 'thisisaverylongstring'), 'inline3' => array('thisisaverylongstring', 'thisisaverylongstring', 'thisisaverylongstring', 'thisisaverylongstring'), 'inline4' => array('thisisaverylongstringwithallotoftext', 'thisisaverylongstringwithallotoftext'), 'inline_long_ok' => array('one', 'two', 'three', 'four', 'five', 'six', 'seven'), 'inline_long_nok' => array('one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten'), );
coder_sniffer/Drupal/Test/Arrays/ArrayUnitTest.php +37 −20 Original line number Diff line number Diff line Loading @@ -14,10 +14,14 @@ class ArrayUnitTest extends CoderSniffUnitTest * The key of the array should represent the line number and the value * should represent the number of errors that should occur on that line. * * @param string $testFile The name of the file being tested. * * @return array(int => int) */ public function getErrorList() public function getErrorList($testFile=null) { switch ($testFile) { case 'ArrayUnitTest.inc': return [ 13 => 1, 33 => 1, Loading @@ -25,6 +29,12 @@ class ArrayUnitTest extends CoderSniffUnitTest 88 => 1, 92 => 1, ]; case 'ArrayUnitTest.1.inc': return [ 14 => 1, 17 => 1, ]; } }//end getErrorList() Loading @@ -35,10 +45,14 @@ class ArrayUnitTest extends CoderSniffUnitTest * The key of the array should represent the line number and the value * should represent the number of warnings that should occur on that line. * * @param string $testFile The name of the file being tested. * * @return array(int => int) */ public function getWarningList() public function getWarningList($testFile=null) { switch ($testFile) { case 'ArrayUnitTest.inc': return [ 17 => 1, 22 => 1, Loading @@ -50,6 +64,9 @@ class ArrayUnitTest extends CoderSniffUnitTest 59 => 1, 76 => 1, ]; case 'ArrayUnitTest.1.inc': return []; } }//end getWarningList() Loading