diff options
author | provokateurin <kate@provokateurin.de> | 2024-09-06 09:39:33 +0200 |
---|---|---|
committer | provokateurin <kate@provokateurin.de> | 2024-09-09 11:09:27 +0200 |
commit | fc10fa592626d154a91d77d35c93beabdc7605c1 (patch) | |
tree | 9aae432465238dba639b1c79fca1a06b91f3bceb | |
parent | 3f2082ef2e98b3080a749098a74f09b636419afd (diff) | |
download | nextcloud-server-fc10fa592626d154a91d77d35c93beabdc7605c1.tar.gz nextcloud-server-fc10fa592626d154a91d77d35c93beabdc7605c1.zip |
build: Add script to remove doc blocks for OCP implementations
Signed-off-by: provokateurin <kate@provokateurin.de>
-rwxr-xr-x | build/fix-inheritdoc.php | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/build/fix-inheritdoc.php b/build/fix-inheritdoc.php new file mode 100755 index 00000000000..c20e5d00f96 --- /dev/null +++ b/build/fix-inheritdoc.php @@ -0,0 +1,93 @@ +#!/usr/bin/env php +<?php + +declare(strict_types=1); + +/** + * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-only + */ + +include __DIR__ . '/../lib/composer/autoload.php'; +include __DIR__ . '/../build/integration/vendor/autoload.php'; +include __DIR__ . '/../3rdparty/autoload.php'; + +use PhpParser\Node\Name\FullyQualified; +use PhpParser\Node\Stmt\Class_; +use PhpParser\Node\Stmt\Namespace_; +use PhpParser\NodeTraverser; +use PhpParser\NodeVisitor\CloningVisitor; +use PhpParser\NodeVisitor\NameResolver; +use PhpParser\ParserFactory; +use PhpParser\PrettyPrinter; + +$parser = (new ParserFactory())->createForHostVersion(); + +$nodeTraverser = new NodeTraverser(); +$nodeTraverser->addVisitor(new CloningVisitor()); +$nodeTraverser->addVisitor(new NameResolver()); + +$prettyPrinter = new PrettyPrinter\Standard(); + +$iterators = [ + new RecursiveIteratorIterator(new RecursiveDirectoryIterator('lib/private')), + new RecursiveIteratorIterator(new RecursiveDirectoryIterator('core')), +]; +foreach ($iterators as $iterator) { + /** @var SplFileInfo $info */ + foreach ($iterator as $info) { + if ($info->getType() !== 'file' || $info->getExtension() !== 'php') { + continue; + } + + $code = file_get_contents($info->getRealPath()); + $oldStmts = $parser->parse($code); + $oldTokens = $parser->getTokens(); + $newStmts = $nodeTraverser->traverse($oldStmts); + + $changed = false; + foreach ($newStmts as $stmt) { + if (!$stmt instanceof Namespace_) { + continue; + } + + foreach ($stmt->stmts as $childClass) { + if (!$childClass instanceof Class_) { + continue; + } + + $childClassName = $childClass->namespacedName->toString(); + if (!str_starts_with($childClassName, 'OC\\')) { + continue; + } + + /** @var FullyQualified $impl */ + foreach ($childClass->implements as $impl) { + $parentClassName = $impl->toString(); + 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; + } + + $childMethod->setAttribute('comments', []); + $changed = true; + break; + } + } + } + } + } + + if ($changed) { + file_put_contents($info->getRealPath(), $prettyPrinter->printFormatPreserving($newStmts, $oldStmts, $oldTokens)); + } + } +} |