Skip to content

Commit

Permalink
Add rector ruleset for Sulu 3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-schranz committed Apr 29, 2023
1 parent 3edd808 commit af3acb8
Show file tree
Hide file tree
Showing 9 changed files with 155 additions and 2 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
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]);
};
43 changes: 43 additions & 0 deletions config/sets/sulu/sulu-30.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

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(
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',
),
],
);
};
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,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]);
};

0 comments on commit af3acb8

Please sign in to comment.