From 110871d1de763034659ef48bf52be0c2606bf621 Mon Sep 17 00:00:00 2001 From: Michael Telgmann Date: Thu, 17 Jun 2021 16:44:19 +0200 Subject: [PATCH] Implement template annotation for `getExtension` and `getRuntime` Improves static analysis for caller of this methods --- src/Environment.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/Environment.php b/src/Environment.php index 26c1f82c0..87f91e902 100644 --- a/src/Environment.php +++ b/src/Environment.php @@ -548,6 +548,13 @@ class Environment $this->runtimeLoaders[] = $loader; } + /** + * @template TExtension of ExtensionInterface + * + * @param class-string $class + * + * @return TExtension + */ public function getExtension(string $class): ExtensionInterface { return $this->extensionSet->getExtension($class); @@ -556,9 +563,11 @@ class Environment /** * Returns the runtime implementation of a Twig element (filter/function/tag/test). * - * @param string $class A runtime class name + * @template TRuntime of object * - * @return object The runtime implementation + * @param class-string $class A runtime class name + * + * @return TRuntime The runtime implementation * * @throws RuntimeError When the template cannot be found */