mirror of
https://github.com/danog/phpdoc-parser.git
synced 2024-11-26 12:04:52 +01:00
Extend allowed types for conditional for parameter
This commit is contained in:
parent
d8e9fd97ca
commit
129a63b3bc
@ -259,15 +259,19 @@ class TypeParser
|
||||
$tokens->consumeTokenType(Lexer::TOKEN_IDENTIFIER);
|
||||
}
|
||||
|
||||
$targetType = $this->parseAtomic($tokens);
|
||||
$targetType = $this->parse($tokens);
|
||||
|
||||
$tokens->tryConsumeTokenType(Lexer::TOKEN_PHPDOC_EOL);
|
||||
$tokens->consumeTokenType(Lexer::TOKEN_NULLABLE);
|
||||
$tokens->tryConsumeTokenType(Lexer::TOKEN_PHPDOC_EOL);
|
||||
|
||||
$ifType = $this->parseAtomic($tokens);
|
||||
$ifType = $this->parse($tokens);
|
||||
|
||||
$tokens->tryConsumeTokenType(Lexer::TOKEN_PHPDOC_EOL);
|
||||
$tokens->consumeTokenType(Lexer::TOKEN_COLON);
|
||||
$tokens->tryConsumeTokenType(Lexer::TOKEN_PHPDOC_EOL);
|
||||
|
||||
$elseType = $this->parseAtomic($tokens);
|
||||
$elseType = $this->parse($tokens);
|
||||
|
||||
return new Ast\Type\ConditionalTypeForParameterNode($parameterName, $targetType, $ifType, $elseType, $negated);
|
||||
}
|
||||
|
@ -12,6 +12,7 @@ use PHPStan\PhpDocParser\Ast\Type\ArrayShapeNode;
|
||||
use PHPStan\PhpDocParser\Ast\Type\ArrayTypeNode;
|
||||
use PHPStan\PhpDocParser\Ast\Type\CallableTypeNode;
|
||||
use PHPStan\PhpDocParser\Ast\Type\CallableTypeParameterNode;
|
||||
use PHPStan\PhpDocParser\Ast\Type\ConditionalTypeForParameterNode;
|
||||
use PHPStan\PhpDocParser\Ast\Type\ConditionalTypeNode;
|
||||
use PHPStan\PhpDocParser\Ast\Type\ConstTypeNode;
|
||||
use PHPStan\PhpDocParser\Ast\Type\GenericTypeNode;
|
||||
@ -1210,6 +1211,42 @@ class TypeParserTest extends TestCase
|
||||
false
|
||||
),
|
||||
],
|
||||
[
|
||||
'($foo is Bar|Baz ? never : int|string)',
|
||||
new ConditionalTypeForParameterNode(
|
||||
'$foo',
|
||||
new UnionTypeNode([
|
||||
new IdentifierTypeNode('Bar'),
|
||||
new IdentifierTypeNode('Baz'),
|
||||
]),
|
||||
new IdentifierTypeNode('never'),
|
||||
new UnionTypeNode([
|
||||
new IdentifierTypeNode('int'),
|
||||
new IdentifierTypeNode('string'),
|
||||
]),
|
||||
false
|
||||
),
|
||||
],
|
||||
[
|
||||
'(' . PHP_EOL .
|
||||
' $foo is Bar|Baz' . PHP_EOL .
|
||||
' ? never' . PHP_EOL .
|
||||
' : int|string' . PHP_EOL .
|
||||
')',
|
||||
new ConditionalTypeForParameterNode(
|
||||
'$foo',
|
||||
new UnionTypeNode([
|
||||
new IdentifierTypeNode('Bar'),
|
||||
new IdentifierTypeNode('Baz'),
|
||||
]),
|
||||
new IdentifierTypeNode('never'),
|
||||
new UnionTypeNode([
|
||||
new IdentifierTypeNode('int'),
|
||||
new IdentifierTypeNode('string'),
|
||||
]),
|
||||
false
|
||||
),
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user