Skip to content

Commit d44fffe

Browse files
committed
Fix parser issues
1 parent 56cafce commit d44fffe

3 files changed

Lines changed: 19 additions & 5 deletions

File tree

libs/parser/src/InMemoryCachedParser.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ final class InMemoryCachedParser implements ParserInterface
1717
*/
1818
private array $types = [];
1919

20+
/**
21+
* @var array<non-empty-string, ParsedResult>
22+
*/
23+
private array $sequences = [];
24+
2025
public function __construct(
2126
private readonly ParserInterface $parser = new Parser(),
2227
private readonly SourceFactoryInterface $sources = new SourceFactory(),
@@ -33,4 +38,16 @@ public function parse(mixed $source): TypeNode
3338

3439
return $this->types[$instance->getHash()] ??= $this->parser->parse($source);
3540
}
41+
42+
/**
43+
* @throws ParserExceptionInterface
44+
* @throws SourceExceptionInterface
45+
* @throws \Throwable
46+
*/
47+
public function parseTolerant(mixed $source): ParsedResult
48+
{
49+
$instance = $this->sources->create($source);
50+
51+
return $this->sequences[$instance->getHash()] ??= $this->parser->parseTolerant($source);
52+
}
3653
}

libs/parser/src/TypeResolver.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
namespace TypeLang\Parser;
66

7-
use TypeLang\Node\FullQualifiedName;
87
use TypeLang\Node\Name;
98
use TypeLang\Node\Type\TypeNode;
109
use TypeLang\Parser\Traverser\TypeMapVisitor;
@@ -52,9 +51,7 @@ public function resolveWith(TypeNode $type, array $replacements): TypeNode
5251
foreach ($replacements as $key => $replacement) {
5352
// normalize value
5453
if (\is_string($replacement)) {
55-
$replacement = \str_starts_with($replacement, '\\')
56-
? new FullQualifiedName($replacement)
57-
: new Name($replacement);
54+
$replacement = Name::createFromString($replacement);
5855
}
5956

6057
// normalize key

phpstan.neon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ includes:
33
- vendor/phpstan/phpstan-deprecation-rules/rules.neon
44
- vendor/phpstan/phpstan-strict-rules/rules.neon
55
# Components
6-
# - libs/parser/phpstan.neon
6+
- libs/parser/phpstan.neon
77
# - libs/phpdoc/phpstan.neon
88
# - libs/phpdoc-standard-tags/phpstan.neon
99
# - libs/phpdoc-template-tags/phpstan.neon

0 commit comments

Comments
 (0)