Add template for getRuntime method (#164)

This commit is contained in:
Vincent Langlet 2021-03-29 16:24:13 +02:00 committed by GitHub
parent e363384dfa
commit 9138d0bc80
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 58 additions and 0 deletions

10
.editorconfig Normal file
View File

@ -0,0 +1,10 @@
root = true
[*]
end_of_line = lf
insert_final_newline = true
indent_style = space
indent_size = 2
[{*.php, *.json}]
indent_size = 4

View File

@ -11,4 +11,15 @@ class Environment
* @psalm-taint-specialize
*/
public function render($name, array $context = []): string {}
/**
* @template T of object
*
* @param class-string<T> $class
*
* @return T
*
* @throws RuntimeError When the template cannot be found
*/
public function getRuntime($class) {}
}

View File

@ -0,0 +1,37 @@
@symfony-common
Feature: Twig Environment
Background:
Given I have the following config
"""
<?xml version="1.0"?>
<psalm errorLevel="1">
<projectFiles>
<directory name="."/>
<ignoreFiles> <directory name="../../vendor"/> </ignoreFiles>
</projectFiles>
<plugins>
<pluginClass class="Psalm\SymfonyPsalmPlugin\Plugin"/>
</plugins>
</psalm>
"""
Scenario: getRuntime method return type is dynamic
Given I have the following code
"""
<?php
use Symfony\Component\Form\FormRenderer;
use Twig\Environment;
class Foo
{
public function foo(Environment $environment): FormRenderer
{
return $environment->getRuntime(FormRenderer::class);
}
}
"""
When I run Psalm
Then I see no errors