Skip to content

Commit

Permalink
Merge pull request #21 from membrane-php/ignore-missing-laravel-methods
Browse files Browse the repository at this point in the history
Ignore PHPStan complaining about missing Laravel helper methods.
  • Loading branch information
charjr authored Feb 27, 2024
2 parents 456b5cf + ecf051c commit ede6935
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 9 deletions.
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,
);
}
}

0 comments on commit ede6935

Please sign in to comment.