Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions build/psalm/LogicalOperatorChecker.php
Original file line number Diff line number Diff line change
@@ -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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
|| $stmt instanceof PhpParser\Node\Expr\BinaryOp\LogicalOr) {
or $stmt instanceof PhpParser\Node\Expr\BinaryOp\LogicalOr) {

/s

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;
}
}
1 change: 1 addition & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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"/>
Expand Down
Loading