Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add rector ruleset for Sulu 3.0 #18

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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": {
Expand Down Expand Up @@ -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
}
}
}
11 changes: 11 additions & 0 deletions config/sets/sulu/level/up-to-sulu-30.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

declare(strict_types=1);

use Rector\Config\RectorConfig;
use Sulu\Rector\Set\SuluLevelSetList;
use Sulu\Rector\Set\SuluSetList;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->sets([SuluSetList::SULU_30, SuluLevelSetList::UP_TO_SULU_25]);
};
39 changes: 39 additions & 0 deletions config/sets/sulu/sulu-30.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

declare(strict_types=1);

use Rector\Config\RectorConfig;
use Rector\Renaming\Rector\MethodCall\RenameMethodRector;
use Rector\Renaming\ValueObject\MethodCallRename;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->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',
),
// @see https://github.com/sulu/sulu/pull/7053
new MethodCallRename(
'Sulu\Component\Security\Event\PermissionUpdateEvent',
'getSecurityIdentity',
'getPermissions',
),
],
);
};
5 changes: 5 additions & 0 deletions src/Set/SuluLevelSetList.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
5 changes: 5 additions & 0 deletions src/Set/SuluSetList.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
2 changes: 1 addition & 1 deletion tests/Set/Sulu25/Sulu25Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace Sulu\Rector\Tests\Set\Sulu30\Fixture;

class PermissionUpdateEventGetSecurityIdentityToGetPermissions {
public function getDefaultLocalization(\Sulu\Component\Security\Event\PermissionUpdateEvent $event): string
{
return $event->getSecurityIdentity();
}
}

?>
-----
<?php

namespace Sulu\Rector\Tests\Set\Sulu30\Fixture;

class PermissionUpdateEventGetSecurityIdentityToGetPermissions {
public function getDefaultLocalization(\Sulu\Component\Security\Event\PermissionUpdateEvent $event): string
{
return $event->getPermissions();
}
}

?>
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

namespace Sulu\Rector\Tests\Set\Sulu30\Fixture;

class PortalLocalizationXDefaultToDefault {
public function getDefaultLocalization(\Sulu\Component\Webspace\Portal $portal): string
{
return $portal->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();
}
}

?>
-----
<?php

namespace Sulu\Rector\Tests\Set\Sulu30\Fixture;

class PortalLocalizationXDefaultToDefault {
public function getDefaultLocalization(\Sulu\Component\Webspace\Portal $portal): string
{
return $portal->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();
}
}

?>
32 changes: 32 additions & 0 deletions tests/Set/Sulu30/Sulu30Test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

declare(strict_types=1);

namespace Sulu\Rector\Tests\Set\Sulu30;

use Rector\Testing\PHPUnit\AbstractRectorTestCase;
use Symplify\SmartFileSystem\SmartFileInfo;

final class Sulu30Test extends AbstractRectorTestCase
{
/**
* @dataProvider provideData()
*/
public function test(string $fileInfo): void
{
$this->doTestFile($fileInfo);
}

/**
* @return \Iterator<SmartFileInfo>
*/
public function provideData(): \Iterator
{
return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture');
}

public function provideConfigFilePath(): string
{
return __DIR__ . '/config/sulu-30.php';
}
}
11 changes: 11 additions & 0 deletions tests/Set/Sulu30/config/sulu-30.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

declare(strict_types=1);

use Rector\Config\RectorConfig;
use Sulu\Rector\Set\SuluSetList;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->import(__DIR__ . '/../../../../config/config.php');
$rectorConfig->sets([SuluSetList::SULU_30]);
};