Skip to content

Commit 6535bdf

Browse files
committed
Add static code analysis
1 parent 3d9f787 commit 6535bdf

9 files changed

Lines changed: 74 additions & 10 deletions

File tree

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: Static Analysis
2+
3+
on: [ push ]
4+
5+
jobs:
6+
PHPUnit:
7+
strategy:
8+
matrix:
9+
include:
10+
# Laravel 10.*
11+
- php: 8.3
12+
testbench: 8.*
13+
laravel: 10.*
14+
composer-flag: '--prefer-stable'
15+
# Laravel 11.*
16+
- php: 8.3
17+
testbench: 9.*
18+
laravel: 11.*
19+
composer-flag: '--prefer-stable'
20+
# Laravel 12.*
21+
- php: 8.4
22+
testbench: 10.*
23+
laravel: 12.*
24+
composer-flag: '--prefer-stable'
25+
# Laravel 13.*
26+
- php: 8.4
27+
testbench: 11.*
28+
laravel: 13.*
29+
composer-flag: '--prefer-stable'
30+
31+
runs-on: ubuntu-latest
32+
33+
steps:
34+
- uses: actions/checkout@v6
35+
36+
- name: Setup PHP
37+
uses: shivammathur/setup-php@v2
38+
with:
39+
php-version: ${{ matrix.php }}
40+
extensions: curl, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, iconv
41+
coverage: none
42+
43+
- name: Install dependencies
44+
run: composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update
45+
46+
- name: Update dependencies
47+
run: composer update ${{ matrix.composer-flag }} --prefer-dist --no-interaction
48+
49+
- name: Run PhpStan
50+
run: composer analyse

.github/workflows/unittests.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,9 @@ jobs:
129129
extensions: curl, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, iconv
130130
coverage: xdebug
131131

132+
- name: Remove larastan
133+
run: composer remove --dev larastan/larastan
134+
132135
- name: Install dependencies
133136
run: composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update
134137

composer.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,10 @@
2323
"illuminate/database": "^10|^11|^12|^13"
2424
},
2525
"require-dev": {
26+
"friendsofphp/php-cs-fixer": "^3.6",
27+
"larastan/larastan": "^3.0",
2628
"orchestra/testbench": "^8.0|^9.0|^10.0",
2729
"phpunit/phpunit": "^10|^11.5.3",
28-
"friendsofphp/php-cs-fixer": "^3.6",
2930
"squizlabs/php_codesniffer": "^3.5"
3031
},
3132
"autoload": {
@@ -42,7 +43,8 @@
4243
"test": "vendor/bin/phpunit",
4344
"test-coverage": "XDEBUG_MODE=coverage vendor/bin/phpunit --coverage-text --coverage-html coverage",
4445
"fix": "./vendor/bin/php-cs-fixer fix",
45-
"lint": "./vendor/bin/phpcs --extensions=php"
46+
"lint": "./vendor/bin/phpcs --extensions=php",
47+
"analyse": "@php ./vendor/bin/phpstan analyse --memory-limit=2G"
4648
},
4749
"extra": {
4850
"laravel": {

phpstan.neon

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
includes:
2+
- ./vendor/larastan/larastan/extension.neon
3+
4+
parameters:
5+
6+
paths:
7+
- src
8+
- tests
9+
10+
# Level 9 is the highest level
11+
level: 9

src/Rules/ExistsEloquent.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
use Closure;
88
use Illuminate\Contracts\Validation\ValidationRule;
9-
use Illuminate\Database\Eloquent\Builder;
109
use Illuminate\Database\Eloquent\Model;
1110
use Illuminate\Support\Str;
1211

@@ -142,7 +141,7 @@ public function validate(string $attribute, mixed $value, Closure $fail): void
142141
return;
143142
}
144143
}
145-
/** @var Model|Builder $builder */
144+
/** @var Model $builder */
146145
$builder = new $this->model();
147146
$modelKeyName = $builder->getKeyName();
148147
if (null === $this->key) {

src/Rules/UniqueEloquent.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
use Closure;
88
use Illuminate\Contracts\Validation\ValidationRule;
9-
use Illuminate\Database\Eloquent\Builder;
109
use Illuminate\Database\Eloquent\Model;
1110
use Illuminate\Support\Str;
1211

@@ -109,7 +108,7 @@ public function validate(string $attribute, mixed $value, Closure $fail): void
109108
return;
110109
}
111110
}
112-
/** @var Model|Builder $builder */
111+
/** @var Model $builder */
113112
$builder = new $this->model();
114113
$modelKeyName = $builder->getKeyName();
115114
$builder = $builder->where(null === $this->key ? $modelKeyName : $this->key, $value);

tests/TestCase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public function setUp(): void
2626

2727
/**
2828
* @param Application $app
29-
* @return array
29+
* @return array<int, class-string>
3030
*/
3131
protected function getPackageProviders($app): array
3232
{

tests/TestEnvironment/Models/Fact.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class Fact extends Model
2020
protected $guarded = [];
2121

2222
/**
23-
* @return BelongsTo<User>
23+
* @return BelongsTo<User, $this>
2424
*/
2525
public function user(): BelongsTo
2626
{

tests/TestEnvironment/Models/User.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ class User extends Model
2020
protected $guarded = [];
2121

2222
/**
23-
* @return HasMany<Fact>
23+
* @return HasMany<Fact, $this>
2424
*/
25-
public function user(): HasMany
25+
public function facts(): HasMany
2626
{
2727
return $this->hasMany(Fact::class);
2828
}

0 commit comments

Comments
 (0)