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

Ignore PHPStan complaining about missing Laravel helper methods. #21

Merged
merged 1 commit into from
Feb 27, 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: 3 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -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
32 changes: 23 additions & 9 deletions src/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
]);
}
}

Expand Down Expand Up @@ -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,
);
}
}