Skip to content

Commit

Permalink
feat: adds missing typehints to query builder stub (#1821)
Browse files Browse the repository at this point in the history
  • Loading branch information
lribi committed Feb 12, 2024
1 parent d05f410 commit c3fd4b2
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 6 deletions.
10 changes: 5 additions & 5 deletions stubs/10.0.0/QueryBuilder.stub
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class Builder
* @param string $as
* @param \Closure|string $first
* @param string|null $operator
* @param string|null $second
* @param \Illuminate\Contracts\Database\Query\Expression|string|null $second
* @param string $type
* @param bool $where
* @return $this
Expand All @@ -25,7 +25,7 @@ class Builder
/**
* Add a basic where clause to the query.
*
* @param \Closure|string|array<string|int, mixed> $column
* @param \Closure|string|array<string|int, mixed>|\Illuminate\Contracts\Database\Query\Expression $column
* @param mixed $operator
* @param mixed $value
* @param string $boolean
Expand All @@ -46,7 +46,7 @@ class Builder
/**
* Add an "or where" clause to the query.
*
* @param \Closure|model-property|array<model-property|int, mixed> $column
* @param \Closure|model-property|array<model-property|int, mixed>|\Illuminate\Contracts\Database\Query\Expression $column
* @param mixed $operator
* @param mixed $value
* @return $this
Expand Down Expand Up @@ -106,7 +106,7 @@ class Builder
/**
* Add a "where null" clause to the query.
*
* @param string|array<string> $columns
* @param string|array<string>|\Illuminate\Contracts\Database\Query\Expression $columns
* @param string $boolean
* @param bool $not
* @return $this
Expand All @@ -116,7 +116,7 @@ class Builder
/**
* Add a "where not null" clause to the query.
*
* @param string|array<string> $columns
* @param string|array<string>|\Illuminate\Contracts\Database\Query\Expression $columns
* @param string $boolean
* @return $this
*/
Expand Down
4 changes: 4 additions & 0 deletions tests/Type/GeneralTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ public static function dataFileAsserts(): iterable
yield from self::gatherAssertTypes(__DIR__.'/data/model-relations-l10-20.php');
}

if (version_compare(LARAVEL_VERSION, '10.24.0', '>=')) {
yield from self::gatherAssertTypes(__DIR__.'/data/query-builder-l10-24.php');
}

//##############################################################################################################

// Console Commands
Expand Down
53 changes: 53 additions & 0 deletions tests/Type/data/query-builder-l10-24.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

declare(strict_types=1);

namespace QueryBuilder;

use Illuminate\Support\Facades\DB;

use function PHPStan\Testing\assertType;

function testJoinSubExpressionParameter(): void
{
$subQuery = DB::table('addresses')
->select(['id', 'user_id']);

$builder = DB::table('users')
->joinSub($subQuery, 'addresses', 'users.user_id', '=', DB::raw('addresses.user_id'));

assertType('Illuminate\Database\Query\Builder', $builder);
}

function testWhereExpressionParameter(): void
{
$builder = DB::table('users')
->where(DB::raw('id'), '=', 1);

assertType('Illuminate\Database\Query\Builder', $builder);
}

function testOrWhereExpressionParameter(): void
{
$builder = DB::table('users')
->where(DB::raw('id'), '=', 1)
->orWhere(DB::raw('id'), '=', 2);

assertType('Illuminate\Database\Query\Builder', $builder);
}

function testWhereNullExpressionParameter(): void
{
$builder = DB::table('users')
->whereNull(DB::raw('email_verified_at'));

assertType('Illuminate\Database\Query\Builder', $builder);
}

function testWhereNotNullExpressionParameter(): void
{
$builder = DB::table('users')
->whereNotNull(DB::raw('email_verified_at'));

assertType('Illuminate\Database\Query\Builder', $builder);
}
2 changes: 1 addition & 1 deletion tests/Type/data/query-builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace EloquentBuilder;
namespace QueryBuilder;

use Illuminate\Support\Facades\DB;

Expand Down

0 comments on commit c3fd4b2

Please sign in to comment.