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

Closed
wants to merge 1 commit into 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

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

@ruudk
Copy link
Contributor Author

ruudk commented Nov 18, 2024

@stof @fabpot what to do with this?

@ruudk ruudk requested a review from stof November 21, 2024 08:11
By introducing a `getExtension` method in `Template` we can help PHPStan with the
proper return type.
@fabpot
Copy link
Contributor

fabpot commented Nov 22, 2024

I'm 👎 on this one as I don't want to change the code just to please a static analyzer.

@ruudk
Copy link
Contributor Author

ruudk commented Nov 22, 2024

Understood, thanks!

@ruudk ruudk closed this Nov 22, 2024
@ruudk ruudk deleted the get-extension branch November 22, 2024 10:21
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.

3 participants