From 9138d0bc80e322a92c19b42095c69d136b885910 Mon Sep 17 00:00:00 2001 From: Vincent Langlet Date: Mon, 29 Mar 2021 16:24:13 +0200 Subject: [PATCH] Add template for getRuntime method (#164) --- .editorconfig | 10 +++++ src/Stubs/common/TwigEnvironment.stubphp | 11 ++++++ .../acceptance/TwigEnvironment.feature | 37 +++++++++++++++++++ 3 files changed, 58 insertions(+) create mode 100644 .editorconfig create mode 100644 tests/acceptance/acceptance/TwigEnvironment.feature diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..3aefbb1 --- /dev/null +++ b/.editorconfig @@ -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 diff --git a/src/Stubs/common/TwigEnvironment.stubphp b/src/Stubs/common/TwigEnvironment.stubphp index c75d3c1..8db7d03 100644 --- a/src/Stubs/common/TwigEnvironment.stubphp +++ b/src/Stubs/common/TwigEnvironment.stubphp @@ -11,4 +11,15 @@ class Environment * @psalm-taint-specialize */ public function render($name, array $context = []): string {} + + /** + * @template T of object + * + * @param class-string $class + * + * @return T + * + * @throws RuntimeError When the template cannot be found + */ + public function getRuntime($class) {} } diff --git a/tests/acceptance/acceptance/TwigEnvironment.feature b/tests/acceptance/acceptance/TwigEnvironment.feature new file mode 100644 index 0000000..a7f1975 --- /dev/null +++ b/tests/acceptance/acceptance/TwigEnvironment.feature @@ -0,0 +1,37 @@ +@symfony-common +Feature: Twig Environment + + Background: + Given I have the following config + """ + + + + + + + + + + + + """ + + Scenario: getRuntime method return type is dynamic + Given I have the following code + """ + getRuntime(FormRenderer::class); + } + } + """ + When I run Psalm + Then I see no errors