Skip to content

Commit

Permalink
Create SuppressMissingThrowsDocblockHook.php
Browse files Browse the repository at this point in the history
Signed-off-by: Nathanael Esayeas <nathanael.esayeas@protonmail.com>
  • Loading branch information
ghostwriter committed Aug 27, 2023
1 parent e74b3d4 commit d8c787f
Showing 1 changed file with 47 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

declare(strict_types=1);

namespace Ghostwriter\PsalmPlugin\Hook\PHPUnit\Framework\TestCase;

use Ghostwriter\PsalmPlugin\AbstractBeforeAddIssueEventHook;
use PHPUnit\Framework\TestCase;
use Psalm\Issue\MissingThrowsDocblock;
use Psalm\Plugin\EventHandler\Event\BeforeAddIssueEvent;

final class SuppressMissingThrowsDocblockHook extends AbstractBeforeAddIssueEventHook
{
/**
* @return false|null
*/
public static function beforeAddIssue(BeforeAddIssueEvent $event): ?bool
{
$codeIssue = $event->getIssue();

if (!$codeIssue instanceof MissingThrowsDocblock) {
return self::IGNORE;
}

$codeLocation = $codeIssue->code_location;

$codebase = $event->getCodebase();

foreach ($codebase->classlike_storage_provider->getAll() as $storage) {
if (null === $storage->location) {
continue;
}

if ($storage->location->file_path !== $codeLocation->file_path) {
continue;
}

if (!$codebase->classExtends($storage->name, TestCase::class)) {
continue;
}

return self::SUPPRESS;
}

return self::IGNORE;
}
}

0 comments on commit d8c787f

Please sign in to comment.