55 - Add PHPStan and larastan static analysis

This commit is contained in:
myrmidex 2026-08-15 21:50:37 +02:00
parent 671cdb66ba
commit d2dfe44693
9 changed files with 223 additions and 4 deletions

View file

@ -58,6 +58,9 @@ jobs:
- name: Lint - name: Lint
run: vendor/bin/pint --test run: vendor/bin/pint --test
- name: Static analysis
run: vendor/bin/phpstan analyse --memory-limit=1G --no-progress --error-format=github
- name: Tests - name: Tests
run: php artisan test --coverage-clover coverage.xml --coverage-text run: php artisan test --coverage-clover coverage.xml --coverage-text

View file

@ -19,8 +19,9 @@ public function increment(): JsonResponse
} }
$tracker->increment('count'); $tracker->increment('count');
$tracker->refresh();
return response()->json(['count' => $tracker->refresh()->count]); return response()->json(['count' => $tracker->count]);
} }
public function update(Request $request): JsonResponse public function update(Request $request): JsonResponse

View file

@ -28,6 +28,9 @@ protected function casts(): array
]; ];
} }
/**
* @return BelongsTo<User, $this>
*/
public function user(): BelongsTo public function user(): BelongsTo
{ {
return $this->belongsTo(User::class); return $this->belongsTo(User::class);

View file

@ -32,6 +32,9 @@ protected function casts(): array
]; ];
} }
/**
* @return HasOne<Tracker, $this>
*/
public function tracker(): HasOne public function tracker(): HasOne
{ {
return $this->hasOne(Tracker::class); return $this->hasOne(Tracker::class);

View file

@ -17,11 +17,13 @@
}, },
"require-dev": { "require-dev": {
"fakerphp/faker": "^1.23", "fakerphp/faker": "^1.23",
"larastan/larastan": "^3.5",
"laravel/pail": "^1.2.2", "laravel/pail": "^1.2.2",
"laravel/pint": "^1.18", "laravel/pint": "^1.18",
"laravel/sail": "^1.43", "laravel/sail": "^1.43",
"mockery/mockery": "^1.6", "mockery/mockery": "^1.6",
"nunomaduro/collision": "^8.6", "nunomaduro/collision": "^8.6",
"phpstan/phpstan": "^2.1.32 <2.2",
"phpunit/phpunit": "^12.0" "phpunit/phpunit": "^12.0"
}, },
"autoload": { "autoload": {

186
composer.lock generated
View file

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "a30f9c47c86600aafedfd3862ac984c5", "content-hash": "48478688a363bdda6c30a93ad1a52636",
"packages": [ "packages": [
{ {
"name": "brick/math", "name": "brick/math",
@ -6424,6 +6424,137 @@
}, },
"time": "2025-04-30T06:54:44+00:00" "time": "2025-04-30T06:54:44+00:00"
}, },
{
"name": "iamcal/sql-parser",
"version": "v0.7",
"source": {
"type": "git",
"url": "https://github.com/iamcal/SQLParser.git",
"reference": "610392f38de49a44dab08dc1659960a29874c4b8"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/iamcal/SQLParser/zipball/610392f38de49a44dab08dc1659960a29874c4b8",
"reference": "610392f38de49a44dab08dc1659960a29874c4b8",
"shasum": ""
},
"require-dev": {
"php-coveralls/php-coveralls": "^1.0",
"phpunit/phpunit": "^5|^6|^7|^8|^9"
},
"type": "library",
"autoload": {
"psr-4": {
"iamcal\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Cal Henderson",
"email": "cal@iamcal.com"
}
],
"description": "MySQL schema parser",
"support": {
"issues": "https://github.com/iamcal/SQLParser/issues",
"source": "https://github.com/iamcal/SQLParser/tree/v0.7"
},
"time": "2026-01-28T22:20:33+00:00"
},
{
"name": "larastan/larastan",
"version": "v3.9.6",
"source": {
"type": "git",
"url": "https://github.com/larastan/larastan.git",
"reference": "9ad17e83e96b63536cb6ac39c3d40d29ff9cf636"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/larastan/larastan/zipball/9ad17e83e96b63536cb6ac39c3d40d29ff9cf636",
"reference": "9ad17e83e96b63536cb6ac39c3d40d29ff9cf636",
"shasum": ""
},
"require": {
"ext-json": "*",
"iamcal/sql-parser": "^0.7.0",
"illuminate/console": "^11.44.2 || ^12.4.1 || ^13",
"illuminate/container": "^11.44.2 || ^12.4.1 || ^13",
"illuminate/contracts": "^11.44.2 || ^12.4.1 || ^13",
"illuminate/database": "^11.44.2 || ^12.4.1 || ^13",
"illuminate/http": "^11.44.2 || ^12.4.1 || ^13",
"illuminate/pipeline": "^11.44.2 || ^12.4.1 || ^13",
"illuminate/support": "^11.44.2 || ^12.4.1 || ^13",
"php": "^8.2",
"phpstan/phpstan": "^2.1.44"
},
"require-dev": {
"doctrine/coding-standard": "^13",
"laravel/framework": "^11.44.2 || ^12.7.2 || ^13",
"mockery/mockery": "^1.6.12",
"nikic/php-parser": "^5.4",
"orchestra/canvas": "^v9.2.2 || ^10.0.1 || ^11",
"orchestra/testbench-core": "^9.12.0 || ^10.1 || ^11",
"phpstan/phpstan-deprecation-rules": "^2.0.1",
"phpunit/phpunit": "^10.5.35 || ^11.5.15 || ^12.5.8"
},
"suggest": {
"orchestra/testbench": "Using Larastan for analysing a package needs Testbench",
"phpmyadmin/sql-parser": "Install to enable Larastan's optional phpMyAdmin-based SQL parser automatically"
},
"type": "phpstan-extension",
"extra": {
"phpstan": {
"includes": [
"extension.neon"
]
},
"branch-alias": {
"dev-master": "3.0-dev"
}
},
"autoload": {
"psr-4": {
"Larastan\\Larastan\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Can Vural",
"email": "can9119@gmail.com"
}
],
"description": "Larastan - Discover bugs in your code without running it. A phpstan/phpstan extension for Laravel",
"keywords": [
"PHPStan",
"code analyse",
"code analysis",
"larastan",
"laravel",
"package",
"php",
"static analysis"
],
"support": {
"issues": "https://github.com/larastan/larastan/issues",
"source": "https://github.com/larastan/larastan/tree/v3.9.6"
},
"funding": [
{
"url": "https://github.com/canvural",
"type": "github"
}
],
"time": "2026-04-16T10:02:43+00:00"
},
{ {
"name": "laravel/pail", "name": "laravel/pail",
"version": "v1.2.6", "version": "v1.2.6",
@ -6992,6 +7123,59 @@
}, },
"time": "2022-02-21T01:04:05+00:00" "time": "2022-02-21T01:04:05+00:00"
}, },
{
"name": "phpstan/phpstan",
"version": "2.1.56",
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/phpstan/phpstan/zipball/93a603c9fc3be8c3c93bbc8d22170ad766685537",
"reference": "93a603c9fc3be8c3c93bbc8d22170ad766685537",
"shasum": ""
},
"require": {
"php": "^7.4|^8.0"
},
"conflict": {
"phpstan/phpstan-shim": "*"
},
"bin": [
"phpstan",
"phpstan.phar"
],
"type": "library",
"autoload": {
"files": [
"bootstrap.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"description": "PHPStan - PHP Static Analysis Tool",
"keywords": [
"dev",
"static analysis"
],
"support": {
"docs": "https://phpstan.org/user-guide/getting-started",
"forum": "https://github.com/phpstan/phpstan/discussions",
"issues": "https://github.com/phpstan/phpstan/issues",
"security": "https://github.com/phpstan/phpstan/security/policy",
"source": "https://github.com/phpstan/phpstan-src"
},
"funding": [
{
"url": "https://github.com/ondrejmirtes",
"type": "github"
},
{
"url": "https://github.com/phpstan",
"type": "github"
}
],
"time": "2026-05-26T17:04:57+00:00"
},
{ {
"name": "phpunit/php-code-coverage", "name": "phpunit/php-code-coverage",
"version": "12.5.6", "version": "12.5.6",

21
phpstan.neon Normal file
View file

@ -0,0 +1,21 @@
includes:
- vendor/larastan/larastan/extension.neon
parameters:
level: 7
paths:
- app/
- database/
- tests/
excludePaths:
- bootstrap/*.php
- storage/*
ignoreErrors:
# Migration files return an anonymous class; the base Migration declares neither up() nor down().
# An interface on the migration is not an option: it would live under autoload-dev, which
# production omits (`composer install --no-dev`), so every migration would fatal on deploy.
-
message: '#Call to an undefined method Illuminate\\Database\\Migrations\\Migration::(up|down)\(\)#'
path: tests/Feature/*MigrationTest.php

View file

@ -4,6 +4,7 @@
namespace Tests\Feature; namespace Tests\Feature;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema; use Illuminate\Support\Facades\Schema;
@ -16,7 +17,7 @@ class CountBackfillMigrationTest extends TestCase
private const MIGRATION = __DIR__.'/../../database/migrations/2026_08_15_000002_add_count_to_trackers_drop_entries.php'; private const MIGRATION = __DIR__.'/../../database/migrations/2026_08_15_000002_add_count_to_trackers_drop_entries.php';
// Each require returns a fresh anonymous-class instance; there is no name to collide. // Each require returns a fresh anonymous-class instance; there is no name to collide.
private function migration(): object private function migration(): Migration
{ {
return require self::MIGRATION; return require self::MIGRATION;
} }

View file

@ -4,6 +4,7 @@
namespace Tests\Feature; namespace Tests\Feature;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema; use Illuminate\Support\Facades\Schema;
@ -14,7 +15,7 @@ class DropAssetsMigrationTest extends TestCase
use RefreshDatabase; use RefreshDatabase;
// Each require returns a fresh anonymous-class instance; there is no name to collide. // Each require returns a fresh anonymous-class instance; there is no name to collide.
private function migration(): object private function migration(): Migration
{ {
return require __DIR__.'/../../database/migrations/2026_08_15_000003_drop_assets_and_pricing.php'; return require __DIR__.'/../../database/migrations/2026_08_15_000003_drop_assets_and_pricing.php';
} }