diff options
Diffstat (limited to 'build/rector.php')
-rw-r--r-- | build/rector.php | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/build/rector.php b/build/rector.php index ed8b748663e..db39fb4ce48 100644 --- a/build/rector.php +++ b/build/rector.php @@ -7,10 +7,46 @@ declare(strict_types=1); * SPDX-License-Identifier: AGPL-3.0-only */ +use PhpParser\Node; +use Rector\CodingStyle\Contract\ClassNameImport\ClassNameImportSkipVoterInterface; use Rector\Config\RectorConfig; +use Rector\StaticTypeMapper\ValueObject\Type\FullyQualifiedObjectType; +use Rector\ValueObject\Application\File; $nextcloudDir = dirname(__DIR__); +class NextcloudNamespaceSkipVoter implements ClassNameImportSkipVoterInterface { + private array $namespacePrefixes = [ + 'OC', + 'OCA', + 'OCP', + ]; + private array $skippedClassNames = [ + 'Backend', + 'Connection', + 'Exception', + 'IManager', + 'IProvider', + 'Manager', + 'Plugin', + 'Provider', + ]; + public function shouldSkip(File $file, FullyQualifiedObjectType $fullyQualifiedObjectType, Node $node) : bool { + if (in_array($fullyQualifiedObjectType->getShortName(), $this->skippedClassNames)) { + // Skip common class names to avoid confusion + return true; + } + foreach ($this->namespacePrefixes as $prefix) { + if (str_starts_with($fullyQualifiedObjectType->getClassName(), $prefix . '\\')) { + // Import Nextcloud namespaces + return false; + } + } + // Skip everything else + return true; + } +} + $config = RectorConfig::configure() ->withPaths([ $nextcloudDir . '/apps', @@ -30,9 +66,12 @@ $config = RectorConfig::configure() ]) // uncomment to reach your current PHP version // ->withPhpSets() + ->withImportNames(importShortClasses:false) ->withTypeCoverageLevel(0); +$config->registerService(NextcloudNamespaceSkipVoter::class, tag:ClassNameImportSkipVoterInterface::class); +/* Ignore all files ignored by git */ $ignoredEntries = shell_exec('git status --porcelain --ignored ' . escapeshellarg($nextcloudDir)); $ignoredEntries = explode("\n", $ignoredEntries); $ignoredEntries = array_filter($ignoredEntries, static fn (string $line) => str_starts_with($line, '!! ')); |