mirror of
https://github.com/danog/psalm-plugin-symfony.git
synced 2025-01-22 13:01:49 +01:00
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:
parent
7a628c6fda
commit
d1f2fbab84
@ -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()
|
||||
|
@ -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;
|
||||
|
@ -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 |
|
||||
|
Loading…
x
Reference in New Issue
Block a user