From 4b1eb23c3d9af64794be2ca33d56978d26dc7007 Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Mon, 10 Jan 2022 13:42:50 +0100 Subject: [PATCH] Update to new psalm API --- composer.json | 5 +++++ hooks/InsaneComparisonAnalyzer.php | 23 +++++++++++------------ 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/composer.json b/composer.json index 9d4427c..e247a0d 100644 --- a/composer.json +++ b/composer.json @@ -27,5 +27,10 @@ "require-dev": { "vimeo/psalm": "^4.0", "nikic/php-parser": "^4.0" + }, + "config": { + "allow-plugins": { + "composer/package-versions-deprecated": true + } } } diff --git a/hooks/InsaneComparisonAnalyzer.php b/hooks/InsaneComparisonAnalyzer.php index a7e489e..6968db3 100644 --- a/hooks/InsaneComparisonAnalyzer.php +++ b/hooks/InsaneComparisonAnalyzer.php @@ -5,30 +5,29 @@ declare(strict_types=1); namespace Orklah\PsalmInsaneComparison\Hooks; use PhpParser\Node\Expr; -use Psalm\Codebase; use Psalm\CodeLocation; -use Psalm\Context; use Psalm\Internal\Type\Comparator\UnionTypeComparator; use Psalm\Issue\PluginIssue; use Psalm\IssueBuffer; -use Psalm\Plugin\Hook\AfterExpressionAnalysisInterface; -use Psalm\StatementsSource; +use Psalm\Plugin\EventHandler\AfterExpressionAnalysisInterface; +use Psalm\Plugin\EventHandler\Event\AfterExpressionAnalysisEvent; use Psalm\Type; use Psalm\Type\Atomic\TLiteralInt; use Psalm\Type\Atomic\TLiteralString; use Psalm\Type\Atomic\TPositiveInt; -use Psalm\Type\Atomic\TSingleLetter; class InsaneComparisonAnalyzer implements AfterExpressionAnalysisInterface { - public static function afterExpressionAnalysis( - Expr $expr, - Context $context, - StatementsSource $statements_source, - Codebase $codebase, - array &$file_replacements = [] - ): ?bool + /** + * Called after an expression has been checked + * + * @return null|false + */ + public static function afterExpressionAnalysis(AfterExpressionAnalysisEvent $event): ?bool { + $expr = $event->getExpr(); + $statements_source = $event->getStatementsSource(); + $codebase = $event->getCodebase(); if (!$expr instanceof Expr\BinaryOp\Equal && !$expr instanceof Expr\BinaryOp\NotEqual) { return true; }