Skip to content

Commit

Permalink
Merge pull request #242 from danog/master
Browse files Browse the repository at this point in the history
Psalm 5 support
  • Loading branch information
orklah authored Dec 1, 2022
2 parents 39e4241 + 2888815 commit 681b22c
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 27 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"illuminate/routing": "^8.0 || ^9.0",
"illuminate/support": "^8.0 || ^9.0",
"illuminate/view": "^8.0 || ^9.0",
"vimeo/psalm": "^4.8.1",
"vimeo/psalm": "^4.8.1|^5",
"orchestra/testbench": "^6.22 || ^7.0",
"barryvdh/laravel-ide-helper": "^2.10"
},
Expand Down
5 changes: 1 addition & 4 deletions src/Handlers/Eloquent/ModelRelationshipPropertyHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,7 @@ public static function getPropertyType(PropertyTypeProviderEvent $event): ?Union

$relationType = $atomicType;

foreach ($atomicType->getChildNodes() as $childNode) {
if (!$childNode instanceof Union) {
continue;
}
foreach ($atomicType->type_params as $childNode) {
foreach ($childNode->getAtomicTypes() as $atomicType) {
if (!$atomicType instanceof Type\Atomic\TNamedObject) {
continue;
Expand Down
21 changes: 0 additions & 21 deletions src/Handlers/SuppressHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@

class SuppressHandler implements AfterClassLikeVisitInterface
{
/**
* @var array<string, list<class-string>>
*/
private const BY_CLASS = [
'UnusedClass' => [
'App\Console\Kernel',
Expand All @@ -33,18 +30,12 @@ class SuppressHandler implements AfterClassLikeVisitInterface
],
];

/**
* @var array<string, array<class-string, list<string>>>
*/
private const BY_CLASS_METHOD = [
'PossiblyUnusedMethod' => [
'App\Http\Middleware\RedirectIfAuthenticated' => ['handle'],
],
];

/**
* @var array<string, list<class-string>>
*/
private const BY_NAMESPACE = [
'PropertyNotSetInConstructor' => [
'App\Jobs',
Expand All @@ -55,9 +46,6 @@ class SuppressHandler implements AfterClassLikeVisitInterface
],
];

/**
* @var array<string, array<class-string, list<string>>>
*/
private const BY_NAMESPACE_METHOD = [
'PossiblyUnusedMethod' => [
'App\Events' => ['broadcastOn'],
Expand All @@ -67,9 +55,6 @@ class SuppressHandler implements AfterClassLikeVisitInterface
]
];

/**
* @var array<string, list<class-string>>
*/
private const BY_PARENT_CLASS = [
'PropertyNotSetInConstructor' => [
'Illuminate\Console\Command',
Expand All @@ -79,18 +64,12 @@ class SuppressHandler implements AfterClassLikeVisitInterface
],
];

/**
* @var array<string, array<class-string, list<string>>>
*/
private const BY_PARENT_CLASS_PROPERTY = [
'NonInvariantDocblockPropertyType' => [
'Illuminate\Console\Command' => ['description'],
],
];

/**
* @var array<string, array<class-string, list<string>>>
*/
private const BY_USED_TRAITS = [
'PropertyNotSetInConstructor' => [
'Illuminate\Queue\InteractsWithQueue',
Expand Down
20 changes: 19 additions & 1 deletion tests/acceptance/EloquentBuilderTypes.feature
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ Feature: Eloquent Builder types
When I run Psalm
Then I see no errors

Scenario: can not call whereDate with incompatible type
Scenario: can not call whereDate with incompatible type [ Psalm 4 ]
Given I have the following code
"""
/**
Expand All @@ -264,11 +264,29 @@ Feature: Eloquent Builder types
return $builder->whereDate('created_at', '>', 1);
}
"""
And I have Psalm older than "4.99.0" (because of "changed issue type")
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 not call whereDate with incompatible type [ Psalm 5 ]
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);
}
"""
And I have Psalm newer than "4.99.0" (because of "changed issue type")
When I run Psalm
Then I see these errors
| Type | Message |
| InvalidArgument | Argument 3 of Illuminate\Database\Eloquent\Builder::whereDate expects DateTimeInterface\|null\|string, but 1 provided |

Scenario: can call count on the builder instance
Given I have the following code
"""
Expand Down

0 comments on commit 681b22c

Please sign in to comment.