-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add types for referenced extensions inside Template #4429
Conversation
$compiler->raw(\sprintf('$this->env->getExtension(\'%s\')', $class)); | ||
} else { | ||
$compiler->raw(\sprintf('$this->extensions[\'%s\']', ltrim($class, '\\'))); | ||
$compiler->raw(\sprintf('$this->getExtension(\'%s\')', ltrim($class, '\\'))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder, why aren't we always using $this->env->getExtension
? That one already has proper typing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe this was a performance optimization to avoid extra method calls (based on the comment a file lines above).
This could actually be supported for the existing code if phpstan/phpstan#9521 was implemented in phpstan, as the type of Template::$extensions
is class-string-map<T of ExtensionInterface, T>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, unfortunately we don't have it yet.
@fabpot ready for review |
By introducing a `getExtension` method in `Template` we can help PHPStan with the proper return type.
I'm 👎 on this one as I don't want to change the code just to please a static analyzer. |
Understood, thanks! |
By introducing a
getExtension
method inTemplate
we can help PHPStan with the proper return type./cc @stof