fix crash when using self::class in container get (#34)

* fix crash when using self::class in container get

* no message

* no message
This commit is contained in:
Farhad Safarov 2020-05-27 16:58:32 +03:00 committed by GitHub
parent 7a628c6fda
commit d1f2fbab84
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 3 deletions

View File

@ -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()

View File

@ -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;

View File

@ -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
"""
<?php
class SomeController
{
use \Symfony\Component\DependencyInjection\ContainerAwareTrait;
public function index()
{
$this->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 |