12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- <?php
- declare(strict_types=1);
- use PhpParser\Node;
- use Rector\CodingStyle\Contract\ClassNameImport\ClassNameImportSkipVoterInterface;
- use Rector\Config\RectorConfig;
- use Rector\Php80\Rector\Class_\ClassPropertyAssignToConstructorPromotionRector;
- 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)) {
-
- return true;
- }
- foreach ($this->namespacePrefixes as $prefix) {
- if (str_starts_with($fullyQualifiedObjectType->getClassName(), $prefix . '\\')) {
-
- return false;
- }
- }
-
- return true;
- }
- }
- $config = RectorConfig::configure()
- ->withPaths([
- $nextcloudDir . '/apps',
-
-
-
-
-
-
-
- ])
- ->withSkip([
- $nextcloudDir . '/apps/*/3rdparty/*',
- $nextcloudDir . '/apps/*/build/stubs/*',
- $nextcloudDir . '/apps/*/composer/*',
- $nextcloudDir . '/apps/*/config/*',
- ])
-
-
- ->withImportNames(importShortClasses:false)
- ->withTypeCoverageLevel(0)
- ->withConfiguredRule(ClassPropertyAssignToConstructorPromotionRector::class, [
- 'inline_public' => true,
- 'rename_property' => true,
- ]);
- $config->registerService(NextcloudNamespaceSkipVoter::class, tag:ClassNameImportSkipVoterInterface::class);
- $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, '!! '));
- $ignoredEntries = array_map(static fn (string $line) => substr($line, 3), $ignoredEntries);
- $ignoredEntries = array_values($ignoredEntries);
- foreach ($ignoredEntries as $ignoredEntry) {
- if (str_ends_with($ignoredEntry, '/')) {
- $config->withSkip([$ignoredEntry . '*']);
- } else {
- $config->withSkip([$ignoredEntry . '/*']);
- }
- }
- return $config;
|