From 3f2082ef2e98b3080a749098a74f09b636419afd Mon Sep 17 00:00:00 2001 From: provokateurin Date: Fri, 6 Sep 2024 09:39:13 +0200 Subject: [PATCH] build: Add psalm plugin to ensure OCP implementations have no doc block Signed-off-by: provokateurin --- build/psalm/OcInheritDoc.php | 64 ++++++++++++++++++++++++++++++++++++ psalm.xml | 1 + 2 files changed, 65 insertions(+) create mode 100644 build/psalm/OcInheritDoc.php diff --git a/build/psalm/OcInheritDoc.php b/build/psalm/OcInheritDoc.php new file mode 100644 index 00000000000..38cc78e2e73 --- /dev/null +++ b/build/psalm/OcInheritDoc.php @@ -0,0 +1,64 @@ +getStmt(); + $statementsSource = $event->getStatementsSource(); + + if (!$childClass instanceof Class_) { + return; + } + + $childClassName = $childClass->getAttribute('namespacedName')?->toString() ?? ''; + if (!str_starts_with($childClassName, 'OC\\')) { + return; + } + + /** @var Name $impl */ + foreach ($childClass->implements as $impl) { + $parentClassName = $impl->getAttribute('resolvedName') ?? ''; + if ($parentClassName === 'OCP\\Capabilities\\ICapability' || $parentClassName === 'OCP\\Capabilities\\IPublicCapability' || !str_starts_with($parentClassName, 'OCP\\')) { + continue; + } + + $parentClass = new ReflectionClass($parentClassName); + $parentMethods = $parentClass->getMethods(); + + foreach ($childClass->getMethods() as $childMethod) { + foreach ($parentMethods as $parentMethod) { + if (strtolower($childMethod->name->name) !== strtolower($parentMethod->name)) { + continue; + } + + $doc = $childMethod->getDocComment(); + if ($doc !== null) { + IssueBuffer::maybeAdd( + new InvalidDocblock( + 'Docblock for OCP implementation must be empty to inherit the interface.', + new CodeLocation($statementsSource, $childMethod) + ) + ); + } + + break; + } + } + } + } +} diff --git a/psalm.xml b/psalm.xml index 1d62b7327bc..14e3acd97ba 100644 --- a/psalm.xml +++ b/psalm.xml @@ -17,6 +17,7 @@ +