From af3acb8391f8c5adffa99a98c6386f444f39b084 Mon Sep 17 00:00:00 2001 From: Alexander Schranz Date: Sat, 29 Apr 2023 15:38:15 +0200 Subject: [PATCH 1/3] Add rector ruleset for Sulu 3.0 --- composer.json | 3 +- config/sets/sulu/level/up-to-sulu-30.php | 11 +++++ config/sets/sulu/sulu-30.php | 43 ++++++++++++++++++ src/Set/SuluLevelSetList.php | 5 +++ src/Set/SuluSetList.php | 5 +++ tests/Set/Sulu25/Sulu25Test.php | 2 +- ...l_localization_xdefault_to_default.php.inc | 45 +++++++++++++++++++ tests/Set/Sulu30/Sulu30Test.php | 32 +++++++++++++ tests/Set/Sulu30/config/sulu-30.php | 11 +++++ 9 files changed, 155 insertions(+), 2 deletions(-) create mode 100644 config/sets/sulu/level/up-to-sulu-30.php create mode 100644 config/sets/sulu/sulu-30.php create mode 100644 tests/Set/Sulu30/Fixture/portal_localization_xdefault_to_default.php.inc create mode 100644 tests/Set/Sulu30/Sulu30Test.php create mode 100644 tests/Set/Sulu30/config/sulu-30.php diff --git a/composer.json b/composer.json index cd2d000..28fd27c 100644 --- a/composer.json +++ b/composer.json @@ -61,7 +61,8 @@ "allow-plugins": { "rector/extension-installer": true, "cweagans/composer-patches": true, - "phpstan/extension-installer": true + "phpstan/extension-installer": true, + "php-http/discovery": true } } } diff --git a/config/sets/sulu/level/up-to-sulu-30.php b/config/sets/sulu/level/up-to-sulu-30.php new file mode 100644 index 0000000..ade26f5 --- /dev/null +++ b/config/sets/sulu/level/up-to-sulu-30.php @@ -0,0 +1,11 @@ +sets([SuluSetList::SULU_30, SuluLevelSetList::UP_TO_SULU_25]); +}; diff --git a/config/sets/sulu/sulu-30.php b/config/sets/sulu/sulu-30.php new file mode 100644 index 0000000..0e63024 --- /dev/null +++ b/config/sets/sulu/sulu-30.php @@ -0,0 +1,43 @@ +ruleWithConfiguration( + RenameMethodRector::class, + [ + // @see https://github.com/sulu/sulu/pull/7053 + new MethodCallRename( + 'Sulu\Component\Webspace\Portal', + 'getXDefaultLocalization', + 'getDefaultLocalization', + ), + // @see https://github.com/sulu/sulu/pull/7053 + new MethodCallRename( + 'Sulu\Component\Webspace\Portal', + 'setXDefaultLocalization', + 'setDefaultLocalization', + ), + // @see https://github.com/sulu/sulu/pull/7053 + new MethodCallRename( + 'Sulu\Component\Localization\Localization', + 'isXDefault', + 'isDefault', + ), + ], + ); +}; diff --git a/src/Set/SuluLevelSetList.php b/src/Set/SuluLevelSetList.php index 4c5f1e5..b2af6cd 100644 --- a/src/Set/SuluLevelSetList.php +++ b/src/Set/SuluLevelSetList.php @@ -17,4 +17,9 @@ final class SuluLevelSetList implements SetListInterface * @var string */ final public const UP_TO_SULU_25 = __DIR__ . '/../../config/sets/sulu/level/up-to-sulu-25.php'; + + /** + * @var string + */ + final public const UP_TO_SULU_30 = __DIR__ . '/../../config/sets/sulu/level/up-to-sulu-30.php'; } diff --git a/src/Set/SuluSetList.php b/src/Set/SuluSetList.php index 5e87b17..3cfe2ff 100644 --- a/src/Set/SuluSetList.php +++ b/src/Set/SuluSetList.php @@ -17,4 +17,9 @@ final class SuluSetList implements SetListInterface * @var string */ final public const SULU_25 = __DIR__ . '/../../config/sets/sulu/sulu-25.php'; + + /** + * @var string + */ + final public const SULU_30 = __DIR__ . '/../../config/sets/sulu/sulu-30.php'; } diff --git a/tests/Set/Sulu25/Sulu25Test.php b/tests/Set/Sulu25/Sulu25Test.php index 2d00d38..5905aac 100644 --- a/tests/Set/Sulu25/Sulu25Test.php +++ b/tests/Set/Sulu25/Sulu25Test.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Sulu\Rector\Tests\Set\Sulu24; +namespace Sulu\Rector\Tests\Set\Sulu25; use Rector\Testing\PHPUnit\AbstractRectorTestCase; use Symplify\SmartFileSystem\SmartFileInfo; diff --git a/tests/Set/Sulu30/Fixture/portal_localization_xdefault_to_default.php.inc b/tests/Set/Sulu30/Fixture/portal_localization_xdefault_to_default.php.inc new file mode 100644 index 0000000..77f943c --- /dev/null +++ b/tests/Set/Sulu30/Fixture/portal_localization_xdefault_to_default.php.inc @@ -0,0 +1,45 @@ +getXDefaultLocalization(); + } + + public function setDefaultLocalization(\Sulu\Component\Webspace\Portal $portal, \Sulu\Component\Localization\Localization $localization): void + { + $portal->setXDefaultLocalization($localization); + } + + public function isDefault(\Sulu\Component\Localization\Localization $localization): string + { + return $localization->isXDefault(); + } +} + +?> +----- +getDefaultLocalization(); + } + + public function setDefaultLocalization(\Sulu\Component\Webspace\Portal $portal, \Sulu\Component\Localization\Localization $localization): void + { + $portal->setDefaultLocalization($localization); + } + + public function isDefault(\Sulu\Component\Localization\Localization $localization): string + { + return $localization->isDefault(); + } +} + +?> diff --git a/tests/Set/Sulu30/Sulu30Test.php b/tests/Set/Sulu30/Sulu30Test.php new file mode 100644 index 0000000..b4df9e1 --- /dev/null +++ b/tests/Set/Sulu30/Sulu30Test.php @@ -0,0 +1,32 @@ +doTestFile($fileInfo); + } + + /** + * @return \Iterator + */ + public function provideData(): \Iterator + { + return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture'); + } + + public function provideConfigFilePath(): string + { + return __DIR__ . '/config/sulu-30.php'; + } +} diff --git a/tests/Set/Sulu30/config/sulu-30.php b/tests/Set/Sulu30/config/sulu-30.php new file mode 100644 index 0000000..bad8634 --- /dev/null +++ b/tests/Set/Sulu30/config/sulu-30.php @@ -0,0 +1,11 @@ +import(__DIR__ . '/../../../../config/config.php'); + $rectorConfig->sets([SuluSetList::SULU_30]); +}; From a4eda0c918f19244fc8e420ae6413188b2953c6a Mon Sep 17 00:00:00 2001 From: Alexander Schranz Date: Sat, 29 Apr 2023 15:46:34 +0200 Subject: [PATCH 2/3] Fix code style and update composer requirements --- composer.json | 4 ++-- config/sets/sulu/sulu-30.php | 10 ---------- 2 files changed, 2 insertions(+), 12 deletions(-) diff --git a/composer.json b/composer.json index 28fd27c..e376db0 100644 --- a/composer.json +++ b/composer.json @@ -9,7 +9,7 @@ ], "require": { "php": "^8.1", - "rector/rector": "^0.14.1 || ^0.15" + "rector/rector": "^0.15" }, "require-dev": { "friendsofphp/php-cs-fixer": "^3.6", @@ -20,7 +20,7 @@ "phpstan/phpstan-strict-rules": "^1.2", "phpstan/phpstan-webmozart-assert": "^1.1", "phpunit/phpunit": "^9.5.20", - "sulu/sulu": "^2.5@dev", + "sulu/sulu": "^2.5@dev || ^3.0@dev", "thecodingmachine/phpstan-strict-rules": "^1.0" }, "autoload": { diff --git a/config/sets/sulu/sulu-30.php b/config/sets/sulu/sulu-30.php index 0e63024..04fb7b5 100644 --- a/config/sets/sulu/sulu-30.php +++ b/config/sets/sulu/sulu-30.php @@ -2,19 +2,9 @@ declare(strict_types=1); -use PHPStan\Type\ArrayType; -use PHPStan\Type\BooleanType; -use PHPStan\Type\FloatType; -use PHPStan\Type\IntegerType; -use PHPStan\Type\IterableType; -use PHPStan\Type\MixedType; -use PHPStan\Type\ObjectType; -use PHPStan\Type\StringType; use Rector\Config\RectorConfig; use Rector\Renaming\Rector\MethodCall\RenameMethodRector; use Rector\Renaming\ValueObject\MethodCallRename; -use Rector\TypeDeclaration\Rector\ClassMethod\AddReturnTypeDeclarationRector; -use Rector\TypeDeclaration\ValueObject\AddReturnTypeDeclaration; return static function (RectorConfig $rectorConfig): void { $rectorConfig->ruleWithConfiguration( From 8bc242d66030068e674ca4006e182cb98337fe94 Mon Sep 17 00:00:00 2001 From: Alexander Schranz Date: Sat, 29 Apr 2023 15:49:46 +0200 Subject: [PATCH 3/3] Add ruleset for get security identity --- config/sets/sulu/sulu-30.php | 6 +++++ ...curity_identity_to_get_permissions.php.inc | 25 +++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 tests/Set/Sulu30/Fixture/permission_update_event_get_security_identity_to_get_permissions.php.inc diff --git a/config/sets/sulu/sulu-30.php b/config/sets/sulu/sulu-30.php index 04fb7b5..877d8af 100644 --- a/config/sets/sulu/sulu-30.php +++ b/config/sets/sulu/sulu-30.php @@ -28,6 +28,12 @@ 'isXDefault', 'isDefault', ), + // @see https://github.com/sulu/sulu/pull/7053 + new MethodCallRename( + 'Sulu\Component\Security\Event\PermissionUpdateEvent', + 'getSecurityIdentity', + 'getPermissions', + ), ], ); }; diff --git a/tests/Set/Sulu30/Fixture/permission_update_event_get_security_identity_to_get_permissions.php.inc b/tests/Set/Sulu30/Fixture/permission_update_event_get_security_identity_to_get_permissions.php.inc new file mode 100644 index 0000000..b03e991 --- /dev/null +++ b/tests/Set/Sulu30/Fixture/permission_update_event_get_security_identity_to_get_permissions.php.inc @@ -0,0 +1,25 @@ +getSecurityIdentity(); + } +} + +?> +----- +getPermissions(); + } +} + +?>