Skip to content

refactor(QueryBuilder): Properly type the query builder#57763

Open
CarlSchwan wants to merge 1 commit intomasterfrom
carl/type-querybuilder
Open

refactor(QueryBuilder): Properly type the query builder#57763
CarlSchwan wants to merge 1 commit intomasterfrom
carl/type-querybuilder

Conversation

@CarlSchwan
Copy link
Member

@CarlSchwan CarlSchwan commented Jan 23, 2026

  • Resolves: #

Summary

TODO

  • ...

Checklist

@CarlSchwan CarlSchwan added this to the Nextcloud 34 milestone Jan 23, 2026
@CarlSchwan CarlSchwan self-assigned this Jan 23, 2026
@CarlSchwan CarlSchwan added 2. developing Work in progress feature: database Database related DB labels Jan 23, 2026
@CarlSchwan CarlSchwan force-pushed the carl/type-querybuilder branch 7 times, most recently from 4949aa8 to 27c24e9 Compare January 26, 2026 10:02
@CarlSchwan CarlSchwan force-pushed the carl/type-querybuilder branch 2 times, most recently from 75af4a1 to ca05129 Compare January 27, 2026 10:17
@CarlSchwan CarlSchwan added 3. to review Waiting for reviews and removed 2. developing Work in progress labels Jan 27, 2026
@CarlSchwan CarlSchwan marked this pull request as ready for review January 27, 2026 10:18
@CarlSchwan CarlSchwan requested review from Altahrim, ArtificialOwl, icewind1991 and sorbaugh and removed request for a team January 27, 2026 10:18
Comment on lines +258 to +259
parent::innerJoin($fromAlias, $join, $alias, $condition);
return $this;
Copy link
Contributor

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.

Copy link
Member Author

Choose a reason for hiding this comment

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

doesn't work :/

@CarlSchwan CarlSchwan force-pushed the carl/type-querybuilder branch 2 times, most recently from 97b14e1 to efaca86 Compare January 28, 2026 17:31
And make sure the related unit tests are also typed and checked by
psalm.

Signed-off-by: Carl Schwan <carlschwan@kde.org>
@CarlSchwan CarlSchwan force-pushed the carl/type-querybuilder branch from efaca86 to 4020f91 Compare January 30, 2026 14:28
Copy link
Member

@provokateurin provokateurin left a comment

Choose a reason for hiding this comment

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

Please add all files you touched to psalm:strict and rector:strict. That will probably result in some more issues being found, but I think it's worth fixing them in such an important part of our codebase.

@@ -326,17 +325,17 @@ public function setFirstResult($firstResult);
* @return int The position of the first result.
* @since 8.2.0
*/
public function getFirstResult();
public function getFirstResult(): int;

/**
* Sets the maximum number of results to retrieve (the "limit").
*
* @param int|null $maxResults The maximum number of results to retrieve.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
* @param int|null $maxResults The maximum number of results to retrieve.
* @param positive-int|null $maxResults The maximum number of results to retrieve.


/**
* Gets all defined query parameter types for the query being constructed indexed by parameter index or name.
*
* @return array The currently defined query parameter types indexed by parameter index or name.
* @return list<self::PARAM_*> The currently defined query parameter types indexed by parameter index or name.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
* @return list<self::PARAM_*> The currently defined query parameter types indexed by parameter index or name.
* @return array<string|int, self::PARAM_*> The currently defined query parameter types indexed by parameter index or name.

@@ -267,47 +266,47 @@ public function setParameter($key, $value, $type = null);
*
* @param array $params The query parameters to set.
* @param array $types The query parameters types to set.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
* @param array $types The query parameters types to set.
* @param array<string|int, mixed> $params The query parameters to set.
* @param array<string|int, self::PARAM_*> $types The query parameters types to set.

Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
* @param non-negative-int $firstResult The first result to return.

@@ -345,7 +344,7 @@ public function setMaxResults($maxResults);
* @return int|null The maximum number of results.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
* @return int|null The maximum number of results.
* @return positive-int|null The maximum number of results.

* @return $this This QueryBuilder instance.
*
* @see where()
* @since 8.2.0
*
* @psalm-taint-sink sql $where
*/
public function orWhere(...$where);
public function orWhere(...$where): self;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
public function orWhere(...$where): self;
public function orWhere(mixed ...$where): self;

* @since 8.2.0
*
* @psalm-taint-sink sql $groupBys
*/
public function groupBy(...$groupBys);
public function groupBy(...$groupBys): self;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
public function groupBy(...$groupBys): self;
public function groupBy(mixed ...$groupBys): self;

* @since 8.2.0
*
* @psalm-taint-sink sql $groupby
*/
public function addGroupBy(...$groupBy);
public function addGroupBy(...$groupBy): self;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
public function addGroupBy(...$groupBy): self;
public function addGroupBy(mixed ...$groupBy): self;

* @since 8.2.0
*
* @psalm-taint-sink sql $having
*/
public function having(...$having);
public function having(...$having): self;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
public function having(...$having): self;
public function having(mixed ...$having): self;

Copy link
Member

Choose a reason for hiding this comment

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

mixed should be replaced by string|IParameter|IQueryFunction|ILiteral in almost all places.
Also non-empty-string could be used on most methods, but it's not that important.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

3. to review Waiting for reviews feature: database Database related DB

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

Comments