Skip to content

[13.x] Modernize Database Query Builder with Native Property Types#59486

Draft
genius-asif-hub wants to merge 1 commit intolaravel:13.xfrom
genius-asif-hub:feature/modernize-query-builder
Draft

[13.x] Modernize Database Query Builder with Native Property Types#59486
genius-asif-hub wants to merge 1 commit intolaravel:13.xfrom
genius-asif-hub:feature/modernize-query-builder

Conversation

@genius-asif-hub
Copy link
Copy Markdown

This PR modernizes the Illuminate\Database\Query\Builder class by adding native PHP property type hints to properties that were previously only type-hinted in docblocks.

Why this is important:

  • Static Analysis: Significantly improves the accuracy of PHPStan and Larastan analysis for the core.
  • Modernization: Aligns the database component with Laravel 13's push for native PHP 8.2+ type safety.
  • Zero Bloat: This is a pure technical improvement that removes documentation redundancy and improves runtime safety without adding new logic or methods.

Changes:

  • Added native types to $connection, $grammar, $processor, $bindings, $columns, $wheres, $joins, $limit, $offset, and 15+ other core properties.
  • Initialized typed properties to null where appropriate to prevent "uninitialized property" access errors.
  • Added necessary imports for IndexHint and others.

Verified with vendor/bin/phpunit tests/Database/ - All tests passing.

@genius-asif-hub genius-asif-hub force-pushed the feature/modernize-query-builder branch from af27a11 to f540e94 Compare April 1, 2026 16:21
@genius-asif-hub genius-asif-hub marked this pull request as draft April 1, 2026 16:24
@browner12
Copy link
Copy Markdown
Contributor

You have absolutely 0% chance of getting this merged to the 13.x branch. At a minimum it must go to master, and even then the maintainers are unlikely to accept it.

Copy link
Copy Markdown
Contributor

@shaedrich shaedrich left a comment

Choose a reason for hiding this comment

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

Adding native types over PHPDoc block ones requires targeting master/14.x

Furthermore, I would advise against changing formatting when this is not part of what the PR is trying to solve

/**
* The table joins for the query.
*
* @var array|null
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You can type this array:

Suggested change
* @var array|null
* @var array<\Illuminate\Database\Query\JoinClause>|null

@@ -112,163 +112,195 @@ class Builder implements BuilderContract
*
* @var bool|array
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You can narrow this further down:

Suggested change
* @var bool|array
* @var bool|array<\Illuminate\Contracts\Database\Query\Expression|string>>

/**
* The where constraints for the query.
*
* @var array
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You can type this, too:

Suggested change
* @var array
* @var array{
* type: 'Expression'|'Basic'|'JsonBoolean'|'Bitwise'|'NullSafeEquals'|'Null'|'NotNull',
* column: string|\Illuminate\Contracts\Database\Query\Expression,
* operator: string,
* value: mixed,
* boolean: 'and'|'or'
* }[]

/**
* The groupings for the query.
*
* @var array|null
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You may type this:

Suggested change
* @var array|null
* @var array<\Illuminate\Contracts\Database\Query\Expression|string>|null

/**
* The having constraints for the query.
*
* @var array|null
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

See $where

/**
* The orderings for the query.
*
* @var array|null
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This might be typed as well:

Suggested change
* @var array|null
* @var array{
* column: \Illuminate\Contracts\Database\Query\Expression|string,
* direction: 'asc'|'desc'
* }[]|null

/**
* The query union statements.
*
* @var array|null
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Also typeable:

Suggested change
* @var array|null
* @var array{
* query: \Closure|\Illuminate\Database\Query\Builder|\Illuminate\Database\Eloquent\Builder<*>,
* all: bool
* }[]|null

/**
* The callbacks that should be invoked before the query is executed.
*
* @var array
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Same here:

Suggested change
* @var array
* @var array<\Closure(\Illuminate\Database\Query\Builder): mixed>

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

Successfully merging this pull request may close these issues.

4 participants