aboutsummaryrefslogtreecommitdiffstats
path: root/build/psalm
diff options
context:
space:
mode:
authorprovokateurin <kate@provokateurin.de>2024-07-27 22:34:06 +0200
committerprovokateurin <kate@provokateurin.de>2024-07-27 22:36:18 +0200
commita94249d1d52472630c5a5884350fdfc5dcfbe0e6 (patch)
treeefd8c6b9a5c3af78307cab8619900838ec4a1329 /build/psalm
parent212a621697cd32b65ea78fa90015cec9d9d1dfe3 (diff)
downloadnextcloud-server-a94249d1d52472630c5a5884350fdfc5dcfbe0e6.tar.gz
nextcloud-server-a94249d1d52472630c5a5884350fdfc5dcfbe0e6.zip
build(psalm): Enforce named attribute arguments
Signed-off-by: provokateurin <kate@provokateurin.de>
Diffstat (limited to 'build/psalm')
-rw-r--r--build/psalm/AttributeNamedParameters.php53
1 files changed, 53 insertions, 0 deletions
diff --git a/build/psalm/AttributeNamedParameters.php b/build/psalm/AttributeNamedParameters.php
new file mode 100644
index 00000000000..0b34cf3cf22
--- /dev/null
+++ b/build/psalm/AttributeNamedParameters.php
@@ -0,0 +1,53 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-only
+ */
+
+use PhpParser\Node\Attribute;
+use Psalm\CodeLocation;
+use Psalm\FileSource;
+use Psalm\Issue\InvalidDocblock;
+use Psalm\IssueBuffer;
+use Psalm\Plugin\EventHandler\Event\AfterClassLikeVisitEvent;
+
+class AttributeNamedParameters implements Psalm\Plugin\EventHandler\AfterClassLikeVisitInterface {
+ public static function afterClassLikeVisit(AfterClassLikeVisitEvent $event): void {
+ $stmt = $event->getStmt();
+ $statementsSource = $event->getStatementsSource();
+
+ foreach ($stmt->attrGroups as $attrGroup) {
+ foreach ($attrGroup->attrs as $attr) {
+ self::checkAttribute($attr, $statementsSource);
+ }
+ }
+
+ foreach ($stmt->getMethods() as $method) {
+ foreach ($method->attrGroups as $attrGroup) {
+ foreach ($attrGroup->attrs as $attr) {
+ self::checkAttribute($attr, $statementsSource);
+ }
+ }
+ }
+ }
+
+ private static function checkAttribute(Attribute $stmt, FileSource $statementsSource): void {
+ if ($stmt->name->getLast() === 'Attribute') {
+ return;
+ }
+
+ foreach ($stmt->args as $arg) {
+ if ($arg->name === null) {
+ IssueBuffer::maybeAdd(
+ new InvalidDocblock(
+ 'Attribute arguments must be named.',
+ new CodeLocation($statementsSource, $stmt)
+ )
+ );
+ }
+ }
+ }
+}