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 @@ +