Skip to content
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

Open
wants to merge 1 commit into
base: 3.x
Choose a base branch
from

Conversation

ruudk
Copy link
Contributor

@ruudk ruudk commented Oct 31, 2024

By introducing a getExtension method in Template we can help PHPStan with the proper return type.

/cc @stof

By introducing a `getExtension` method in `Template` we can help PHPStan with the
proper return type.
Comment on lines 53 to +55
$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, '\\')));
Copy link
Contributor Author

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.

Copy link
Member

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>

Copy link
Contributor Author

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.

@ruudk
Copy link
Contributor Author

ruudk commented Nov 1, 2024

@fabpot ready for review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants