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

Bug: One-off declarations on @psalm-params for Connection::executeUpdate && Connection::executeStatement #106

Closed
martinsebastianwns opened this issue Dec 3, 2021 · 7 comments

Comments

@martinsebastianwns
Copy link

martinsebastianwns commented Dec 3, 2021

@psalm-param definitions for $query and $types are off by one on executeUpdate and executeStatement.

Connection::executeUpdate

* @psalm-param scalar[] $params The query parameters.

* @psalm-param int[]|string[] $types The parameter types.

Connection::executeStatement

* @psalm-param scalar[] $params The query parameters.

* @psalm-param int[]|string[] $types The parameter types.


Proposal:

-     * @psalm-param scalar[]        $params The query parameters.
+     * @psalm-param scalar[]        $query The query parameters.
-     * @psalm-param int[]|string[]  $types  The parameter types.
+     * @psalm-param int[]|string[]  $params  The parameter types.

public function [...](string $query, array $params = [], array $types = []): int {}

Error Output:

 Argument 2 of Doctrine\DBAL\Connection::executeUpdate expects array<array-key, scalar>, array{ids: array<array-key, mixed>} provided (see https://psalm.dev/004)
            array(
                'ids' => $articleIDs
            ),

BR
Martin

@orklah
Copy link
Collaborator

orklah commented Dec 3, 2021

The error you get is because you're trying to push mixed[] to $params. I don't expect your proposal to make it any better. Replacing scalar[] by int[]|string[] restricts the type even more

@martinsebastianwns
Copy link
Author

Heya @orklah, thank you for the correction. You are absolutely correct.

@weirdan
Copy link
Member

weirdan commented Dec 3, 2021

definitions for $query and $types are off by one

Psalm matches params to docblock tags by parameter name.

@orklah
Copy link
Collaborator

orklah commented Dec 3, 2021

small error on my part, you didn't push mixed[] but array<string, mixed[]> but the conclusion was the same

@martinsebastianwns
Copy link
Author

definitions for $query and $types are off by one

Psalm matches params to docblock tags by parameter name.

I know. I mixed it up when reading the param descriptions, the words "query" and "parameter" came off very prominent to me but the rest is history.

@spideyfusion
Copy link

Actually, we're getting hit with the same problem. I think that the updated stub introduced in #105 is incorrect, as the following code is perfectly valid, yet Psalm is complaining:

$this->entityManager->getConnection()->executeStatement($sql, [$uuids], [Connection::PARAM_STR_ARRAY]);

results in:

ERROR: InvalidArgument - some/path/Service.php:621:13 - Argument 2 of Doctrine\DBAL\Connection::executeStatement expects array<array-key, scalar>, array{int, array<array-key, mixed>} provided (see https://psalm.dev/004)
            [$uuids],

The doc block for the $params argument on the executeStatement method is:

@param array<int, mixed>|array<string, mixed> $params Statement parameters

Shouldn't the stub's parameter be mixed[] instead of scalar[] then?

@orklah
Copy link
Collaborator

orklah commented Jan 26, 2022

scalar[]|scalar[][] would probably be more helpful for users I think

Can you propose a PR?

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

No branches or pull requests

4 participants