-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
refactor(QueryBuilder): Properly type the query builder #57763
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
base: master
Are you sure you want to change the base?
Conversation
4949aa8 to
27c24e9
Compare
27c24e9 to
75af4a1
Compare
And make sure the related unit tests are also typed and checked by psalm. Signed-off-by: Carl Schwan <carlschwan@kde.org>
75af4a1 to
ca05129
Compare
| */ | ||
| public function eq($x, $y, $type = null): string { | ||
| #[Override] | ||
| public function eq(string|ILiteral|IQueryFunction|IParameter $x, IQueryFunction|ILiteral|IParameter|string $y, int|string|null $type = null): string { |
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.
| public function eq(string|ILiteral|IQueryFunction|IParameter $x, IQueryFunction|ILiteral|IParameter|string $y, int|string|null $type = null): string { | |
| public function eq( | |
| string|ILiteral|IQueryFunction|IParameter $x, | |
| IQueryFunction|ILiteral|IParameter|string $y, | |
| int|string|null $type = null, | |
| ): string { |
Please split on several lines when types get that complicated.
| */ | ||
| public function like($x, $y, $type = null): string { | ||
| #[Override] | ||
| public function like(ILiteral|IParameter|IQueryFunction|string $x, mixed $y, mixed $type = null): string { |
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.
Why are these parameters mixed and not the same as the other methods above?
| * @return string | ||
| */ | ||
| public function notIn($x, $y, $type = null): string { | ||
| #[Override] |
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.
All the types parameter in the file should be typed the same way.
| parent::innerJoin($fromAlias, $join, $alias, $condition); | ||
| return $this; |
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 think if you properly type the methods with @return $this in phpdoc you do not need to split all these return parent::… into 2 lines, as $this of self and parent is the same.
| * @since 12.0.0 | ||
| */ | ||
| public function concat($x, ...$expr): IQueryFunction; | ||
| public function concat(string|ILiteral|IParameter|IQueryFunction $x, ...$expr): IQueryFunction; |
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 believe you can type the variadic parameter as well.
| * Gets the type of the currently built query. | ||
| * | ||
| * @return integer | ||
| * @deprecated Since 34.0.0, if necessary, track the type of the query being built outside of the builder. |
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.
| * @deprecated Since 34.0.0, if necessary, track the type of the query being built outside of the builder. | |
| * @deprecated 34.0.0 If necessary, track the type of the query being built outside of the builder. |
| * @param mixed $value The parameter value. | ||
| * @param string|null|int $type One of the IQueryBuilder::PARAM_* constants. | ||
| * | ||
| * @return $this This QueryBuilder instance. |
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 think we should have the @return $this on all fluent methods. It’s stronger typing than : self.
| * @param mixed $key The key (index or name) of the bound parameter type. | ||
| * @param int|string $key The key (index or name) of the bound parameter type. | ||
| * | ||
| * @return mixed The value of the bound parameter type. |
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 guess it’s the type and not the value?
And probably string|int and not mixed?
Summary
TODO
Checklist
3. to review, feature component)stable32)