minor #3541 Implement template annotation for getExtension (mitelg)

This PR was merged into the 3.x branch.

Discussion
----------

Implement template annotation for `getExtension`

Hello there 🙂  👋

my first PR here 😉

This change would help to improve static analysis with tools like PHPStan and Psalm.

Commits
-------

110871d1 Implement template annotation for `getExtension` and `getRuntime`
This commit is contained in:
Fabien Potencier
2022-01-02 16:29:57 +01:00
+11 -2
View File
@@ -557,6 +557,13 @@ class Environment
$this->runtimeLoaders[] = $loader;
}
/**
* @template TExtension of ExtensionInterface
*
* @param class-string<TExtension> $class
*
* @return TExtension
*/
public function getExtension(string $class): ExtensionInterface
{
return $this->extensionSet->getExtension($class);
@@ -565,9 +572,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<TRuntime> $class A runtime class name
*
* @return TRuntime The runtime implementation
*
* @throws RuntimeError When the template cannot be found
*/