Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Laravel 11 support #364

Merged
merged 2 commits into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ name: PHP CS check

on:
push:
branches: [master]
paths:
- '**.php'
- 'composer.json'
Expand All @@ -23,7 +24,7 @@ jobs:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.1
php-version: 8.2
coverage: none
tools: cs2pr

Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/psalm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ name: Psalm

on:
push:
branches: [master]
paths:
- '**.php'
- 'psalm*'
Expand All @@ -12,6 +13,7 @@ on:
- '**.php'
- 'psalm*'
- 'composer.json'
- '.github/workflows/psalm.yml'

jobs:
psalm:
Expand All @@ -23,7 +25,7 @@ jobs:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.2'
php-version: 8.2
coverage: none

- name: Install composer dependencies
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/test-laravel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ name: Test laravel projects

on:
push:
branches: [master]
paths:
- '**.php'
- '**.stubphp'
Expand All @@ -13,8 +14,10 @@ on:
paths:
- '**.php'
- '**.stubphp'
- 'composer.json'
- 'tests/laravel*'
- 'tests/lumen*'
- '.github/workflows/test-laravel.yml'

jobs:
build:
Expand Down
19 changes: 10 additions & 9 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ name: Tests
on:
workflow_dispatch:
push:
branches: [master]
paths:
- '**.php'
- '**.stubphp'
Expand All @@ -16,6 +17,7 @@ on:
- '**.stubphp'
- '**.feature'
- 'composer.json'
- '.github/workflows/test.yml'
schedule:
- cron: "0 6 * * *"

Expand All @@ -31,7 +33,7 @@ jobs:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.0
php-version: 8.2
coverage: none
tools: composer:v2

Expand All @@ -51,11 +53,13 @@ jobs:
fail-fast: true
matrix:
php: [8.3, 8.2, 8.0]
laravel: [^10.0, ^9.0]
laravel: [^11.0, ^10.0, ^9.0]
dependencies: [lowest, highest]
exclude:
- php: 8.0
laravel: ^10.0
- php: 8.0
laravel: ^11.0
name: Acceptance P${{ matrix.php }} | L${{ matrix.laravel }} | ${{ matrix.dependencies == 'highest' && '↑' || '↓' }}
steps:
- name: Checkout code
Expand All @@ -69,13 +73,10 @@ jobs:
coverage: none
tools: composer

- name: Install lowest dependencies from composer.json
if: "matrix.dependencies == 'lowest'"
run: composer update --with='laravel/framework:${{ matrix.laravel }}' --no-interaction --no-progress --prefer-dist --prefer-stable --prefer-lowest

- name: Install highest dependencies from composer.json
if: "matrix.dependencies == 'highest'"
run: composer update --with='laravel/framework:${{ matrix.laravel }}' --no-interaction --no-progress --prefer-dist --prefer-stable
- name: Install dependencies from composer.json
run: |
composer require "illuminate/support:${{ matrix.laravel }}" --no-update
composer update --no-interaction --no-progress --prefer-dist --prefer-stable ${{ matrix.dependencies == 'lowest' && '--prefer-lowest' || '' }}

- name: Run Acceptance Tests
run: composer test:type
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ At this moment, the package is maintained almost solely by [@alies-dev](https://
who can constantly improve this package and the whole Psalm ecosystem.

Some ideas to implement:
- [ ] Add support for Laravel 11 (easy)
- [ ] Fully support custom Model Query Builders (medium)
- [ ] Add an option to rely on Model `@property` declarations only
- [ ] Get rid of `barryvdh/laravel-ide-helper` dependency and be more accurate with attribute types
Expand All @@ -32,10 +31,10 @@ This [Psalm](https://github.com/vimeo/psalm) plugin brings static analysis and t

## Versions & Dependencies

| Laravel Psalm Plugin | PHP | Laravel | Psalm |
|----------------------|-------|-------------|-------|
| 2.x | ^8.0 | 8, 9, 10 | 4, 5 |
| 1.x | ^7.1 | 5, 6, 7, 8 | 3, 4 |
| Laravel Psalm Plugin | PHP | Laravel | Psalm |
|----------------------|-------|--------------|-------|
| 2.x | ^8.0 | 8, 9, 10, 11 | 4, 5 |
| 1.x | ^7.1 | 5, 6, 7, 8 | 3, 4 |

See [releases](https://github.com/psalm/psalm-plugin-laravel/releases) for more details about supported PHP, Laravel and Psalm versions.

Expand Down
26 changes: 13 additions & 13 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,19 @@
"require": {
"php": "^8.0.2",
"ext-simplexml": "*",
"barryvdh/laravel-ide-helper": "^2.13",
"illuminate/config": "^9.48 || ^10.0",
"illuminate/container": "^9.48 || ^10.0",
"illuminate/contracts": "^9.48 || ^10.0",
"illuminate/database": "^9.48 || ^10.0",
"illuminate/events": "^9.48 || ^10.0",
"illuminate/http": "^9.48 || ^10.0",
"illuminate/routing": "^9.48 || ^10.0",
"illuminate/support": "^9.48 || ^10.0",
"illuminate/view": "^9.48 || ^10.0",
"barryvdh/laravel-ide-helper": "^2.13 || ^3.0",
"illuminate/config": "^9.48 || ^10.0 || ^11.0",
"illuminate/container": "^9.48 || ^10.0 || ^11.0",
"illuminate/contracts": "^9.48 || ^10.0 || ^11.0",
"illuminate/database": "^9.48 || ^10.0 || ^11.0",
"illuminate/events": "^9.48 || ^10.0 || ^11.0",
"illuminate/http": "^9.48 || ^10.0 || ^11.0",
"illuminate/routing": "^9.48 || ^10.0 || ^11.0",
"illuminate/support": "^9.48 || ^10.0 || ^11.0",
"illuminate/view": "^9.48 || ^10.0 || ^11.0",
"nikic/php-parser": "^4.13",
"orchestra/testbench": "^7.19 || ^8.0",
"symfony/console": "^6.0",
"orchestra/testbench": "^7.19 || ^8.0 || ^9.0",
"symfony/console": "^6.0 || ^7.0",
"vimeo/psalm": "^4.30 || ^5.1"
},
"require-dev": {
Expand All @@ -38,7 +38,7 @@
"ramsey/collection": "^1.3",
"slevomat/coding-standard": "^8.8",
"squizlabs/php_codesniffer": "*",
"symfony/http-foundation": "^6.0"
"symfony/http-foundation": "^6.0 || ^7.0"
},
"minimum-stability": "dev",
"prefer-stable": true,
Expand Down
2 changes: 1 addition & 1 deletion src/Fakes/FakeFilesystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ final class FakeFilesystem extends Filesystem
*/
public function put($path, $contents, $lock = false)
{
$destination = $this->destination ?: $path;
$destination = $this->destination !== null ? $this->destination : $path;

$this->destination = null;

Expand Down
2 changes: 1 addition & 1 deletion src/Handlers/Eloquent/ModelMethodHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public static function getMethodReturnType(MethodReturnTypeProviderEvent $event)
if ($event->getMethodNameLowercase() === '__callstatic') {
$called_method_name_lowercase = $event->getCalledMethodNameLowercase();

if (!$called_method_name_lowercase) {
if ($called_method_name_lowercase === null) {
return null;
}
$methodId = new MethodIdentifier($called_fq_classlike_name, $called_method_name_lowercase);
Expand Down
2 changes: 1 addition & 1 deletion src/Handlers/Eloquent/Schema/SchemaColumn.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@ public function __construct(
$this->name = $name;
$this->type = $type;
$this->nullable = $nullable;
$this->options = $options ?: [];
$this->options = $options !== null ? $options : [];
}
}
2 changes: 1 addition & 1 deletion src/Providers/ViewFactoryProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public static function get(): Factory

$file_path = $service_helper_reflection->getFileName();

if (!$file_path) {
if ($file_path === false) {
throw new UnexpectedValueException('Service helper should have a file path');
}

Expand Down
19 changes: 17 additions & 2 deletions tests/Acceptance/acceptance/FoundationHelpers.feature
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,30 @@ Feature: Foundation helpers
When I run Psalm
Then I see no errors

Scenario: app() support: env can be pulled off the app
Scenario: app() support: env can be pulled off the app [ Psalm <5.20 ]
Given I have the following code
"""
if (app()->environment('production')) {
// do something
}
"""
And I have Psalm older than "5.20.0" (because of "changed issue type")
When I run Psalm
Then I see no errors

Scenario: app() support: env can be pulled off the app [ Psalm >5.20 ]
Given I have the following code
"""
if (app()->environment('production')) {
// do something
}
"""
And I have Psalm newer than "5.20.0" (because of "changed issue type")
When I run Psalm
Then I see these errors
| Type | Message |
| RiskyTruthyFalsyComparison | Operand of type bool\|string contains type string, which can be falsy and truthy. This can cause possibly unexpected behavior. Use strict comparison instead. |

Scenario: auth() support
Given I have the following code
"""
Expand Down Expand Up @@ -187,14 +201,15 @@ Feature: Foundation helpers
When I run Psalm
Then I see no errors

Scenario: precognitive() support
Scenario: precognitive() support [ Psalm 5 ]
Given I have the following code
"""
$payload = precognitive(function () {
return ['foo' => 'bar'];
});
/** @psalm-check-type $payload = array{'foo': 'bar'} */
"""
And I have Psalm newer than "5.0" (because of "new psalm-check-type syntax")
When I run Psalm
Then I see no errors

Expand Down
6 changes: 4 additions & 2 deletions tests/Acceptance/acceptance/PathHelpers.feature
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,13 @@ Feature: Path helpers
| Type | Message |
| MissingFile | Cannot find file |

Scenario: public path can be resolved from application instance
Scenario: public path can be resolved from application instance [ Psalm 5 ]
Given I have the following code
"""
/** @psalm-check-type $path = string */
$path = app()->make('path.public');
"""
And I have Psalm newer than "5.0" (because of "new psalm-check-type syntax")
When I run Psalm
Then I see no errors

Expand Down Expand Up @@ -150,11 +151,12 @@ Feature: Path helpers
| Type | Message |
| MissingFile | Cannot find file |

Scenario: storage path can be resolved from application instance
Scenario: storage path can be resolved from application instance [ Psalm 5 ]
Given I have the following code
"""
/** @psalm-check-type $path = string */
$path = app()->make('path.storage');
"""
And I have Psalm newer than "5.0" (because of "new psalm-check-type syntax")
When I run Psalm
Then I see no errors
5 changes: 5 additions & 0 deletions tests/Application/laravel-test-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,11 @@
<code>ExampleProvider</code>
</UnusedClass>
</file>
<file src="app/Providers/RouteServiceProvider.php">
<RiskyTruthyFalsyComparison>
<code><![CDATA[$request->user()?->id]]></code>
</RiskyTruthyFalsyComparison>
</file>
<file src="app/Rules/ExampleRule.php">
<UnusedClass>
<code>ExampleRule</code>
Expand Down
3 changes: 3 additions & 0 deletions tests/Application/lumen-test-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@
<code>User</code>
<code>User</code>
</PropertyNotSetInConstructor>
<NonInvariantDocblockPropertyType>
<code>$fillable</code>
</NonInvariantDocblockPropertyType>
</file>
<file src="app/Providers/AuthServiceProvider.php">
<MissingClosureParamType>
Expand Down