Skip to content

Commit

Permalink
Merge branch '2.17'
Browse files Browse the repository at this point in the history
  • Loading branch information
keradus committed Jan 18, 2021
2 parents f5f4639 + f209e6d commit adf246f
Show file tree
Hide file tree
Showing 9 changed files with 418 additions and 8 deletions.
8 changes: 4 additions & 4 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
defaultTimeLimit="3"
defaultTimeLimit="10"
enforceTimeLimit="true"
failOnWarning="true"
processIsolation="false"
stopOnFailure="false"
timeoutForSmallTests="3"
timeoutForMediumTests="6"
timeoutForLargeTests="9"
timeoutForSmallTests="10"
timeoutForMediumTests="20"
timeoutForLargeTests="30"
verbose="false"
>
<testsuites>
Expand Down
6 changes: 4 additions & 2 deletions src/Fixer/PhpUnit/PhpUnitTestCaseStaticMethodCallsFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -473,8 +473,10 @@ private function needsConversion(Tokens $tokens, $index, $referenceIndex, $callT
*/
private function findEndOfNextBlock(Tokens $tokens, $index)
{
$index = $tokens->getNextTokenOfKind($index, ['{']);
$nextIndex = $tokens->getNextTokenOfKind($index, [';', '{']);

return $tokens->findBlockEnd(Tokens::BLOCK_TYPE_CURLY_BRACE, $index);
return $tokens[$nextIndex]->equals('{')
? $tokens->findBlockEnd(Tokens::BLOCK_TYPE_CURLY_BRACE, $nextIndex)
: $nextIndex;
}
}
7 changes: 7 additions & 0 deletions src/Tokenizer/Analyzer/ArgumentsAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,14 @@ public function getArguments(Tokens $tokens, $openParenthesis, $closeParenthesis
{
$arguments = [];
$firstSensibleToken = $tokens->getNextMeaningfulToken($openParenthesis);

if ($tokens[$firstSensibleToken]->equals(')')) {
return $arguments;
}

$paramContentIndex = $openParenthesis + 1;
$argumentsStart = $paramContentIndex;

for (; $paramContentIndex < $closeParenthesis; ++$paramContentIndex) {
$token = $tokens[$paramContentIndex];

Expand Down Expand Up @@ -106,21 +108,26 @@ public function getArgumentInfo(Tokens $tokens, $argumentStart, $argumentEnd)
];

$sawName = false;

for ($index = $argumentStart; $index <= $argumentEnd; ++$index) {
$token = $tokens[$index];

if ($token->isComment() || $token->isWhitespace() || $token->isGivenKind(T_ELLIPSIS) || $token->equals('&')) {
continue;
}

if ($token->isGivenKind(T_VARIABLE)) {
$sawName = true;
$info['name_index'] = $index;
$info['name'] = $token->getContent();

continue;
}

if ($token->equals('=')) {
continue;
}

if ($sawName) {
$info['default'] .= $token->getContent();
} else {
Expand Down
4 changes: 3 additions & 1 deletion src/Tokenizer/Analyzer/FunctionsAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,14 +153,16 @@ public function getFunctionReturnType(Tokens $tokens, $methodIndex)
$argumentsStart = $tokens->getNextTokenOfKind($methodIndex, ['(']);
$argumentsEnd = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $argumentsStart);
$typeColonIndex = $tokens->getNextMeaningfulToken($argumentsEnd);
if (':' !== $tokens[$typeColonIndex]->getContent()) {

if (!$tokens[$typeColonIndex]->isGivenKind(CT::T_TYPE_COLON)) {
return null;
}

$type = '';
$typeStartIndex = $tokens->getNextMeaningfulToken($typeColonIndex);
$typeEndIndex = $typeStartIndex;
$functionBodyStart = $tokens->getNextTokenOfKind($typeColonIndex, ['{', ';', [T_DOUBLE_ARROW]]);

for ($i = $typeStartIndex; $i < $functionBodyStart; ++$i) {
if ($tokens[$i]->isWhitespace() || $tokens[$i]->isComment()) {
continue;
Expand Down
6 changes: 6 additions & 0 deletions src/Tokenizer/Transformer/TypeAlternationTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,12 @@ public function process(Tokens $tokens, Token $token, $index)
return;
}

if (\PHP_VERSION_ID >= 70400 && $prePrevToken->isGivenKind(T_FN)) {
$this->replaceToken($tokens, $index); // `|` is part of an array function variable `fn(int|null`

return;
}

if (
$prePrevToken->isGivenKind(T_STRING)
&& $tokens[$tokens->getPrevMeaningfulToken($prevPrevTokenIndex)]->isGivenKind(T_FUNCTION)
Expand Down
14 changes: 14 additions & 0 deletions tests/Fixer/PhpUnit/PhpUnitTestCaseStaticMethodCallsFixerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,20 @@ public function foo()
EOF
,
],
'do not crash on abstract static function' => [
<<<'EOF'
<?php
abstract class FooTest extends TestCase
{
abstract public static function dataProvider();
}
EOF
,
null,
[
'call_type' => PhpUnitTestCaseStaticMethodCallsFixer::CALL_TYPE_THIS,
],
],
];
}

Expand Down
Loading

0 comments on commit adf246f

Please sign in to comment.