From ecf051c35b6d0969356635376178d3a54fd2ef53 Mon Sep 17 00:00:00 2001 From: John Charman Date: Tue, 27 Feb 2024 11:02:28 +0000 Subject: [PATCH] Ignore PHPStan complaining about missing Laravel helper methods. - These methods will be present within any Laravel project. --- phpstan.neon | 3 +++ src/ServiceProvider.php | 32 +++++++++++++++++++++++--------- 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/phpstan.neon b/phpstan.neon index c158993..fa13787 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -2,3 +2,6 @@ parameters: level: 9 paths: - src + ignoreErrors: + - '#^Function config not found.$#' # config() is a Laravel helper method + - '#^Function config_path not found.$#' # config_path() is a Laravel helper method diff --git a/src/ServiceProvider.php b/src/ServiceProvider.php index 9573fe6..ad6e24e 100644 --- a/src/ServiceProvider.php +++ b/src/ServiceProvider.php @@ -15,15 +15,21 @@ class ServiceProvider extends \Illuminate\Support\ServiceProvider { private const CONFIG_PATH = __DIR__ . '/../config/membrane.php'; + private const CONFIG_NAME = 'membrane'; public function boot(): void { - /** @phpstan-ignore-next-line */ // config_path is a laravel framework helper method - $this->publishes([self::CONFIG_PATH => config_path('membrane.php')], [self::CONFIG_NAME]); + $this->publishes( + [self::CONFIG_PATH => config_path('membrane.php')], + [self::CONFIG_NAME] + ); if ($this->app->runningInConsole()) { - $this->commands([CacheOpenAPIRoutes::class, CacheOpenAPIProcessors::class]); + $this->commands([ + CacheOpenAPIRoutes::class, + CacheOpenAPIProcessors::class + ]); } } @@ -53,15 +59,23 @@ public function register(): void /** @return Builder[] */ private function instantiateBuilders(): array { - /** @phpstan-ignore-next-line */ // config is a laravel framework helper method - if (!file_exists(config('membrane.routes_file')) || empty(config('membrane.additional_builders'))) { + if ( + !file_exists(config('membrane.routes_file')) || + empty(config('membrane.additional_builders')) + ) { return []; } - /** @phpstan-ignore-next-line */ // config is a laravel framework helper method - $router = new Router(new RouteCollection(include config('membrane.routes_file'))); + $router = new Router( + new RouteCollection(include config('membrane.routes_file')) + ); - /** @phpstan-ignore-next-line */ // config is a laravel framework helper method - return array_map(fn($className) => new $className($router), config('membrane.additional_builders')); + return array_filter( + array_map( + fn($className) => new $className($router), + config('membrane.additional_builders') + ), + fn($class) => $class instanceof Builder, + ); } }