Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@hemberger
Copy link
Contributor

Fixes #844.

PhpStorm currently lacks the ability to infer a template type from a class-string constructor argument (see
https://youtrack.jetbrains.com/issue/WI-65811/Infer-type-from-constructors-class-string-parameter). As a result of #842 (v7.0.1), this requires PhpStorm users to manually typehint their ContainerBuilder instances, e.g.:

/** @var ContainerBuilder<Container> $builder */
$builder = new ContainerBuilder();

To avoid this, we only use the proper templated typehints with Psalm- and PHPStan-specific annotations, and leave the non-templated typehints as a fallback. Note that the fallbacks will not give the correct type when using a non-default Container class.

@Gounlaf While this should in theory recover the pre-7.0.1 behavior for PhpStorm, I'm not able to test this. Could you please check if it fixes your issue? Many thanks!

@mnapoli
Copy link
Member

mnapoli commented Feb 7, 2023

Thanks!

These are a lot of annotations, couldn't we limit ourselves to reverting #842 for now? Maintaining all those annotations is not something I am looking for tbh :/

@jdreesen
Copy link
Contributor

jdreesen commented Feb 7, 2023

I don't think we need both @psalm-* and @phpstan-* as each tool can understand both.

Fixes PHP-DI#844.

PhpStorm currently lacks the ability to infer a template type from a
`class-string` constructor argument (see
https://youtrack.jetbrains.com/issue/WI-65811/Infer-type-from-constructors-class-string-parameter).
As a result of PHP-DI#842 (v7.0.1), this requires PhpStorm users to manually
typehint their ContainerBuilder instances, e.g.:

    /** @var ContainerBuilder<Container> $builder */
    $builder = new ContainerBuilder();

To avoid this, we only use the proper templated typehints with Psalm
annotations (which will be usable by both Psalm and PHPStan), and leave
the non-templated typehints as a fallback. Note that the fallbacks will
not give the correct type when using a non-default Container class.
@hemberger
Copy link
Contributor Author

I don't think we need both @psalm-* and @phpstan-* as each tool can understand both.

Good point, thanks! I've updated the PR to remove the @phpstan- annotations in favor of @psalm- (since that's what is more commonly used in this project).

Maintaining all those annotations is not something I am looking for tbh :/

I understand completely. Do you feel the situation is sufficiently improved with the @phpstan- annotations removed?

@mnapoli
Copy link
Member

mnapoli commented Feb 7, 2023

@hemberger yes that's better, thank you!

@mnapoli mnapoli merged commit 5d1a866 into PHP-DI:master Feb 7, 2023
@hemberger hemberger deleted the issue-844 branch February 7, 2023 17:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7.x IDE Integration broken?

3 participants