Skip to content

Commit

Permalink
fixed use in comment in file beginnig breaking parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
romalytvynenko committed May 19, 2024
1 parent c76724d commit bcafb37
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/Infer/Reflector/ClassReflector.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ public function getNameContext(): NameContext

$code = Str::before($content, $firstMatchedClassLikeString);

// Removes all comments.
$code = preg_replace('/\/\*(?:[^*]|\*+[^*\/])*\*+\/|(?<![:\'"])\/\/.*|(?<![:\'"])#.*/', '', $code);

$re = '/(namespace|use) ([.\s\S]*?);/m';
preg_match_all($re, $code, $matches);

Expand Down
2 changes: 1 addition & 1 deletion src/Infer/Services/FileParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public static function getInstance(): static

public function parseContent(string $content): FileParserResult
{
return $this->cache[md5($content).'23'] ??= new FileParserResult(
return $this->cache[md5($content)] ??= new FileParserResult(
$statements = Arr::wrap($this->parser->parse($content)),
new FileNameResolver(new NameContext(new Throwing()))
);
Expand Down

0 comments on commit bcafb37

Please sign in to comment.