Skip to content

Commit ab1e1d3

Browse files
committed
Add missing PsalmApi::$issue->accepts
1 parent 94225dc commit ab1e1d3

File tree

3 files changed

+50
-0
lines changed

3 files changed

+50
-0
lines changed

src/Toolkit/Issue.php

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Fp\PsalmToolkit\Toolkit;
6+
7+
use Closure;
8+
use Fp\Functional\Option\Option;
9+
use Psalm\Issue\CodeIssue;
10+
use Psalm\IssueBuffer;
11+
use Psalm\Plugin\EventHandler\Event\AfterExpressionAnalysisEvent;
12+
use Psalm\Plugin\EventHandler\Event\AfterFunctionCallAnalysisEvent;
13+
use Psalm\Plugin\EventHandler\Event\AfterMethodCallAnalysisEvent;
14+
use Psalm\Plugin\EventHandler\Event\AfterStatementAnalysisEvent;
15+
use Psalm\Plugin\EventHandler\Event\FunctionReturnTypeProviderEvent;
16+
use Psalm\Plugin\EventHandler\Event\MethodReturnTypeProviderEvent;
17+
use Psalm\StatementsSource;
18+
19+
final class Issue
20+
{
21+
/**
22+
* @return Closure(CodeIssue): Option<empty>
23+
*/
24+
public function accepts(
25+
StatementsSource |
26+
AfterMethodCallAnalysisEvent |
27+
AfterFunctionCallAnalysisEvent |
28+
MethodReturnTypeProviderEvent |
29+
AfterStatementAnalysisEvent |
30+
FunctionReturnTypeProviderEvent |
31+
AfterExpressionAnalysisEvent $source,
32+
): Closure {
33+
$s = match (true) {
34+
$source instanceof StatementsSource => $source,
35+
$source instanceof AfterMethodCallAnalysisEvent => $source->getStatementsSource(),
36+
$source instanceof AfterFunctionCallAnalysisEvent => $source->getStatementsSource(),
37+
$source instanceof MethodReturnTypeProviderEvent => $source->getSource(),
38+
$source instanceof AfterStatementAnalysisEvent => $source->getStatementsSource(),
39+
$source instanceof FunctionReturnTypeProviderEvent => $source->getStatementsSource(),
40+
$source instanceof AfterExpressionAnalysisEvent => $source->getStatementsSource(),
41+
};
42+
43+
return function(CodeIssue $issue) use ($s) {
44+
IssueBuffer::accepts($issue, $s->getSuppressedIssues());
45+
return Option::none();
46+
};
47+
}
48+
}

src/Toolkit/Plugin.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public function __invoke(RegistrationInterface $registration, ?SimpleXMLElement
2323
PsalmApi::$args = new Args();
2424
PsalmApi::$classlikes = new Classlikes();
2525
PsalmApi::$codebase = ProjectAnalyzer::getInstance()->getCodebase();
26+
PsalmApi::$issue = new Issue();
2627

2728
$register = function(string $hook) use ($registration): void {
2829
if (class_exists($hook)) {

src/Toolkit/PsalmApi.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@ final class PsalmApi
1212
public static Types $types;
1313
public static Codebase $codebase;
1414
public static Classlikes $classlikes;
15+
public static Issue $issue;
1516
}

0 commit comments

Comments
 (0)