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

Use better typing in QueryBuilder #4220

Closed
wants to merge 2 commits into from

Conversation

greg0ire
Copy link
Member

Summary

That class is a bit hard to understand, so I tried to be as precise as possible while keeping both Psalm and Phpstan happy (which means I couldn't be as precise as I wanted).

@greg0ire greg0ire force-pushed the describe-sql-parts branch from 88956cc to e9f7f69 Compare August 23, 2020 12:43
@greg0ire
Copy link
Member Author

@morozov while working on this, I noticed that upgrading Psalm produced many errors related to the named parameters RFC, because of changes in parameter names between abstractions and concretions. I could have sworn you already worked on this, but could not find anything. Can you point me to a PR where you worked on this? We might want to backport it.

@morozov
Copy link
Member

morozov commented Aug 23, 2020

@greg0ire, must be #4172.

@@ -414,6 +430,8 @@ public function getMaxResults()
* @param bool $append
*
* @return $this This QueryBuilder instance.
*
* @psalm-param 'select'|'from'|'set'|'where'|'groupBy'|'having'|'orderBy'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missed param name

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, this reveals I missed join and values

@@ -1273,7 +1291,7 @@ public function __toString()
* @link http://www.zetacomponents.org
*
* @param mixed $value
* @param mixed $type
* @param int $type
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dbal supports to use string as bind type, isn't it?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How so? You mean by using string instead of ParameterType::STRING, which is an integer?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be compatible with:

* @param mixed $type Either a PDO binding type or a DBAL mapping type name or instance.

which is also not annotated properly. It's string|int|Type|null (see other branches).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I annotated both (and more) as you described.

It makes it easier for Psalm (and arguably for humans) to understand
this piece of code.
@greg0ire greg0ire force-pushed the describe-sql-parts branch from e9f7f69 to 9936a2a Compare August 23, 2020 13:59
@greg0ire
Copy link
Member Author

Ok, I thought it was on higher branches but no, it's just that there are other signatures that are affected by this. I created #4221 to keep track of that

@greg0ire greg0ire requested a review from morozov August 23, 2020 14:29
@greg0ire greg0ire force-pushed the describe-sql-parts branch from 9936a2a to 1ebaa93 Compare August 23, 2020 14:35
@greg0ire greg0ire force-pushed the describe-sql-parts branch from 1ebaa93 to 8514fbb Compare August 23, 2020 17:23
@greg0ire greg0ire closed this Aug 23, 2020
@greg0ire greg0ire reopened this Aug 23, 2020
@greg0ire greg0ire closed this Aug 23, 2020
@greg0ire greg0ire reopened this Aug 23, 2020
@@ -187,6 +202,8 @@ public function getConnection()
* Gets the state of this query builder instance.
*
* @return int Either QueryBuilder::STATE_DIRTY or QueryBuilder::STATE_CLEAN.
*
* @psalm-return QueryBuilder::STATE_*
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this different from the type of $state?

* @param string $placeHolder The name to bind with. The string must start with a colon ':'.
* @param mixed $value
* @param string|int|Type|null $type
* @param string $placeHolder The name to bind with. The string must start with a colon ':'.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should it be string|null?

@morozov
Copy link
Member

morozov commented Aug 23, 2020

Given that none of the issues found during the review were found by any of the static analysis tools, what's the point of this improvement at this moment? Is it a pre-condition for say Psalm update?

@greg0ire greg0ire force-pushed the describe-sql-parts branch from 8514fbb to 51bfc87 Compare August 23, 2020 18:56
@greg0ire
Copy link
Member Author

greg0ire commented Aug 23, 2020

Given that none of the issues found during the review were found by any of the static analysis tools, what's the point of this improvement at this moment? Is it a pre-condition for say Psalm update?

Not at all, what prompted me to do this is #4219 , where I noticed that the code was hard to understand because of all the possibilities of the structure in $sqlParts. I tried to describe it accurately, but was quickly faced with hard to overcome issues, so resolved to use mixed for most key, sadly. So I'd say it has more to do with helping people than SA tools understand this class.
Do you think I should re-target to an upper branch?

@morozov
Copy link
Member

morozov commented Aug 23, 2020

Instead of beating the dead horse, why don't we backport the relevant changes from master (#3830, #3832, #3833) to 3.0.x and leave 2.x alone?

@greg0ire
Copy link
Member Author

Ok, I'll close this, it didn't turn out as good as I hoped anyway.

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

Successfully merging this pull request may close these issues.

3 participants