diff --git a/CodeSniffer.conf b/CodeSniffer.conf index 7367e45b1b..ce37ce82be 100644 --- a/CodeSniffer.conf +++ b/CodeSniffer.conf @@ -1,4 +1,5 @@ 'Snap', ) ?> diff --git a/CodeSniffer/Standards/PEAR/Sniffs/Functions/FunctionDeclarationSniff.php b/CodeSniffer/Standards/PEAR/Sniffs/Functions/FunctionDeclarationSniff.php index 0442555e5f..f268a3352c 100644 --- a/CodeSniffer/Standards/PEAR/Sniffs/Functions/FunctionDeclarationSniff.php +++ b/CodeSniffer/Standards/PEAR/Sniffs/Functions/FunctionDeclarationSniff.php @@ -28,6 +28,11 @@ class PEAR_Sniffs_Functions_FunctionDeclarationSniff implements PHP_CodeSniffer_Sniff { + /** + * Whitespace characters req'd per indent level + * @var int + */ + public $indent = 4; /** * Returns an array of tokens this test wants to listen for. @@ -236,7 +241,7 @@ public function processMultiLineDeclaration(PHP_CodeSniffer_File $phpcsFile, $st }//end if }//end if - // Each line between the parenthesis should be indented 4 spaces. + // Each line between the parenthesis should be indented. $openBracket = $tokens[$stackPtr]['parenthesis_opener']; $lastLine = $tokens[$openBracket]['line']; for ($i = ($openBracket + 1); $i < $closeBracket; $i++) { @@ -249,7 +254,7 @@ public function processMultiLineDeclaration(PHP_CodeSniffer_File $phpcsFile, $st // as the function. $expectedIndent = $functionIndent; } else { - $expectedIndent = ($functionIndent + 4); + $expectedIndent = ($functionIndent + $this->indent); } // We changed lines, so this should be a whitespace indent token. @@ -260,7 +265,7 @@ public function processMultiLineDeclaration(PHP_CodeSniffer_File $phpcsFile, $st } if ($expectedIndent !== $foundIndent) { - $error = 'Multi-line function declaration not indented correctly; expected %s spaces but found %s'; + $error = 'Multi-line function declaration not indented correctly; expected %s whitespace characters but found %s'; $data = array( $expectedIndent, $foundIndent, diff --git a/CodeSniffer/Standards/PSR1/Sniffs/Classes/ClassDeclarationSniff.php b/CodeSniffer/Standards/PSR1/Sniffs/Classes/ClassDeclarationSniff.php index a6fbf1fa3c..508c3458aa 100644 --- a/CodeSniffer/Standards/PSR1/Sniffs/Classes/ClassDeclarationSniff.php +++ b/CodeSniffer/Standards/PSR1/Sniffs/Classes/ClassDeclarationSniff.php @@ -28,6 +28,11 @@ class PSR1_Sniffs_Classes_ClassDeclarationSniff implements PHP_CodeSniffer_Sniff { + /** + * Enforce namespaces for all classes? + * @var bool + */ + public $enforce_namespaces = true; /** * Returns an array of tokens this test wants to listen for. @@ -62,7 +67,7 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) $phpcsFile->addError($error, $nextClass, 'MultipleClasses'); } - if (version_compare(PHP_VERSION, '5.3.0') >= 0) { + if ($this->enforce_namespaces && version_compare(PHP_VERSION, '5.3.0') >= 0) { $namespace = $phpcsFile->findPrevious(T_NAMESPACE, ($stackPtr - 1)); if ($namespace === false) { $error = 'Each class must be in a namespace of at least one level (a top-level vendor name)'; diff --git a/CodeSniffer/Standards/PSR2/Sniffs/ControlStructures/SwitchDeclarationSniff.php b/CodeSniffer/Standards/PSR2/Sniffs/ControlStructures/SwitchDeclarationSniff.php index f51dd9143e..5e2459dd5e 100644 --- a/CodeSniffer/Standards/PSR2/Sniffs/ControlStructures/SwitchDeclarationSniff.php +++ b/CodeSniffer/Standards/PSR2/Sniffs/ControlStructures/SwitchDeclarationSniff.php @@ -28,6 +28,11 @@ class PSR2_Sniffs_ControlStructures_SwitchDeclarationSniff implements PHP_CodeSniffer_Sniff { + /** + * Whitespace characters req'd per indent level + * @var int + */ + public $indent = 4; /** * Returns an array of tokens this test wants to listen for. @@ -63,7 +68,7 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) $switch = $tokens[$stackPtr]; $nextCase = $stackPtr; - $caseAlignment = ($switch['column'] + 4); + $caseAlignment = ($switch['column'] + $this->indent); $caseCount = 0; $foundDefault = false; @@ -87,7 +92,7 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) } if ($tokens[$nextCase]['column'] !== $caseAlignment) { - $error = strtoupper($type).' keyword must be indented 4 spaces from SWITCH keyword'; + $error = strtoupper($type).' keyword must be indented from SWITCH keyword'; $phpcsFile->addError($error, $nextCase, $type.'Indent'); } @@ -123,7 +128,7 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) // Only need to check some things once, even if the // closer is shared between multiple case statements, or even // the default case. - if ($tokens[$nextCloser]['column'] !== ($caseAlignment + 4)) { + if ($tokens[$nextCloser]['column'] !== ($caseAlignment + $this->indent)) { $error = 'Terminating statement must be indented to the same level as the CASE body'; $phpcsFile->addError($error, $nextCloser, 'BreakIndent'); } diff --git a/CodeSniffer/Standards/Snap/ruleset.xml b/CodeSniffer/Standards/Snap/ruleset.xml new file mode 100644 index 0000000000..e33b59b9d7 --- /dev/null +++ b/CodeSniffer/Standards/Snap/ruleset.xml @@ -0,0 +1,37 @@ + + + The Snap Interactive coding standard. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +