mirror of
https://github.com/nextcloud/server.git
synced 2025-12-18 15:56:14 -05:00
ci(psalm): Add a checker against logical operators
Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
parent
6ba4ca3d8f
commit
967a181403
2 changed files with 31 additions and 0 deletions
30
build/psalm/LogicalOperatorChecker.php
Normal file
30
build/psalm/LogicalOperatorChecker.php
Normal 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;
|
||||
}
|
||||
}
|
||||
|
|
@ -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"/>
|
||||
|
|
|
|||
Loading…
Reference in a new issue