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

Signature of wrapper Connection constructor is not enforced #4511

Closed
morozov opened this issue Feb 26, 2021 · 5 comments · Fixed by #5166
Closed

Signature of wrapper Connection constructor is not enforced #4511

morozov opened this issue Feb 26, 2021 · 5 comments · Fixed by #5166

Comments

@morozov
Copy link
Member

morozov commented Feb 26, 2021

Psalm on level 2:

ERROR: UnsafeInstantiation - lib/Doctrine/DBAL/DriverManager.php:236:16 - Cannot safely instantiate class Doctrine\DBAL\Connection with "new $class_name" as its constructor might change in child classes (see https://psalm.dev/229)
        return new $wrapperClass($params, $driver, $config, $eventManager);
@greg0ire
Copy link
Member

A solution might be to have a static method for this, that way the LSP is enforced

@morozov
Copy link
Member Author

morozov commented Feb 27, 2021

Ideally, I'd like to turn it into a composition similar to what we did with the portability layer. Each wrapper connector class by definition may have different dependencies injected via the constructor and the only way to do that now is to pass them via $params which isn't really type-safe.

@github-actions github-actions bot added the Stale label Oct 28, 2021
@morozov morozov removed the Stale label Oct 31, 2021
@orklah
Copy link

orklah commented Jan 6, 2022

Note that Psalm has an annotation @psalm-consistent-constructor that will silent this Issue while making sure every child respects the original signature

@morozov
Copy link
Member Author

morozov commented Jan 6, 2022

Thanks, @orklah. That's definitely a good way to document the shortcomings of the existing API.

@github-actions
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 21, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants