Skip to content

Commit

Permalink
updated MemberVarSpacingSniff
Browse files Browse the repository at this point in the history
  • Loading branch information
vossik committed May 19, 2021
1 parent 313b2ff commit 43c2a37
Showing 1 changed file with 5 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,8 @@ class MemberVarSpacingSniff extends \PHP_CodeSniffer\Sniffs\AbstractVariableSnif
public int $spacingBeforeFirst = 1;
public bool $ignoreFirstMemberVar = false;

/**
* @return int|void
*/
//@phpcs:ignore Squiz.Commenting.FunctionComment.ScalarTypeHintMissing
//@phpcs:ignore SlevomatCodingStandard.TypeHints.ReturnTypeHint.MissingNativeTypeHint
protected function processMemberVar(\PHP_CodeSniffer\Files\File $phpcsFile, $stackPtr)
protected function processMemberVar(\PHP_CodeSniffer\Files\File $phpcsFile, $stackPtr) : ?int
{
$tokens = $phpcsFile->getTokens();

Expand All @@ -25,7 +21,7 @@ protected function processMemberVar(\PHP_CodeSniffer\Files\File $phpcsFile, $sta
$startOfStatement = $phpcsFile->findPrevious($validPrefixes, $stackPtr - 1, null, false, null, true);

if ($startOfStatement === false) {
return;
return null;
}

$endOfStatement = $phpcsFile->findNext(\T_SEMICOLON, $stackPtr + 1, null, false, null, true);
Expand Down Expand Up @@ -97,13 +93,13 @@ protected function processMemberVar(\PHP_CodeSniffer\Files\File $phpcsFile, $sta
&& isset($tokens[$prev]['scope_condition']) === true
&& $tokens[$tokens[$prev]['scope_condition']]['code'] === \T_FUNCTION
) {
return;
return null;
}

$prevVar = $phpcsFile->findPrevious(\T_VARIABLE, $first - 1);

if ($this->ignoreFirstMemberVar && $tokens[$prevVar]['code'] !== \T_VARIABLE) {
return;
return null;
}

if ($tokens[$prev]['code'] === \T_OPEN_CURLY_BRACKET
Expand Down Expand Up @@ -131,7 +127,7 @@ protected function processMemberVar(\PHP_CodeSniffer\Files\File $phpcsFile, $sta
return $endOfStatement;
}

return;
return null;
}

$data = [
Expand Down

0 comments on commit 43c2a37

Please sign in to comment.