diff --git a/config/nextcloud-29/nextcloud-29-deprecations.php b/config/nextcloud-29/nextcloud-29-deprecations.php index 1983bea..6cf8c61 100644 --- a/config/nextcloud-29/nextcloud-29-deprecations.php +++ b/config/nextcloud-29/nextcloud-29-deprecations.php @@ -2,11 +2,28 @@ declare(strict_types=1); -use Nextcloud\Rector\Rector\ReplaceIConfigWithIAppConfigRector; +use Nextcloud\Rector\Rector\ReplaceInjectedMethodCallRector; use Nextcloud\Rector\Set\NextcloudSets; +use Nextcloud\Rector\ValueObject\ReplaceInjectedMethodCall; use Rector\Config\RectorConfig; return static function (RectorConfig $rectorConfig): void { $rectorConfig->sets([NextcloudSets::NEXTCLOUD_27]); - $rectorConfig->rule(ReplaceIConfigWithIAppConfigRector::class); + $rectorConfig->ruleWithConfiguration( + ReplaceInjectedMethodCallRector::class, + [ + new ReplaceInjectedMethodCall( + 'OCP\IConfig', + 'OCP\IAppConfig', + 'appConfig', + [ + 'getAppValue' => 'getValue', + 'getAppKeys' => 'getKeys', + 'setAppValue' => 'setValue', + 'deleteAppValue' => 'deleteKey', + 'deleteAppValues' => 'deleteApp', + ], + ), + ], + ); }; diff --git a/config/nextcloud-32/nextcloud-32-deprecations.php b/config/nextcloud-32/nextcloud-32-deprecations.php new file mode 100644 index 0000000..515ffa4 --- /dev/null +++ b/config/nextcloud-32/nextcloud-32-deprecations.php @@ -0,0 +1,25 @@ +sets([NextcloudSets::NEXTCLOUD_29]); + $rectorConfig->ruleWithConfiguration( + ReplaceInjectedMethodCallRector::class, + [ + new ReplaceInjectedMethodCall( + 'OCP\Mail\IMailer', + 'OCP\Mail\IEmailValidator', + 'emailValidator', + [ + 'validateMailAddress' => 'isValid', + ], + ), + ], + ); +}; diff --git a/config/nextcloud-33/nextcloud-33-deprecations.php b/config/nextcloud-33/nextcloud-33-deprecations.php index 06f4911..b52280e 100644 --- a/config/nextcloud-33/nextcloud-33-deprecations.php +++ b/config/nextcloud-33/nextcloud-33-deprecations.php @@ -4,15 +4,36 @@ use Nextcloud\Rector\Rector\AnnotationToAttributeRector; use Nextcloud\Rector\Rector\ReplaceFetchAllMethodCallRector; -use Nextcloud\Rector\Rector\ReplaceIConfigWithIUserConfigRector; +use Nextcloud\Rector\Rector\ReplaceInjectedMethodCallRector; use Nextcloud\Rector\Set\NextcloudSets; +use Nextcloud\Rector\ValueObject\ReplaceInjectedMethodCall; use Rector\Config\RectorConfig; use Rector\Php80\ValueObject\AnnotationToAttribute; return static function (RectorConfig $rectorConfig): void { - $rectorConfig->sets([NextcloudSets::NEXTCLOUD_29]); + $rectorConfig->sets([NextcloudSets::NEXTCLOUD_32]); $rectorConfig->rule(ReplaceFetchAllMethodCallRector::class); - $rectorConfig->rule(ReplaceIConfigWithIUserConfigRector::class); + $rectorConfig->ruleWithConfiguration( + ReplaceInjectedMethodCallRector::class, + [ + new ReplaceInjectedMethodCall( + 'OCP\IConfig', + 'OCP\IUserConfig', + 'userConfig', + [ + 'getAllUserValues' => 'getAllValues', + 'getUserKeys' => 'getKeys', + 'getUserValue' => 'getValueString', + 'getUserValueForUsers' => 'getValuesByUsers', + 'getUsersForUserValue' => 'searchUsersByValueString', + 'setUserValue' => 'setValueString', + 'deleteUserValue' => 'deleteUserConfig', + 'deleteAllUserValues' => 'deleteAllUserConfig', + 'deleteAppFromAllUsers' => 'deleteApp', + ], + ), + ], + ); $rectorConfig->ruleWithConfiguration( AnnotationToAttributeRector::class, [ diff --git a/src/Rector/AReplaceClassRector.php b/src/Rector/AReplaceClassRector.php deleted file mode 100644 index 4a4a373..0000000 --- a/src/Rector/AReplaceClassRector.php +++ /dev/null @@ -1,224 +0,0 @@ - - */ - abstract public function getMethodMap(): array; - - abstract public function getRuleDefinition(): RuleDefinition; - - protected function getNewMethod(?string $oldMethod): ?string - { - if ($oldMethod === null) { - return null; - } - - return $this->getMethodMap()[$oldMethod] ?? null; - } - - /** - * @return array> - */ - #[Override] - public function getNodeTypes(): array - { - return [Class_::class]; - } - - #[Override] - public function refactor(Node $node): ?Node - { - if (!($node instanceof Class_)) { - return null; - } - - $constructor = $node->getMethod(MethodName::CONSTRUCT); - if (!$constructor instanceof ClassMethod) { - return null; - } - - $iConfigPropertyNames = $this->collectOldPromotedPropertyNames($constructor); - if ($iConfigPropertyNames === []) { - return null; - } - - $callsToRewrite = $this->collectDeprecatedCalls($node, $iConfigPropertyNames); - if ($callsToRewrite === []) { - return null; - } - - $appConfigName = $this->findExistingPropertyName($constructor); - if ($appConfigName === null) { - $appConfigName = $this->makeUniquePropertyName($constructor, $this->getDesiredVarName()); - $constructor->params[] = $this->buildPromotedParam($appConfigName); - } - - foreach ($callsToRewrite as $call) { - $oldMethodName = $this->getName($call->name); - $newMethodName = $this->getNewMethod($oldMethodName); - if ($oldMethodName === null || $newMethodName === null) { - continue; - } - /** @var PropertyFetch $propertyFetch */ - $propertyFetch = $call->var; - $propertyFetch->name = new Identifier($appConfigName); - $call->name = new Identifier($newMethodName); - } - - return $node; - } - - /** - * @return list - */ - private function collectOldPromotedPropertyNames(ClassMethod $constructor): array - { - $names = []; - foreach ($constructor->getParams() as $param) { - if ($param->flags === 0) { - continue; - } - if (!$this->isObjectType($param, new ObjectType($this->getOldClassName()))) { - continue; - } - $name = $this->getName($param->var); - if (is_string($name)) { - $names[] = $name; - } - } - - return $names; - } - - /** - * @param list $propertyNames - * - * @return list - */ - private function collectDeprecatedCalls(Class_ $class, array $propertyNames): array - { - $deprecatedMethods = array_keys($this->getMethodMap()); - $calls = []; - foreach ($class->getMethods() as $classMethod) { - $stmts = $classMethod->getStmts(); - if ($stmts === null) { - continue; - } - $this->traverseNodesWithCallable( - $stmts, - function (Node $subNode) use ($propertyNames, $deprecatedMethods, &$calls): ?Node { - if (!$subNode instanceof MethodCall) { - return null; - } - if (!$this->isNames($subNode->name, $deprecatedMethods)) { - return null; - } - if (!$subNode->var instanceof PropertyFetch) { - return null; - } - $propertyFetch = $subNode->var; - if (!$propertyFetch->var instanceof Variable) { - return null; - } - if (!$this->isName($propertyFetch->var, 'this')) { - return null; - } - if ($this->isNames($propertyFetch->name, $propertyNames)) { - $calls[] = $subNode; - } - - return null; - }, - ); - } - - return $calls; - } - - private function findExistingPropertyName(ClassMethod $constructor): ?string - { - foreach ($constructor->getParams() as $param) { - if ($param->flags === 0) { - continue; - } - if (!$this->isObjectType($param, new ObjectType($this->getNewClassName()))) { - continue; - } - $name = $this->getName($param->var); - if (is_string($name)) { - return $name; - } - } - - return null; - } - - private function makeUniquePropertyName(ClassMethod $constructor, string $desired): string - { - $taken = []; - foreach ($constructor->getParams() as $param) { - $name = $this->getName($param->var); - if (is_string($name)) { - $taken[$name] = true; - } - } - if (!isset($taken[$desired])) { - return $desired; - } - $i = 2; - while (isset($taken[$desired . $i])) { - $i++; - } - - return $desired . $i; - } - - private function buildPromotedParam(string $name): Param - { - return new Param( - new Variable($name), - null, - new FullyQualified($this->getNewClassName()), - false, - false, - [], - Modifiers::PRIVATE, - ); - } -} diff --git a/src/Rector/ReplaceIConfigWithIAppConfigRector.php b/src/Rector/ReplaceIConfigWithIAppConfigRector.php deleted file mode 100644 index faa78b0..0000000 --- a/src/Rector/ReplaceIConfigWithIAppConfigRector.php +++ /dev/null @@ -1,87 +0,0 @@ - 'getValue', - 'getAppKeys' => 'getKeys', - 'setAppValue' => 'setValue', - 'deleteAppValue' => 'deleteKey', - 'deleteAppValues' => 'deleteApp', - ]; - } - - #[Override] - public function getRuleDefinition(): RuleDefinition - { - return new RuleDefinition( - 'Replace deprecated \OCP\IConfig app-config methods with their \OCP\IAppConfig counterparts,' - . ' injecting IAppConfig alongside the existing IConfig.', - [ - new CodeSample( - <<<'CODE_SAMPLE' -use OCP\IConfig; - -class SomeClass -{ - public function __construct(private IConfig $config) {} - - public function run(): string - { - return $this->config->getAppValue('myapp', 'mykey', 'default'); - } -} -CODE_SAMPLE, - <<<'CODE_SAMPLE' -use OCP\IAppConfig; -use OCP\IConfig; - -class SomeClass -{ - public function __construct(private IConfig $config, private IAppConfig $appConfig) {} - - public function run(): string - { - return $this->appConfig->getValueString('myapp', 'mykey', 'default'); - } -} -CODE_SAMPLE, - ), - ], - ); - } -} diff --git a/src/Rector/ReplaceIConfigWithIUserConfigRector.php b/src/Rector/ReplaceIConfigWithIUserConfigRector.php deleted file mode 100644 index b92cf7f..0000000 --- a/src/Rector/ReplaceIConfigWithIUserConfigRector.php +++ /dev/null @@ -1,91 +0,0 @@ - 'getAllValues', - 'getUserKeys' => 'getKeys', - 'getUserValue' => 'getValueString', - 'getUserValueForUsers' => 'getValuesByUsers', - 'getUsersForUserValue' => 'searchUsersByValueString', - 'setUserValue' => 'setValueString', - 'deleteUserValue' => 'deleteUserConfig', - 'deleteAllUserValues' => 'deleteAllUserConfig', - 'deleteAppFromAllUsers' => 'deleteApp', - ]; - } - - #[Override] - public function getRuleDefinition(): RuleDefinition - { - return new RuleDefinition( - 'Replace deprecated \OCP\IConfig user-config methods with their \OCP\IUserConfig counterparts,' - . ' injecting IUserConfig alongside the existing IConfig.', - [ - new CodeSample( - <<<'CODE_SAMPLE' -use OCP\IConfig; - -class SomeClass -{ - public function __construct(private IConfig $config) {} - - public function run(): string - { - return $this->config->getUserValue('user', 'myapp', 'mykey', 'default'); - } -} -CODE_SAMPLE, - <<<'CODE_SAMPLE' -use OCP\IConfig; -use OCP\IUserConfig; - -class SomeClass -{ - public function __construct(private IConfig $config, private IUserConfig $userConfig) {} - - public function run(): string - { - return $this->userConfig->getValueString('user', 'myapp', 'mykey', 'default'); - } -} -CODE_SAMPLE, - ), - ], - ); - } -} diff --git a/src/Rector/ReplaceInjectedMethodCallRector.php b/src/Rector/ReplaceInjectedMethodCallRector.php new file mode 100644 index 0000000..314207c --- /dev/null +++ b/src/Rector/ReplaceInjectedMethodCallRector.php @@ -0,0 +1,329 @@ +config->getAppValue('myapp', 'mykey', 'default'); + } +} +CODE_SAMPLE, + <<<'CODE_SAMPLE' +use OCP\IAppConfig; +use OCP\IConfig; + +class SomeClass +{ + public function __construct(private IConfig $config, private IAppConfig $appConfig) {} + + public function run(): string + { + return $this->appConfig->getValueString('myapp', 'mykey', 'default'); + } +} +CODE_SAMPLE + , + [ + new ReplaceInjectedMethodCall( + 'OCP\IConfig', + 'OCP\IAppConfig', + 'appConfig', + ['getAppValue' => 'getValueString'], + ), + ], + ), + ], + ); + } + + /** + * @return array> + */ + #[Override] + public function getNodeTypes(): array + { + return [ + Class_::class, Property::class, Param::class, ClassMethod::class, + Function_::class, Closure::class, ArrowFunction::class, Interface_::class, + ]; + } + + /** + * @param Class_|Property|Param|ClassMethod|Function_|Closure|ArrowFunction|Interface_ $node + * + * @psalm-suppress MoreSpecificImplementedParamType + */ + #[Override] + public function refactor(Node $node): ?Node + { + if ($this->replaceInjectedMethodCall === []) { + throw new InvalidConfigurationException(sprintf('The "%s" rule requires configuration.', self::class)); + } + + $refactoredNode = null; + foreach ($this->replaceInjectedMethodCall as $replaceInjectedMethodCall) { + $refactoredNode = $this->refactorInjectedMethodCall( + $refactoredNode ?? $node, + $replaceInjectedMethodCall->getOldClass(), + $replaceInjectedMethodCall->getNewClass(), + $replaceInjectedMethodCall->getNewVarName(), + $replaceInjectedMethodCall->getMethodMap(), + ); + } + + return $refactoredNode; + } + + /** + * @param array $methodMap + */ + protected function refactorInjectedMethodCall( + Node $node, + string $oldClass, + string $newClass, + string $newVarName, + array $methodMap, + ): ?Node { + if (!($node instanceof Class_)) { + return null; + } + + $constructor = $node->getMethod(MethodName::CONSTRUCT); + if (!$constructor instanceof ClassMethod) { + return null; + } + + $oldPropertyNames = $this->collectOldPromotedPropertyNames($constructor, $oldClass); + if ($oldPropertyNames === []) { + return null; + } + + $callsToRewrite = $this->collectDeprecatedCalls($node, $oldPropertyNames, array_keys($methodMap)); + if ($callsToRewrite === []) { + return null; + } + + $propertyName = $this->findExistingPropertyName($constructor, $newClass); + if ($propertyName === null) { + $propertyName = $this->makeUniquePropertyName($constructor, $newVarName); + $constructor->params[] = $this->buildPromotedParam($propertyName, $newClass); + } + + foreach ($callsToRewrite as $call) { + $oldMethodName = $this->getName($call->name); + if ($oldMethodName === null || !isset($methodMap[$oldMethodName])) { + continue; + } + /** @var PropertyFetch $propertyFetch */ + $propertyFetch = $call->var; + $propertyFetch->name = new Identifier($propertyName); + $call->name = new Identifier($methodMap[$oldMethodName]); + } + + return $node; + } + + /** + * @param array $configuration + * + * @psalm-suppress MoreSpecificImplementedParamType + */ + #[Override] + public function configure(array $configuration): void + { + Assert::allIsAOf($configuration, ReplaceInjectedMethodCall::class); + $this->replaceInjectedMethodCall = $configuration; + } + + /** + * @return PhpVersionFeature::PROPERTY_PROMOTION + */ + #[Override] + public function provideMinPhpVersion(): int + { + return PhpVersionFeature::PROPERTY_PROMOTION; + } + + /** + * @return list + */ + private function collectOldPromotedPropertyNames(ClassMethod $constructor, string $oldClass): array + { + $names = []; + foreach ($constructor->getParams() as $param) { + if ($param->flags === 0) { + continue; + } + if (!$this->isObjectType($param, new ObjectType($oldClass))) { + continue; + } + $name = $this->getName($param->var); + + if (is_string($name)) { + $names[] = $name; + } + } + + return $names; + } + + /** + * @param list $propertyNames + * @param list $deprecatedMethods + * + * @return list + */ + private function collectDeprecatedCalls(Class_ $class, array $propertyNames, array $deprecatedMethods): array + { + $calls = []; + foreach ($class->getMethods() as $classMethod) { + $stmts = $classMethod->getStmts(); + if ($stmts === null) { + continue; + } + $this->traverseNodesWithCallable( + $stmts, + function (Node $subNode) use ($propertyNames, $deprecatedMethods, &$calls): ?Node { + if (!$subNode instanceof MethodCall) { + return null; + } + if (!$this->isNames($subNode->name, $deprecatedMethods)) { + return null; + } + if (!$subNode->var instanceof PropertyFetch) { + return null; + } + $propertyFetch = $subNode->var; + if (!$propertyFetch->var instanceof Variable) { + return null; + } + if (!$this->isName($propertyFetch->var, 'this')) { + return null; + } + if ($this->isNames($propertyFetch->name, $propertyNames)) { + $calls[] = $subNode; + } + + return null; + }, + ); + } + + return $calls; + } + + private function findExistingPropertyName(ClassMethod $constructor, string $newClass): ?string + { + foreach ($constructor->getParams() as $param) { + if ($param->flags === 0) { + continue; + } + if (!$this->isObjectType($param, new ObjectType($newClass))) { + continue; + } + $name = $this->getName($param->var); + + if (is_string($name)) { + return $name; + } + } + + return null; + } + + private function makeUniquePropertyName(ClassMethod $constructor, string $desired): string + { + $taken = []; + foreach ($constructor->getParams() as $param) { + $name = $this->getName($param->var); + if (is_string($name)) { + $taken[$name] = true; + } + } + if (!isset($taken[$desired])) { + return $desired; + } + $i = 2; + while (isset($taken[$desired . $i])) { + $i++; + } + + return $desired . $i; + } + + private function buildPromotedParam(string $name, string $newClass): Param + { + return new Param( + new Variable($name), + null, + new FullyQualified($newClass), + false, + false, + [], + Modifiers::PRIVATE, + ); + } +} diff --git a/src/Set/NextcloudSets.php b/src/Set/NextcloudSets.php index 8fb120e..da413d2 100644 --- a/src/Set/NextcloudSets.php +++ b/src/Set/NextcloudSets.php @@ -21,7 +21,7 @@ final class NextcloudSets /** @psalm-api */ public const NEXTCLOUD_31 = self::NEXTCLOUD_30; /** @psalm-api */ - public const NEXTCLOUD_32 = self::NEXTCLOUD_31; + public const NEXTCLOUD_32 = __DIR__ . '/../../config/nextcloud-32/nextcloud-32-deprecations.php'; /** @psalm-api */ public const NEXTCLOUD_33 = __DIR__ . '/../../config/nextcloud-33/nextcloud-33-deprecations.php'; /** @psalm-api */ diff --git a/src/ValueObject/ReplaceInjectedMethodCall.php b/src/ValueObject/ReplaceInjectedMethodCall.php new file mode 100644 index 0000000..5457cc2 --- /dev/null +++ b/src/ValueObject/ReplaceInjectedMethodCall.php @@ -0,0 +1,61 @@ + $methodMap + */ + public function __construct( + private string $oldClass, + private string $newClass, + private string $newVarName, + private array $methodMap, + ) { + RectorAssert::className($oldClass); + RectorAssert::className($newClass); + RectorAssert::propertyName($newVarName); + + if ($methodMap === []) { + throw new InvalidArgumentException('"methodMap" is not a valid dictionary'); + } + foreach ($methodMap as $oldMethod => $newMethod) { + RectorAssert::propertyName($oldMethod); + RectorAssert::propertyName($newMethod); + } + } + + public function getOldClass(): string + { + return $this->oldClass; + } + + public function getNewClass(): string + { + return $this->newClass; + } + + public function getNewVarName(): string + { + return $this->newVarName; + } + + /** + * @return array + */ + public function getMethodMap(): array + { + return $this->methodMap; + } +} diff --git a/tests/Rector/ReplaceIConfigWithIAppConfigRector/config/config.php b/tests/Rector/ReplaceIConfigWithIAppConfigRector/config/config.php deleted file mode 100644 index 741eb58..0000000 --- a/tests/Rector/ReplaceIConfigWithIAppConfigRector/config/config.php +++ /dev/null @@ -1,17 +0,0 @@ -withImportNames(removeUnusedImports: false) - ->withRules([ - ReplaceIConfigWithIAppConfigRector::class, - ]); diff --git a/tests/Rector/ReplaceIConfigWithIUserConfigRector/config/config.php b/tests/Rector/ReplaceIConfigWithIUserConfigRector/config/config.php deleted file mode 100644 index 0c8acd1..0000000 --- a/tests/Rector/ReplaceIConfigWithIUserConfigRector/config/config.php +++ /dev/null @@ -1,16 +0,0 @@ -withRules([ - ReplaceIConfigWithIUserConfigRector::class, - ]); diff --git a/tests/Rector/ReplaceIConfigWithIAppConfigRector/Fixture/test_fixture.php.inc b/tests/Set/Nextcloud29/Fixture/test_fixture.php.inc similarity index 88% rename from tests/Rector/ReplaceIConfigWithIAppConfigRector/Fixture/test_fixture.php.inc rename to tests/Set/Nextcloud29/Fixture/test_fixture.php.inc index 20a175a..a5c235b 100644 --- a/tests/Rector/ReplaceIConfigWithIAppConfigRector/Fixture/test_fixture.php.inc +++ b/tests/Set/Nextcloud29/Fixture/test_fixture.php.inc @@ -5,7 +5,7 @@ * SPDX-License-Identifier: AGPL-3.0-or-later */ -namespace Nextcloud\Rector\Test\Rector\ReplaceIConfigWithIAppConfigRector\Fixture; +namespace Nextcloud\Rector\Test\Set\Nextcloud29\Fixture; use OCP\IConfig; @@ -35,7 +35,7 @@ class SomeClass * SPDX-License-Identifier: AGPL-3.0-or-later */ -namespace Nextcloud\Rector\Test\Rector\ReplaceIConfigWithIAppConfigRector\Fixture; +namespace Nextcloud\Rector\Test\Set\Nextcloud29\Fixture; use OCP\IAppConfig; use OCP\IConfig; diff --git a/tests/Rector/ReplaceIConfigWithIAppConfigRector/Fixture/test_fixture_double.php.inc b/tests/Set/Nextcloud29/Fixture/test_fixture_double.php.inc similarity index 89% rename from tests/Rector/ReplaceIConfigWithIAppConfigRector/Fixture/test_fixture_double.php.inc rename to tests/Set/Nextcloud29/Fixture/test_fixture_double.php.inc index 1fb7ffa..1f11bb0 100644 --- a/tests/Rector/ReplaceIConfigWithIAppConfigRector/Fixture/test_fixture_double.php.inc +++ b/tests/Set/Nextcloud29/Fixture/test_fixture_double.php.inc @@ -5,7 +5,7 @@ * SPDX-License-Identifier: AGPL-3.0-or-later */ -namespace Nextcloud\Rector\Test\Rector\ReplaceIConfigWithIAppConfigRector\Fixture; +namespace Nextcloud\Rector\Test\Set\Nextcloud29\Fixture; use OCP\IAppConfig; use OCP\IConfig; @@ -36,7 +36,7 @@ class SomeClass * SPDX-License-Identifier: AGPL-3.0-or-later */ -namespace Nextcloud\Rector\Test\Rector\ReplaceIConfigWithIAppConfigRector\Fixture; +namespace Nextcloud\Rector\Test\Set\Nextcloud29\Fixture; use OCP\IAppConfig; use OCP\IConfig; diff --git a/tests/Rector/ReplaceIConfigWithIAppConfigRector/Fixture/test_fixture_service.php.inc b/tests/Set/Nextcloud29/Fixture/test_fixture_service.php.inc similarity index 89% rename from tests/Rector/ReplaceIConfigWithIAppConfigRector/Fixture/test_fixture_service.php.inc rename to tests/Set/Nextcloud29/Fixture/test_fixture_service.php.inc index d8b97ea..00aa5c5 100644 --- a/tests/Rector/ReplaceIConfigWithIAppConfigRector/Fixture/test_fixture_service.php.inc +++ b/tests/Set/Nextcloud29/Fixture/test_fixture_service.php.inc @@ -5,7 +5,7 @@ * SPDX-License-Identifier: AGPL-3.0-or-later */ -namespace Nextcloud\Rector\Test\Rector\ReplaceIConfigWithIAppConfigRector\Fixture; +namespace Nextcloud\Rector\Test\Set\Nextcloud29\Fixture; use OCP\AppFramework\Services\IAppConfig; use OCP\IConfig; @@ -36,7 +36,7 @@ class SomeClass * SPDX-License-Identifier: AGPL-3.0-or-later */ -namespace Nextcloud\Rector\Test\Rector\ReplaceIConfigWithIAppConfigRector\Fixture; +namespace Nextcloud\Rector\Test\Set\Nextcloud29\Fixture; use OCP\AppFramework\Services\IAppConfig; use OCP\IConfig; diff --git a/tests/Rector/ReplaceIConfigWithIAppConfigRector/ReplaceIConfigWithIAppConfigRectorTest.php b/tests/Set/Nextcloud29/Nextcloud29SetTest.php similarity index 64% rename from tests/Rector/ReplaceIConfigWithIAppConfigRector/ReplaceIConfigWithIAppConfigRectorTest.php rename to tests/Set/Nextcloud29/Nextcloud29SetTest.php index 6569443..5e2362a 100644 --- a/tests/Rector/ReplaceIConfigWithIAppConfigRector/ReplaceIConfigWithIAppConfigRectorTest.php +++ b/tests/Set/Nextcloud29/Nextcloud29SetTest.php @@ -2,18 +2,13 @@ declare(strict_types=1); -/* - * SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors - * SPDX-License-Identifier: AGPL-3.0-or-later - */ - -namespace Nextcloud\Rector\Test\Rector\ReplaceIConfigWithIAppConfigRector; +namespace Nextcloud\Rector\Test\Set\Nextcloud29; use Iterator; use PHPUnit\Framework\Attributes\DataProvider; use Rector\Testing\PHPUnit\AbstractRectorTestCase; -final class ReplaceIConfigWithIAppConfigRectorTest extends AbstractRectorTestCase +final class Nextcloud29SetTest extends AbstractRectorTestCase { #[DataProvider('provideData')] public function test(string $filePath): void diff --git a/tests/Set/Nextcloud29/config/config.php b/tests/Set/Nextcloud29/config/config.php new file mode 100644 index 0000000..3d46898 --- /dev/null +++ b/tests/Set/Nextcloud29/config/config.php @@ -0,0 +1,12 @@ +withImportNames(removeUnusedImports: false) + ->withSets([ + NextcloudSets::NEXTCLOUD_29, + ]); diff --git a/tests/Set/Nextcloud32/Fixture/ocp_mail_mailer.php.inc b/tests/Set/Nextcloud32/Fixture/ocp_mail_mailer.php.inc new file mode 100644 index 0000000..3d82bdb --- /dev/null +++ b/tests/Set/Nextcloud32/Fixture/ocp_mail_mailer.php.inc @@ -0,0 +1,49 @@ +mailer->validateMailAddress('valid email?'); + } +} + +?> +----- +emailValidator->isValid('valid email?'); + } +} + +?> diff --git a/tests/Rector/ReplaceIConfigWithIUserConfigRector/ReplaceIConfigWithIUserConfigRectorTest.php b/tests/Set/Nextcloud32/Nextcloud32SetTest.php similarity index 64% rename from tests/Rector/ReplaceIConfigWithIUserConfigRector/ReplaceIConfigWithIUserConfigRectorTest.php rename to tests/Set/Nextcloud32/Nextcloud32SetTest.php index 514614e..e82a99c 100644 --- a/tests/Rector/ReplaceIConfigWithIUserConfigRector/ReplaceIConfigWithIUserConfigRectorTest.php +++ b/tests/Set/Nextcloud32/Nextcloud32SetTest.php @@ -2,18 +2,13 @@ declare(strict_types=1); -/* - * SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors - * SPDX-License-Identifier: AGPL-3.0-or-later - */ - -namespace Nextcloud\Rector\Test\Rector\ReplaceIConfigWithIUserConfigRector; +namespace Nextcloud\Rector\Test\Set\Nextcloud32; use Iterator; use PHPUnit\Framework\Attributes\DataProvider; use Rector\Testing\PHPUnit\AbstractRectorTestCase; -final class ReplaceIConfigWithIUserConfigRectorTest extends AbstractRectorTestCase +final class Nextcloud32SetTest extends AbstractRectorTestCase { #[DataProvider('provideData')] public function test(string $filePath): void diff --git a/tests/Set/Nextcloud32/config/config.php b/tests/Set/Nextcloud32/config/config.php new file mode 100644 index 0000000..908fdb9 --- /dev/null +++ b/tests/Set/Nextcloud32/config/config.php @@ -0,0 +1,11 @@ +withSets([ + NextcloudSets::NEXTCLOUD_32, + ]); diff --git a/tests/Rector/ReplaceIConfigWithIUserConfigRector/Fixture/test_fixture.php.inc b/tests/Set/Nextcloud33/Fixture/test_fixture.php.inc similarity index 89% rename from tests/Rector/ReplaceIConfigWithIUserConfigRector/Fixture/test_fixture.php.inc rename to tests/Set/Nextcloud33/Fixture/test_fixture.php.inc index 00f491d..bf92017 100644 --- a/tests/Rector/ReplaceIConfigWithIUserConfigRector/Fixture/test_fixture.php.inc +++ b/tests/Set/Nextcloud33/Fixture/test_fixture.php.inc @@ -5,7 +5,7 @@ * SPDX-License-Identifier: AGPL-3.0-or-later */ -namespace Nextcloud\Rector\Test\Rector\ReplaceIConfigWithIUserConfigRector\Fixture; +namespace Nextcloud\Rector\Test\Set\Nextcloud33\Fixture; use OCP\IConfig; @@ -35,7 +35,7 @@ class SomeClass * SPDX-License-Identifier: AGPL-3.0-or-later */ -namespace Nextcloud\Rector\Test\Rector\ReplaceIConfigWithIUserConfigRector\Fixture; +namespace Nextcloud\Rector\Test\Set\Nextcloud33\Fixture; use OCP\IConfig; diff --git a/tests/Rector/ReplaceIConfigWithIUserConfigRector/Fixture/test_fixture_double.php.inc b/tests/Set/Nextcloud33/Fixture/test_fixture_double.php.inc similarity index 89% rename from tests/Rector/ReplaceIConfigWithIUserConfigRector/Fixture/test_fixture_double.php.inc rename to tests/Set/Nextcloud33/Fixture/test_fixture_double.php.inc index 1c04146..7a600df 100644 --- a/tests/Rector/ReplaceIConfigWithIUserConfigRector/Fixture/test_fixture_double.php.inc +++ b/tests/Set/Nextcloud33/Fixture/test_fixture_double.php.inc @@ -5,7 +5,7 @@ * SPDX-License-Identifier: AGPL-3.0-or-later */ -namespace Nextcloud\Rector\Test\Rector\ReplaceIConfigWithIUserConfigRector\Fixture; +namespace Nextcloud\Rector\Test\Set\Nextcloud33\Fixture; use OCP\IConfig; use OCP\IUserConfig; @@ -36,7 +36,7 @@ class SomeClass * SPDX-License-Identifier: AGPL-3.0-or-later */ -namespace Nextcloud\Rector\Test\Rector\ReplaceIConfigWithIUserConfigRector\Fixture; +namespace Nextcloud\Rector\Test\Set\Nextcloud33\Fixture; use OCP\IConfig; use OCP\IUserConfig; diff --git a/tests/Set/Nextcloud33/Nextcloud33SetTest.php b/tests/Set/Nextcloud33/Nextcloud33SetTest.php new file mode 100644 index 0000000..8527f66 --- /dev/null +++ b/tests/Set/Nextcloud33/Nextcloud33SetTest.php @@ -0,0 +1,28 @@ +doTestFile($filePath); + } + + public static function provideData(): Iterator + { + return self::yieldFilesFromDirectory(__DIR__ . '/Fixture'); + } + + public function provideConfigFilePath(): string + { + return __DIR__ . '/config/config.php'; + } +} diff --git a/tests/Set/Nextcloud33/config/config.php b/tests/Set/Nextcloud33/config/config.php new file mode 100644 index 0000000..72f3278 --- /dev/null +++ b/tests/Set/Nextcloud33/config/config.php @@ -0,0 +1,11 @@ +withSets([ + NextcloudSets::NEXTCLOUD_33, + ]);