mirror of
https://github.com/danog/psalm-plugin-laravel.git
synced 2024-11-30 04:39:01 +01:00
Merge pull request #170 from caugner/model-@property-support
fix: Support @property on Model with imported type
This commit is contained in:
commit
0e2f510f2e
@ -50,7 +50,8 @@ final class ModelStubProvider implements GeneratesStubs
|
||||
|
||||
$models_generator_command->run(
|
||||
new ArrayInput([
|
||||
'--nowrite' => true
|
||||
'--nowrite' => true,
|
||||
'--reset' => true,
|
||||
]),
|
||||
new NullOutput()
|
||||
);
|
||||
|
22
tests/Models/AbstractUuidModel.php
Normal file
22
tests/Models/AbstractUuidModel.php
Normal file
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Psalm\LaravelPlugin\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Str;
|
||||
use Ramsey\Uuid\UuidInterface;
|
||||
|
||||
/**
|
||||
* @property-read UuidInterface $uuid
|
||||
*/
|
||||
abstract class AbstractUuidModel extends Model
|
||||
{
|
||||
protected static function boot()
|
||||
{
|
||||
parent::boot();
|
||||
|
||||
static::creating(function (Model $model) {
|
||||
$model->setAttribute('uuid', Str::uuid());
|
||||
});
|
||||
}
|
||||
}
|
6
tests/Models/Secret.php
Normal file
6
tests/Models/Secret.php
Normal file
@ -0,0 +1,6 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Tests\Psalm\LaravelPlugin\Models;
|
||||
|
||||
final class Secret extends AbstractUuidModel {
|
||||
};
|
@ -2,6 +2,7 @@
|
||||
|
||||
namespace Tests\Psalm\LaravelPlugin\Models;
|
||||
|
||||
use Carbon\CarbonInterface;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasManyThrough;
|
||||
@ -9,6 +10,7 @@ use Illuminate\Database\Eloquent\Relations\HasOne;
|
||||
|
||||
/**
|
||||
* @property string $id
|
||||
* @property CarbonInterface|null $email_verified_at
|
||||
*/
|
||||
final class User extends Model {
|
||||
protected $table = 'users';
|
||||
|
59
tests/acceptance/EloquentModelPropertyTypes.feature
Normal file
59
tests/acceptance/EloquentModelPropertyTypes.feature
Normal file
@ -0,0 +1,59 @@
|
||||
Feature: Eloquent Model property types
|
||||
Illuminate\Database\Eloquent\Model have property type support
|
||||
|
||||
Background:
|
||||
Given I have the following config
|
||||
"""
|
||||
<?xml version="1.0"?>
|
||||
<psalm totallyTyped="true" usePhpDocPropertiesWithoutMagicCall="true">
|
||||
<projectFiles>
|
||||
<directory name="."/>
|
||||
<ignoreFiles> <directory name="../../vendor"/> </ignoreFiles>
|
||||
</projectFiles>
|
||||
<plugins>
|
||||
<pluginClass class="Psalm\LaravelPlugin\Plugin"/>
|
||||
</plugins>
|
||||
</psalm>
|
||||
"""
|
||||
And I have the following code preamble
|
||||
"""
|
||||
<?php declare(strict_types=1);
|
||||
namespace Tests\Psalm\LaravelPlugin\Sandbox;
|
||||
|
||||
use Tests\Psalm\LaravelPlugin\Models\Secret;
|
||||
use Tests\Psalm\LaravelPlugin\Models\User;
|
||||
"""
|
||||
|
||||
Scenario: Property annotation with scalar type
|
||||
Given I have the following code
|
||||
"""
|
||||
function test(User $user): string
|
||||
{
|
||||
return $user->id;
|
||||
}
|
||||
"""
|
||||
When I run Psalm
|
||||
Then I see no errors
|
||||
|
||||
Scenario: Property annotation with imported type
|
||||
Given I have the following code
|
||||
"""
|
||||
function test(User $user): ?\Carbon\CarbonInterface
|
||||
{
|
||||
return $user->email_verified_at;
|
||||
}
|
||||
"""
|
||||
When I run Psalm
|
||||
Then I see no errors
|
||||
|
||||
|
||||
Scenario: Inherited property annotation
|
||||
Given I have the following code
|
||||
"""
|
||||
function test(Secret $secret): \Ramsey\Uuid\UuidInterface
|
||||
{
|
||||
return $secret->uuid;
|
||||
}
|
||||
"""
|
||||
When I run Psalm
|
||||
Then I see no errors
|
Loading…
Reference in New Issue
Block a user