diff --git a/src/Handler/ClassHandler.php b/src/Handler/ClassHandler.php index 763a333..3888c25 100644 --- a/src/Handler/ClassHandler.php +++ b/src/Handler/ClassHandler.php @@ -4,7 +4,6 @@ namespace Psalm\SymfonyPsalmPlugin\Handler; use PhpParser\Node; use PhpParser\Node\Expr; -use PhpParser\Node\Expr\ClassConstFetch; use PhpParser\Node\Scalar\String_; use Psalm\Codebase; use Psalm\CodeLocation; @@ -73,7 +72,7 @@ class ClassHandler implements AfterClassLikeAnalysisInterface, AfterMethodCallAn break; case 'Doctrine\ORM\EntityManagerInterface::getrepository': case 'Doctrine\Persistence\ObjectManager::getrepository': - if ($expr->args[0]->value instanceof String_ ) { + if ($expr->args[0]->value instanceof String_) { IssueBuffer::accepts( new RepositoryStringShortcut(new CodeLocation($statements_source, $expr->args[0]->value)), $statements_source->getSuppressedIssues() diff --git a/src/Handler/ContainerHandler.php b/src/Handler/ContainerHandler.php index 3b79db8..2950703 100644 --- a/src/Handler/ContainerHandler.php +++ b/src/Handler/ContainerHandler.php @@ -62,7 +62,9 @@ class ContainerHandler implements AfterMethodCallAnalysisInterface, AfterClassLi if (!self::$containerMeta) { if ($return_type_candidate && $expr->args[0]->value instanceof ClassConstFetch) { $className = (string) $expr->args[0]->value->class->getAttribute('resolvedName'); - $return_type_candidate = new Union([new TNamedObject($className)]); + if (!in_array($className, ['self', 'parent', 'static'])) { + $return_type_candidate = new Union([new TNamedObject($className)]); + } } return; diff --git a/tests/acceptance/acceptance/ContainerService.feature b/tests/acceptance/acceptance/ContainerService.feature index 47ed9ef..d75801a 100644 --- a/tests/acceptance/acceptance/ContainerService.feature +++ b/tests/acceptance/acceptance/ContainerService.feature @@ -62,3 +62,23 @@ Feature: Container service Then I see these errors | Type | Message | | UndefinedMethod | Method SomeService::nosuchmethod does not exist | + And I see no other errors + + Scenario: Container get(self::class) should not crash + Given I have the following code + """ + container->get(self::class)->index(); + } + } + """ + When I run Psalm + Then I see these errors + | Type | Message | + | MissingReturnType | Method SomeController::index does not have a return type, expecting void |