mirror of
https://github.com/danog/psalm-plugin-laravel.git
synced 2024-11-26 20:34:48 +01:00
Added missing Builder methods - count() and whereDate()
This commit is contained in:
parent
183c230d33
commit
0b869cc153
@ -8,7 +8,7 @@ class DB extends Facade
|
||||
* Create a raw database expression.
|
||||
*
|
||||
* @param mixed $value
|
||||
* @return void
|
||||
* @return \Illuminate\Database\Query\Expression
|
||||
*
|
||||
* @psalm-taint-sink sql $value
|
||||
*/
|
||||
|
@ -73,6 +73,15 @@ class Builder
|
||||
*/
|
||||
public function where($column, $operator = null, $value = null, $boolean = 'and') { }
|
||||
|
||||
/**
|
||||
* @param string $column
|
||||
* @param string $operator
|
||||
* @param \DateTimeInterface|string|null $value
|
||||
* @param string $boolean
|
||||
* @return self<TModel>
|
||||
*/
|
||||
public function whereDate($column, $operator, $value = null, $boolean = 'and') { }
|
||||
|
||||
/**
|
||||
* @param \Closure|array|string $column
|
||||
* @param mixed $operator
|
||||
@ -347,4 +356,10 @@ class Builder
|
||||
* @return TModel|null
|
||||
*/
|
||||
public function first($columns = ['*']) { }
|
||||
|
||||
/**
|
||||
* @param string $columns
|
||||
* @return int
|
||||
*/
|
||||
public function count($columns = '*') { }
|
||||
}
|
||||
|
@ -23,8 +23,8 @@ Feature: DB facade alias
|
||||
|
||||
namespace Tests\Psalm\LaravelPlugin\Sandbox;
|
||||
|
||||
function test(): void {
|
||||
\DB::raw(1);
|
||||
function test(): \Illuminate\Database\Query\Expression {
|
||||
return \DB::raw(1);
|
||||
}
|
||||
"""
|
||||
When I run Psalm
|
||||
|
@ -225,3 +225,63 @@ Feature: Eloquent Builder types
|
||||
"""
|
||||
When I run Psalm
|
||||
Then I see no errors
|
||||
|
||||
Scenario: can call whereDate with \DateTimeInterface|string|null
|
||||
Given I have the following code
|
||||
"""
|
||||
/**
|
||||
* @psalm-param Builder $builder
|
||||
* @psalm-return Builder
|
||||
*/
|
||||
function test_whereDateWithDateTimeInterface(Builder $builder): Builder {
|
||||
return $builder->whereDate('created_at', '>', new \DateTimeImmutable());
|
||||
}
|
||||
|
||||
/**
|
||||
* @psalm-param Builder $builder
|
||||
* @psalm-return Builder
|
||||
*/
|
||||
function test_whereDateWithString(Builder $builder): Builder {
|
||||
return $builder->whereDate('created_at', '>', (new \DateTimeImmutable())->format('d/m/Y'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @psalm-param Builder $builder
|
||||
* @psalm-return Builder
|
||||
*/
|
||||
function test_whereDateWithNull(Builder $builder): Builder {
|
||||
return $builder->whereDate('created_at', '>', null);
|
||||
}
|
||||
"""
|
||||
When I run Psalm
|
||||
Then I see no errors
|
||||
|
||||
Scenario: can not call whereDate with incompatible type
|
||||
Given I have the following code
|
||||
"""
|
||||
/**
|
||||
* @psalm-param Builder $builder
|
||||
* @psalm-return Builder
|
||||
*/
|
||||
function test_whereDateWithInt(Builder $builder): Builder {
|
||||
return $builder->whereDate('created_at', '>', 1);
|
||||
}
|
||||
"""
|
||||
When I run Psalm
|
||||
Then I see these errors
|
||||
| Type | Message |
|
||||
| InvalidScalarArgument | Argument 3 of Illuminate\Database\Eloquent\Builder::whereDate expects DateTimeInterface\|null\|string, 1 provided |
|
||||
|
||||
Scenario: can call count on the builder instance
|
||||
Given I have the following code
|
||||
"""
|
||||
/**
|
||||
* @psalm-param Builder $builder
|
||||
* @psalm-return int
|
||||
*/
|
||||
function test_whereDateWithInt(Builder $builder): int {
|
||||
return $builder->count();
|
||||
}
|
||||
"""
|
||||
When I run Psalm
|
||||
Then I see no errors
|
||||
|
Loading…
Reference in New Issue
Block a user