77 * SPDX-License-Identifier: AGPL-3.0-only
88 */
99
10- use Nextcloud \Rector \Set \NextcloudSets ;
11- use PhpParser \Node ;
12- use Rector \CodingStyle \Contract \ClassNameImport \ClassNameImportSkipVoterInterface ;
13- use Rector \Config \RectorConfig ;
14- use Rector \Php80 \Rector \Class_ \ClassPropertyAssignToConstructorPromotionRector ;
15- use Rector \PHPUnit \Set \PHPUnitSetList ;
16- use Rector \StaticTypeMapper \ValueObject \Type \FullyQualifiedObjectType ;
17- use Rector \ValueObject \Application \File ;
18-
1910$ nextcloudDir = dirname (__DIR__ );
2011
21- class NextcloudNamespaceSkipVoter implements ClassNameImportSkipVoterInterface {
22- private array $ namespacePrefixes = [
23- 'OC ' ,
24- 'OCA ' ,
25- 'OCP ' ,
26- ];
27- private array $ skippedClassNames = [
28- 'Backend ' ,
29- 'Connection ' ,
30- 'Exception ' ,
31- 'IManager ' ,
32- 'IProvider ' ,
33- 'Manager ' ,
34- 'Plugin ' ,
35- 'Provider ' ,
36- ];
37- public function shouldSkip (File $ file , FullyQualifiedObjectType $ fullyQualifiedObjectType , Node $ node ) : bool {
38- if (in_array ($ fullyQualifiedObjectType ->getShortName (), $ this ->skippedClassNames )) {
39- // Skip common class names to avoid confusion
40- return true ;
41- }
42- foreach ($ this ->namespacePrefixes as $ prefix ) {
43- if (str_starts_with ($ fullyQualifiedObjectType ->getClassName (), $ prefix . '\\' )) {
44- // Import Nextcloud namespaces
45- return false ;
46- }
47- }
48- // Skip everything else
49- return true ;
50- }
51- }
52-
53- $ config = RectorConfig::configure ()
12+ return (require 'rector-shared.php ' )
5413 ->withPaths ([
5514 $ nextcloudDir . '/apps ' ,
5615 $ nextcloudDir . '/core ' ,
@@ -71,43 +30,4 @@ public function shouldSkip(File $file, FullyQualifiedObjectType $fullyQualifiedO
7130 // $nextcloudDir . '/lib',
7231 // $nextcloudDir . '/themes',
7332 ])
74- ->withSkip ([
75- $ nextcloudDir . '/apps/*/3rdparty/* ' ,
76- $ nextcloudDir . '/apps/*/build/stubs/* ' ,
77- $ nextcloudDir . '/apps/*/composer/* ' ,
78- $ nextcloudDir . '/apps/*/config/* ' ,
79- // The mock classes are excluded, as the tests explicitly test the annotations which should not be migrated to attributes
80- $ nextcloudDir . '/tests/lib/AppFramework/Middleware/Mock/* ' ,
81- $ nextcloudDir . '/tests/lib/AppFramework/Middleware/Security/Mock/* ' ,
82- ])
83- // uncomment to reach your current PHP version
84- // ->withPhpSets()
85- ->withImportNames (importShortClasses:false )
86- ->withTypeCoverageLevel (0 )
87- ->withConfiguredRule (ClassPropertyAssignToConstructorPromotionRector::class, [
88- 'inline_public ' => true ,
89- 'rename_property ' => true ,
90- ])
91- ->withSets ([
92- NextcloudSets::NEXTCLOUD_27 ,
93- PHPUnitSetList::PHPUNIT_100 ,
94- ]);
95-
96- $ config ->registerService (NextcloudNamespaceSkipVoter::class, tag:ClassNameImportSkipVoterInterface::class);
97-
98- /* Ignore all files ignored by git */
99- $ ignoredEntries = shell_exec ('git status --porcelain --ignored ' . escapeshellarg ($ nextcloudDir ));
100- $ ignoredEntries = explode ("\n" , $ ignoredEntries );
101- $ ignoredEntries = array_filter ($ ignoredEntries , static fn (string $ line ) => str_starts_with ($ line , '!! ' ));
102- $ ignoredEntries = array_map (static fn (string $ line ) => substr ($ line , 3 ), $ ignoredEntries );
103- $ ignoredEntries = array_values ($ ignoredEntries );
104-
105- foreach ($ ignoredEntries as $ ignoredEntry ) {
106- if (str_ends_with ($ ignoredEntry , '/ ' )) {
107- $ config ->withSkip ([$ ignoredEntry . '* ' ]);
108- } else {
109- $ config ->withSkip ([$ ignoredEntry . '/* ' ]);
110- }
111- }
112-
113- return $ config ;
33+ ->withTypeCoverageLevel (0 );
0 commit comments