Skip to content

Commit

Permalink
Adding compatibility with squizlabs/PHP_CodeSniffer 3.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
CMalvika committed Jul 6, 2018
1 parent a90a656 commit 137cb88
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ public function process(File $file, $stackPtr)
$caseCount = 0;
$foundDefault = false;

while (($nextCase = $file->findNext([T_CASE, T_DEFAULT, T_SWITCH], ($nextCase + 1), $switch['scope_closer'])
) !== false
while (($nextCase = $file->findNext([T_CASE, T_DEFAULT, T_SWITCH], ($nextCase + 1), $switch['scope_closer']))
!== false
) {
// Skip nested SWITCH statements; they are handled on their own.
if ($tokens[$nextCase]['code'] === T_SWITCH) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public function process(File $file, $stackPtr)
null,
true
);

if (in_array($tokens[$returnTypePos]['code'], [T_STRING, T_CALLABLE, T_SELF])) {
$closingPtr = $returnTypePos;
}
Expand Down Expand Up @@ -163,6 +164,7 @@ public function process(File $file, $stackPtr)

if ($tokens[$nextPtr]['code'] === T_COLON) {
$endPtr = $nextPtr;

while (!in_array($tokens[$endPtr]['code'], [T_STRING, T_CALLABLE, T_SELF])) {
++$endPtr;
}
Expand Down
7 changes: 7 additions & 0 deletions src/InterNations/Sniffs/Naming/ConstantNameSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,13 @@ public function process(File $file, $stackPtr)
return;
}

// Is this a return type
$prevPtrColon = $file->findPrevious([T_WHITESPACE, T_NULLABLE], ($stackPtr - 1), null, true);

if ($tokens[$prevPtrColon]['code'] === T_COLON) {
return;
}

// Is this a goto label target?
if ($tokens[$nextPtr]['code'] === T_COLON) {
if (in_array($tokens[$prevPtr]['code'], [T_SEMICOLON, T_OPEN_CURLY_BRACKET, T_COLON], true)) {
Expand Down
4 changes: 2 additions & 2 deletions src/InterNations/Sniffs/Syntax/MethodTypeHintsSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -420,8 +420,8 @@ public function process(File $file, $stackPtr)

if (!in_array(
$tokens[$file->findNext(T_COLON, $endBracket)+2]['code'],
[T_NULLABLE, T_STRING, T_CALLABLE, T_SELF])
) {
[T_NULLABLE, T_STRING, T_CALLABLE, T_SELF]
)) {
$error = 'Expected exactly one space after colon, multiple spaces or no space found for the return type';
$file->addError($error, $namePtr, 'WrongStyleTypeHint');

Expand Down

0 comments on commit 137cb88

Please sign in to comment.