From 1122764333fc72ffa35e29cf5423fb557fc4af66 Mon Sep 17 00:00:00 2001 From: Benjamin Nussbaum Date: Tue, 17 Jun 2025 22:18:20 +0200 Subject: [PATCH] chore: add larastan --- app/Console/Commands/MashupCreateCommand.php | 3 +- app/Models/Device.php | 1 + app/Models/Playlist.php | 1 + app/Models/PlaylistItem.php | 5 +- app/Services/ImageGenerationService.php | 2 +- composer.json | 1 + composer.lock | 190 ++++++++++++++++++- phpstan.neon | 10 + 8 files changed, 209 insertions(+), 4 deletions(-) create mode 100644 phpstan.neon diff --git a/app/Console/Commands/MashupCreateCommand.php b/app/Console/Commands/MashupCreateCommand.php index 1022a2a..d6f1378 100644 --- a/app/Console/Commands/MashupCreateCommand.php +++ b/app/Console/Commands/MashupCreateCommand.php @@ -98,6 +98,7 @@ class MashupCreateCommand extends Command protected function selectPlaylist(Device $device): ?Playlist { + /** @var Collection|Playlist[] $playlists */ $playlists = $device->playlists; if ($playlists->isEmpty()) { $this->error('No playlists found for this device. Please create a playlist first.'); @@ -107,7 +108,7 @@ class MashupCreateCommand extends Command $playlistId = select( label: 'Select a playlist', - options: $playlists->mapWithKeys(fn ($playlist) => [$playlist->id => $playlist->name])->toArray() + options: $playlists->mapWithKeys(fn (Playlist $playlist) => [$playlist->id => $playlist->name])->toArray() ); return $playlists->firstWhere('id', $playlistId); diff --git a/app/Models/Device.php b/app/Models/Device.php index 52d6820..4e76909 100644 --- a/app/Models/Device.php +++ b/app/Models/Device.php @@ -142,6 +142,7 @@ class Device extends Model public function getNextPlaylistItem(): ?PlaylistItem { // Get all active playlists + /** @var \Illuminate\Support\Collection|Playlist[] $playlists */ $playlists = $this->playlists() ->where('is_active', true) ->get(); diff --git a/app/Models/Playlist.php b/app/Models/Playlist.php index 0945c1b..2a0527f 100644 --- a/app/Models/Playlist.php +++ b/app/Models/Playlist.php @@ -60,6 +60,7 @@ class Playlist extends Model } // Get active playlist items ordered by display order + /** @var \Illuminate\Support\Collection|PlaylistItem[] $playlistItems */ $playlistItems = $this->items() ->where('is_active', true) ->orderBy('order') diff --git a/app/Models/PlaylistItem.php b/app/Models/PlaylistItem.php index e3f3e28..2459257 100644 --- a/app/Models/PlaylistItem.php +++ b/app/Models/PlaylistItem.php @@ -2,6 +2,7 @@ namespace App\Models; +use Exception; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsTo; @@ -138,7 +139,9 @@ class PlaylistItem extends Model { if (! $this->isMashup()) { return view('trmnl-layouts.single', [ - 'slot' => $this->plugin->render('full', false), + 'slot' => $this->plugin instanceof Plugin + ? $this->plugin->render('full', false) + : throw new Exception('Invalid plugin instance'), ])->render(); } diff --git a/app/Services/ImageGenerationService.php b/app/Services/ImageGenerationService.php index 0c1b5a9..43b68d1 100644 --- a/app/Services/ImageGenerationService.php +++ b/app/Services/ImageGenerationService.php @@ -57,7 +57,7 @@ class ImageGenerationService case ImageFormat::PNG_8BIT_GRAYSCALE->value: case ImageFormat::PNG_8BIT_256C->value: try { - self::convertToPngImageMagick($pngPath, $device->width, $device->height, $device->rotate, quantize: $device->image_format === ImageFormat::PNG_8BIT_GRAYSCALE); + self::convertToPngImageMagick($pngPath, $device->width, $device->height, $device->rotate, quantize: $device->image_format === ImageFormat::PNG_8BIT_GRAYSCALE->value); } catch (ImagickException $e) { throw new RuntimeException('Failed to convert image to PNG: '.$e->getMessage(), 0, $e); } diff --git a/composer.json b/composer.json index a995526..be63349 100644 --- a/composer.json +++ b/composer.json @@ -25,6 +25,7 @@ }, "require-dev": { "fakerphp/faker": "^1.23", + "larastan/larastan": "^3.0", "laravel/pail": "^1.2.2", "laravel/pint": "^1.18", "laravel/sail": "^1.41", diff --git a/composer.lock b/composer.lock index 1ec8b05..07a5677 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "63075a49e79059d81034658d332d9dd8", + "content-hash": "29d4db93339349a577b09a89a73769f5", "packages": [ { "name": "aws/aws-crt-php", @@ -7508,6 +7508,47 @@ }, "time": "2025-04-30T06:54:44+00:00" }, + { + "name": "iamcal/sql-parser", + "version": "v0.6", + "source": { + "type": "git", + "url": "https://github.com/iamcal/SQLParser.git", + "reference": "947083e2dca211a6f12fb1beb67a01e387de9b62" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/iamcal/SQLParser/zipball/947083e2dca211a6f12fb1beb67a01e387de9b62", + "reference": "947083e2dca211a6f12fb1beb67a01e387de9b62", + "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.6" + }, + "time": "2025-03-17T16:59:46+00:00" + }, { "name": "jean85/pretty-package-versions", "version": "2.1.1", @@ -7568,6 +7609,95 @@ }, "time": "2025-03-19T14:43:43+00:00" }, + { + "name": "larastan/larastan", + "version": "v3.4.2", + "source": { + "type": "git", + "url": "https://github.com/larastan/larastan.git", + "reference": "36706736a0c51d3337478fab9c919d78d2e03404" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/larastan/larastan/zipball/36706736a0c51d3337478fab9c919d78d2e03404", + "reference": "36706736a0c51d3337478fab9c919d78d2e03404", + "shasum": "" + }, + "require": { + "ext-json": "*", + "iamcal/sql-parser": "^0.6.0", + "illuminate/console": "^11.44.2 || ^12.4.1", + "illuminate/container": "^11.44.2 || ^12.4.1", + "illuminate/contracts": "^11.44.2 || ^12.4.1", + "illuminate/database": "^11.44.2 || ^12.4.1", + "illuminate/http": "^11.44.2 || ^12.4.1", + "illuminate/pipeline": "^11.44.2 || ^12.4.1", + "illuminate/support": "^11.44.2 || ^12.4.1", + "php": "^8.2", + "phpstan/phpstan": "^2.1.11" + }, + "require-dev": { + "doctrine/coding-standard": "^13", + "laravel/framework": "^11.44.2 || ^12.7.2", + "mockery/mockery": "^1.6.12", + "nikic/php-parser": "^5.4", + "orchestra/canvas": "^v9.2.2 || ^10.0.1", + "orchestra/testbench-core": "^9.12.0 || ^10.1", + "phpstan/phpstan-deprecation-rules": "^2.0.1", + "phpunit/phpunit": "^10.5.35 || ^11.5.15" + }, + "suggest": { + "orchestra/testbench": "Using Larastan for analysing a package needs Testbench" + }, + "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.4.2" + }, + "funding": [ + { + "url": "https://github.com/canvural", + "type": "github" + } + ], + "time": "2025-06-10T09:34:58+00:00" + }, { "name": "laravel/pail", "version": "v1.2.3", @@ -8825,6 +8955,64 @@ }, "time": "2025-02-19T13:28:12+00:00" }, + { + "name": "phpstan/phpstan", + "version": "2.1.17", + "source": { + "type": "git", + "url": "https://github.com/phpstan/phpstan.git", + "reference": "89b5ef665716fa2a52ecd2633f21007a6a349053" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/89b5ef665716fa2a52ecd2633f21007a6a349053", + "reference": "89b5ef665716fa2a52ecd2633f21007a6a349053", + "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": "2025-05-21T20:55:28+00:00" + }, { "name": "phpunit/php-code-coverage", "version": "11.0.9", diff --git a/phpstan.neon b/phpstan.neon new file mode 100644 index 0000000..e5d841f --- /dev/null +++ b/phpstan.neon @@ -0,0 +1,10 @@ +includes: + - vendor/larastan/larastan/extension.neon + - vendor/nesbot/carbon/extension.neon + +parameters: + + paths: + - app/ + + level: 4