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
make PDOStatement generic #890
Conversation
after we have a clear plan on how the signature should look like, I will adjust the tests as needed and I am able to |
stubs/PDOStatement.stub
Outdated
* @implements Traversable<int, RowType> | ||
* @implements IteratorAggregate<int, RowType> |
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.
as in psalm, I changed the key-type to int
as we are effectively working with a list
|
just discovered the code for TemplateType validation is pretty new. adjusted the logic to also take return-types into account.. I think we should separate this fixes into a new PR... |
Hi, can you please really make your local environment work? It's not very effective to run everything through CI and push 21 commits when you can find the same thing locally running |
getting it properly running on windows is a bit of a problem. the dev env works great on mac but requires some not-out-of-the-box tooling. I will see what I can do. |
I know people that have it working on Windows without problems. Even without make you can simply run the commands manually from inside the Makefile. |
d9827ea
to
3a63c3c
Compare
I got make running in git-bash on windows. this PR should be good to go. |
Also - Line 25 in bbb79b7
|
a4adabb
to
77372be
Compare
oh great.. this change made some of the test-changes unnecessary. I reverted those. |
@@ -4,7 +4,6 @@ | |||
|
|||
final class PDO extends \PDO | |||
{ | |||
#[\ReturnTypeWillChange] |
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.
deleted this line because it lead to different error lineno beeing reported depending on php version/github action job
as long as the stubs are not merged in PHPStan upstream, we provide them with the project - phpstan/phpstan-src#896 - phpstan/phpstan-src#890
* @param array<mixed> $ctorArgs | ||
* @return false|T | ||
*/ | ||
public function fetchObject($class = \stdclass::class, array $ctorArgs = array()) {} |
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.
Please test that the fetchObject
method behaves as expected. I suspect you need to add T of object
.
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.
added a test. IMO it works as expected
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 suspect you need to add
T of object
.
good point. also submitted to psalm with vimeo/psalm#7274
2e93e67
to
bf17420
Compare
fwiw, this generic is kind of battle tested as I use it while building https://github.com/staabm/phpstan-dba |
…lue type specified in iterable type array.
bf17420
to
3be1d51
Compare
since I have put these stubs in phpstan-dba, I will close this PR. having them inside the database related repo gives me more flexibility and I think is the best thing long term, as phpstan-src needs to stay more generic and cannot per default be as opinionated as phpstan-dba might needs to be |
as discussed in phpstan/phpstan#6242 I want to build a dynamic return type extension for PDOStatement and therefore need a generic signature.
since I want to add a array-shape RowType, I need a single template for the whole type.
using the same generic template as psalm uses, would not allow me to define the exact type.I am wondering that psalm defines the
Traversable
key asint
but phpstan asint|string
.I opened another a Issue on psalm to discuss why the stub in psalm looks like that