ci(psalm): Add a checker against logical operators

Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
Joas Schilling 2025-11-07 12:07:25 +01:00
parent 6ba4ca3d8f
commit 967a181403
No known key found for this signature in database
GPG key ID: F72FA5B49FFA96B0
2 changed files with 31 additions and 0 deletions

View file

@ -0,0 +1,30 @@
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
use Psalm\CodeLocation;
use Psalm\IssueBuffer;
use Psalm\Plugin\EventHandler\AfterExpressionAnalysisInterface;
use Psalm\Plugin\EventHandler\Event\AfterExpressionAnalysisEvent;
class LogicalOperatorChecker implements AfterExpressionAnalysisInterface {
public static function afterExpressionAnalysis(AfterExpressionAnalysisEvent $event): ?bool {
$stmt = $event->getExpr();
if ($stmt instanceof PhpParser\Node\Expr\BinaryOp\LogicalAnd
|| $stmt instanceof PhpParser\Node\Expr\BinaryOp\LogicalOr) {
IssueBuffer::maybeAdd(
new \Psalm\Issue\UnrecognizedExpression(
'Logical binary operators AND and OR are not allowed in the Nextcloud codebase',
new CodeLocation($event->getStatementsSource()->getSource(), $stmt),
),
$event->getStatementsSource()->getSuppressedIssues(),
);
}
return null;
}
}

View file

@ -17,6 +17,7 @@
<plugins>
<plugin filename="build/psalm/AppFrameworkTainter.php" />
<plugin filename="build/psalm/AttributeNamedParameters.php" />
<plugin filename="build/psalm/LogicalOperatorChecker.php" />
</plugins>
<projectFiles>
<directory name="apps/admin_audit"/>