Skip to content

Commit

Permalink
Fix FileTypeMapper call in MethodTemplateTypeRule
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Jan 5, 2022
1 parent d09938b commit 63838ee
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Rules/Generics/MethodTemplateTypeRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function processNode(Node $node, Scope $scope): array
$methodName = $node->name->toString();
$resolvedPhpDoc = $this->fileTypeMapper->getResolvedPhpDoc(
$scope->getFile(),
$className,
$classReflection->getName(),
$scope->isInTrait() ? $scope->getTraitReflection()->getName() : null,
$methodName,
$docComment->getText(),
Expand Down
5 changes: 5 additions & 0 deletions src/Type/FileTypeMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
use function ltrim;
use function md5;
use function sprintf;
use function strpos;
use function strtolower;
use function time;
use function trait_exists;
Expand Down Expand Up @@ -628,6 +629,10 @@ private function getNameScopeKey(
return md5(sprintf('%s', $file));
}

if ($class !== null && strpos($class, 'class@anonymous') !== false) {
throw new ShouldNotHappenException('Wrong anonymous class name, FilTypeMapper should be called with ClassReflection::getName().');
}

return md5(sprintf('%s-%s-%s-%s', $file, $class, $trait, $function));
}

Expand Down

0 comments on commit 63838ee

Please sign in to comment.