fix: suppress PropertyNotSetInConstructor in Command/FormRequest

This commit is contained in:
Claas Augner 2021-07-06 23:12:41 +02:00
parent c8e0c5161e
commit 273411ad94
2 changed files with 30 additions and 0 deletions

View File

@ -0,0 +1,27 @@
<?php
namespace Psalm\LaravelPlugin\Handlers;
use Illuminate\Console\Command;
use Illuminate\Foundation\Http\FormRequest;
use Psalm\Plugin\EventHandler\AfterClassLikeVisitInterface;
use Psalm\Plugin\EventHandler\Event\AfterClassLikeVisitEvent;
use function in_array;
class SuppressHandler implements AfterClassLikeVisitInterface
{
public static function afterClassLikeVisit(AfterClassLikeVisitEvent $event)
{
$storage = $event->getStorage();
// Commands: suppress PropertyNotSetInConstructor.
if (in_array(Command::class, $storage->parent_classes) && !in_array('PropertyNotSetInConstructor', $storage->suppressed_issues)) {
$storage->suppressed_issues[] = 'PropertyNotSetInConstructor';
}
// FormRequest: suppress PropertyNotSetInConstructor.
if (in_array(FormRequest::class, $storage->parent_classes) && !in_array('PropertyNotSetInConstructor', $storage->suppressed_issues)) {
$storage->suppressed_issues[] = 'PropertyNotSetInConstructor';
}
}
}

View File

@ -12,6 +12,7 @@ use Psalm\LaravelPlugin\Handlers\Helpers\RedirectHandler;
use Psalm\LaravelPlugin\Handlers\Helpers\TransHandler;
use Psalm\LaravelPlugin\Handlers\Helpers\UrlHandler;
use Psalm\LaravelPlugin\Handlers\Helpers\ViewHandler;
use Psalm\LaravelPlugin\Handlers\SuppressHandler;
use Psalm\LaravelPlugin\Providers\ApplicationProvider;
use Psalm\LaravelPlugin\Providers\FacadeStubProvider;
use Psalm\LaravelPlugin\Providers\ModelStubProvider;
@ -75,6 +76,8 @@ class Plugin implements PluginEntryPointInterface
$registration->registerHooksFromClass(TransHandler::class);
require_once 'Handlers/Helpers/RedirectHandler.php';
$registration->registerHooksFromClass(RedirectHandler::class);
require_once 'Handlers/SuppressHandler.php';
$registration->registerHooksFromClass(SuppressHandler::class);
}
private function generateStubFiles(): void