Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Use public $indent variable instead of hardcoded 4 spaces. Allows for…

… better modularity when used in custom rulesets, such as extending PSR2 with modifications.
  • Loading branch information...
commit 0e058d91bb566371acb0c40b068d8df76563d126 1 parent c7e4be4
@asnyder asnyder authored
View
13 CodeSniffer/Standards/PSR2/Sniffs/ControlStructures/SwitchDeclarationSniff.php
@@ -30,6 +30,13 @@ class PSR2_Sniffs_ControlStructures_SwitchDeclarationSniff implements PHP_CodeSn
/**
+ * The number of spaces code should be indented.
+ *
+ * @var int
+ */
+ public $indent = 4;
+
+ /**
* Returns an array of tokens this test wants to listen for.
*
* @return array
@@ -63,7 +70,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 +94,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 ' . $this->indent . ' spaces from SWITCH keyword';
$phpcsFile->addError($error, $nextCase, $type.'Indent');
}
@@ -123,7 +130,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');
}
Please sign in to comment.
Something went wrong with that request. Please try again.