public function process(\PHP_CodeSniffer_File $phpcsFile, $stackPtr)
{
$scope = $phpcsFile->getDeclarationName($stackPtr);
$class = $phpcsFile->getDeclarationName($phpcsFile->findPrevious([T_CLASS, T_INTERFACE], $stackPtr));
$tokens = $phpcsFile->getTokens();
$function = $tokens[$stackPtr];
if (!isset($function['scope_opener'])) {
// No scope means it's an abstract/interface function declaration
return;
}
$scopeTypes = [T_IF, T_ELSE, T_ELSEIF, T_FOR, T_FOREACH, T_SWITCH, T_WHILE];
$functionStartPtr = $function['scope_opener'];
$functionEndPtr = $function['scope_closer'];
$ptr = $functionStartPtr;
// var_dump($class, $scope);
while ($ptr = $phpcsFile->findNext($scopeTypes, $ptr + 1, $functionEndPtr)) {
$token = $tokens[$ptr];
if ($token['code'] != T_IF && $token['code'] != T_ELSE && $token['code'] != T_ELSEIF) {
$this->getBlankLineCountBefore($phpcsFile, $tokens, $functionStartPtr, $ptr - 1);
$this->getBlankLineCountAfter($phpcsFile, $tokens, $token['scope_closer'] + 1, $functionEndPtr);
} elseif ($token['code'] == T_IF) {
$this->getBlankLineCountBefore($phpcsFile, $tokens, $functionStartPtr, $ptr);
$this->getBlankLineCountAfter($phpcsFile, $tokens, $token['scope_closer'] + 1, $functionEndPtr, [T_ELSE, T_ELSEIF]);
} elseif ($token['code'] == T_ELSEIF) {
$this->getBlankLineCountBefore($phpcsFile, $tokens, $functionStartPtr, $ptr, [T_CLOSE_CURLY_BRACKET]);
$this->getBlankLineCountAfter($phpcsFile, $tokens, $token['scope_closer'] + 1, $functionEndPtr, [T_ELSE, T_ELSEIF]);
} elseif ($token['code'] == T_ELSE) {
$this->getBlankLineCountBefore($phpcsFile, $tokens, $functionStartPtr, $ptr, [T_CLOSE_CURLY_BRACKET]);
$this->getBlankLineCountAfter($phpcsFile, $tokens, $token['scope_closer'] + 1, $functionEndPtr);
}
}
}