Skip to content

Commit

Permalink
Merge pull request #575 from wimg/feature/multi-line-return-types
Browse files Browse the repository at this point in the history
Sniff: align `getReturnTypeHintToken()` bc method with PHPCS behaviour
  • Loading branch information
wimg committed Jan 20, 2018
2 parents 75c6100 + d6598b1 commit 6d4259b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
8 changes: 6 additions & 2 deletions PHPCompatibility/Sniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -1063,7 +1063,11 @@ public function getReturnTypeHintToken(\PHP_CodeSniffer_File $phpcsFile, $stackP
return false;
}

$hasColon = $phpcsFile->findNext(array(T_COLON, T_INLINE_ELSE), ($tokens[$stackPtr]['parenthesis_closer'] + 1), $tokens[$stackPtr]['scope_opener']);
$hasColon = $phpcsFile->findNext(
array(T_COLON, T_INLINE_ELSE),
($tokens[$stackPtr]['parenthesis_closer'] + 1),
$tokens[$stackPtr]['scope_opener']
);
if ($hasColon === false) {
return false;
}
Expand All @@ -1081,7 +1085,7 @@ public function getReturnTypeHintToken(\PHP_CodeSniffer_File $phpcsFile, $stackP
$unrecognizedTypes[] = T_STRING;
}

return $phpcsFile->findNext($unrecognizedTypes, ($hasColon + 1), $tokens[$stackPtr]['scope_opener']);
return $phpcsFile->findPrevious($unrecognizedTypes, ($tokens[$stackPtr]['scope_opener'] - 1), $hasColon);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public function dataReturnType()
array('Class name', '5.6', 13, '7.0'),
array('Class name', '5.6', 14, '7.0'),
array('Class name', '5.6', 15, '7.0'),
array('Class name', '5.6', 37, '7.0'),

array('iterable', '7.0', 18, '7.1'),
array('void', '7.0', 19, '7.1'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,13 @@ function ($a) {}

// PHP 7.2+
function foo($a): object {}

function fooInterspersedWithComments($a) :
// Comment.
?
// phpcs:ignore Standard.Category.Sniff -- ignore something about a return type declaration.
\myNamespace\
// Comment.
Baz
{
}

0 comments on commit 6d4259b

Please sign in to comment.