1: <?php declare(strict_types = 1);
2:
3: namespace PHPStan\PhpDoc;
4:
5: use PHPStan\Analyser\NameScope;
6: use PHPStan\PhpDocParser\Lexer\Lexer;
7: use PHPStan\PhpDocParser\Parser\TokenIterator;
8: use PHPStan\PhpDocParser\Parser\TypeParser;
9: use PHPStan\Type\Type;
10:
11: class TypeStringResolver
12: {
13:
14: public function __construct(private Lexer $typeLexer, private TypeParser $typeParser, private TypeNodeResolver $typeNodeResolver)
15: {
16: }
17:
18: /** @api */
19: public function resolve(string $typeString, ?NameScope $nameScope = null): Type
20: {
21: $tokens = new TokenIterator($this->typeLexer->tokenize($typeString));
22: $typeNode = $this->typeParser->parse($tokens);
23: $tokens->consumeTokenType(Lexer::TOKEN_END); // @phpstan-ignore missingType.checkedException
24:
25: return $this->typeNodeResolver->resolve($typeNode, $nameScope ?? new NameScope(null, []));
26: }
27:
28: }
29: