From ac7b5d1268fe80de5fa11fcb74290d2a34d7a474 Mon Sep 17 00:00:00 2001 From: Chetan Date: Sun, 18 Jul 2021 14:14:45 +0530 Subject: [PATCH] Update Ruleset --- Sniffs/Spacing/SpaceBetweenBlocksSniff.php | 107 ------ ruleset.xml | 390 ++++++++++++++++++++- 2 files changed, 374 insertions(+), 123 deletions(-) delete mode 100644 Sniffs/Spacing/SpaceBetweenBlocksSniff.php diff --git a/Sniffs/Spacing/SpaceBetweenBlocksSniff.php b/Sniffs/Spacing/SpaceBetweenBlocksSniff.php deleted file mode 100644 index e6fdb1e..0000000 --- a/Sniffs/Spacing/SpaceBetweenBlocksSniff.php +++ /dev/null @@ -1,107 +0,0 @@ -getTokens(); - - switch ($tokens[$stackPtr]['type']) { - case 'T_ELSE': - case 'T_IF': - case 'T_ELSEIF': - case 'T_SWITCH': - case 'T_WHILE': - case 'T_FOR': - case 'T_FOREACH': - $semicolonLine = $phpcsFile->findPrevious([T_SEMICOLON, T_OPEN_CURLY_BRACKET], $stackPtr - 1, null, false); - $lineDiff = $tokens[$stackPtr]["line"] - $tokens[$semicolonLine]["line"]; - - if ($lineDiff < 2 && $tokens[$semicolonLine]["type"] != "T_OPEN_CURLY_BRACKET") { - $error = 'Construct blocks should be separated by two lines'; - $phpcsFile->addFixableError( - $error, - $stackPtr - 1, - self::class - ); - } - - break; - case 'T_CLOSE_CURLY_BRACKET': - - if (!isset($tokens[$stackPtr]["scope_condition"])) { - break; - } - - // Which condition this token belongs to - $conditionPosition = $tokens[$stackPtr]["scope_condition"]; - $conditionType = $tokens[$conditionPosition]["type"]; - - // Find next non white space token - if ($conditionType === "T_ELSE" || $conditionType == "T_FOREACH" || $conditionType == "T_IF" - || $conditionType == "T_ELSE" || $conditionType == "T_WHILE" - || $conditionType == "T_SWITCH" || $conditionType == "T_FOR" - ) { - // Find next non-white space (start of next statement/block) - $nonWhitePosition = $stackPtr + 1; - $onlyIfBlock = true; - $foundNonWhite = false; - - if (isset($tokens[$nonWhitePosition])) { - while (true) { - if (($tokens[$nonWhitePosition]["type"] == "T_ELSEIF" - || $tokens[$nonWhitePosition]["type"] == "T_ELSE")) { - // This is not an only if block - $onlyIfBlock = false; - } - - if ($tokens[$nonWhitePosition]["type"] == "T_WHITESPACE" && isset($tokens[$nonWhitePosition + 1])) { - $foundNonWhite = true; - $nonWhitePosition++; - continue; - } else { - break; - } - } - - if (!$onlyIfBlock) { - // If this is not only if block, then break, because we need to check this condition - // for else statements - break; - } - - $lineDiff = $tokens[$nonWhitePosition]["line"] - $tokens[$stackPtr]["line"]; - - if ($lineDiff < 2 && $tokens[$nonWhitePosition]["type"] != "T_CLOSE_CURLY_BRACKET" && $foundNonWhite) { - $error = 'Construct blocks should be separated by two lines'; - $phpcsFile->addFixableError( - $error, - $stackPtr - 1, - self::class - ); - } - } - } - break; - } - } -} diff --git a/ruleset.xml b/ruleset.xml index 13b8327..4ffb466 100644 --- a/ruleset.xml +++ b/ruleset.xml @@ -1,5 +1,379 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 0 + + + 0 + + + 0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 0 + + + + + + + + + + + + + + + + error + Method name "%s" must not be prefixed with an underscore to indicate visibility + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 0 + + + 0 + + + + + + + + + + + + + + + + + 0 + + + 0 + + + + + + + + 0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 0 + + + 0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -7,13 +381,11 @@ - - @@ -22,24 +394,18 @@ - - - - - - @@ -51,15 +417,7 @@ - - - - - - - -