From a94249d1d52472630c5a5884350fdfc5dcfbe0e6 Mon Sep 17 00:00:00 2001 From: provokateurin Date: Sat, 27 Jul 2024 22:34:06 +0200 Subject: [PATCH] build(psalm): Enforce named attribute arguments Signed-off-by: provokateurin --- build/psalm/AttributeNamedParameters.php | 53 ++++++++++++++++++++++++ psalm.xml | 1 + 2 files changed, 54 insertions(+) create mode 100644 build/psalm/AttributeNamedParameters.php 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 @@ +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) + ) + ); + } + } + } +} diff --git a/psalm.xml b/psalm.xml index f2aed4b382b..05ea0ef20bc 100644 --- a/psalm.xml +++ b/psalm.xml @@ -16,6 +16,7 @@ > +