mirror of
https://github.com/danog/psalm-plugin-laravel.git
synced 2024-12-11 08:40:00 +01:00
64 lines
1.6 KiB
Gherkin
64 lines
1.6 KiB
Gherkin
Feature: Eloquent Collection Types
|
|
Illuminate\Database\Eloquent\Collection has type support
|
|
|
|
Background:
|
|
Given I have the following config
|
|
"""
|
|
<?xml version="1.0"?>
|
|
<psalm totallyTyped="true">
|
|
<projectFiles>
|
|
<directory name="."/>
|
|
<ignoreFiles> <directory name="../../vendor"/> </ignoreFiles>
|
|
</projectFiles>
|
|
<plugins>
|
|
<pluginClass class="Psalm\LaravelPlugin\Plugin"/>
|
|
</plugins>
|
|
</psalm>
|
|
"""
|
|
|
|
Scenario:
|
|
Given I have the following code
|
|
"""
|
|
<?php declare(strict_types=1);
|
|
|
|
namespace Tests\Psalm\LaravelPlugin\Models;
|
|
|
|
class User extends \Illuminate\Database\Eloquent\Model {
|
|
protected $table = 'users';
|
|
};
|
|
|
|
final class UserRepository
|
|
{
|
|
/**
|
|
* @psalm-return \Illuminate\Database\Eloquent\Collection<User>
|
|
*/
|
|
public function getAll(): \Illuminate\Database\Eloquent\Collection
|
|
{
|
|
return User::all();
|
|
}
|
|
|
|
public function getFirst(): ?User
|
|
{
|
|
return $this->getAll()->first();
|
|
}
|
|
|
|
/**
|
|
* @return \Illuminate\Database\Eloquent\Builder<User>
|
|
*/
|
|
public function getBuilder(): \Illuminate\Database\Eloquent\Builder
|
|
{
|
|
return User::where();
|
|
}
|
|
|
|
/**
|
|
* @psalm-return \Illuminate\Database\Eloquent\Collection<User>
|
|
*/
|
|
public function getWhere(array $attributes): \Illuminate\Database\Eloquent\Collection
|
|
{
|
|
return User::where($attributes)->get();
|
|
}
|
|
}
|
|
"""
|
|
When I run Psalm
|
|
Then I see no errors
|