Skip to content

Commit 967a181

Browse files
committed
ci(psalm): Add a checker against logical operators
Signed-off-by: Joas Schilling <[email protected]>
1 parent 6ba4ca3 commit 967a181

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
7+
* SPDX-License-Identifier: AGPL-3.0-or-later
8+
*/
9+
10+
use Psalm\CodeLocation;
11+
use Psalm\IssueBuffer;
12+
use Psalm\Plugin\EventHandler\AfterExpressionAnalysisInterface;
13+
use Psalm\Plugin\EventHandler\Event\AfterExpressionAnalysisEvent;
14+
15+
class LogicalOperatorChecker implements AfterExpressionAnalysisInterface {
16+
public static function afterExpressionAnalysis(AfterExpressionAnalysisEvent $event): ?bool {
17+
$stmt = $event->getExpr();
18+
if ($stmt instanceof PhpParser\Node\Expr\BinaryOp\LogicalAnd
19+
|| $stmt instanceof PhpParser\Node\Expr\BinaryOp\LogicalOr) {
20+
IssueBuffer::maybeAdd(
21+
new \Psalm\Issue\UnrecognizedExpression(
22+
'Logical binary operators AND and OR are not allowed in the Nextcloud codebase',
23+
new CodeLocation($event->getStatementsSource()->getSource(), $stmt),
24+
),
25+
$event->getStatementsSource()->getSuppressedIssues(),
26+
);
27+
}
28+
return null;
29+
}
30+
}

psalm.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
<plugins>
1818
<plugin filename="build/psalm/AppFrameworkTainter.php" />
1919
<plugin filename="build/psalm/AttributeNamedParameters.php" />
20+
<plugin filename="build/psalm/LogicalOperatorChecker.php" />
2021
</plugins>
2122
<projectFiles>
2223
<directory name="apps/admin_audit"/>

0 commit comments

Comments
 (0)