Skip to content

Commit

Permalink
Add current upgrade rules for Sulu 2.5 (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-schranz authored May 13, 2022
1 parent bb397f2 commit 8226ae5
Show file tree
Hide file tree
Showing 17 changed files with 578 additions and 9 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use Rector\Config\RectorConfig;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->sets([
SuluLevelSetList::UP_TO_SULU_24,
SuluLevelSetList::UP_TO_SULU_25,
]);
};
```
File renamed without changes.
File renamed without changes.
27 changes: 25 additions & 2 deletions config/sets/sulu/sulu-24.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,34 @@

declare(strict_types=1);

use Rector\Arguments\Rector\ClassMethod\ReplaceArgumentDefaultValueRector;
use Rector\Arguments\ValueObject\ReplaceArgumentDefaultValue;
use Rector\Config\RectorConfig;
use Rector\Renaming\Rector\MethodCall\RenameMethodRector;
use Rector\Renaming\ValueObject\MethodCallRename;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->ruleWithConfiguration(
ReplaceArgumentDefaultValueRector::class,
[
// @see https://github.com/sulu/sulu/pull/2214
new ReplaceArgumentDefaultValue(
'Sulu\Component\Localization\Localization',
'getLocalization',
0,
'_',
'Sulu\Component\Localization\Localization::UNDERSCORE',
),
new ReplaceArgumentDefaultValue(
'Sulu\Component\Localization\Localization',
'getLocalization',
0,
'-',
'Sulu\Component\Localization\Localization::DASH',
),
],
);

$rectorConfig
->ruleWithConfiguration(RenameMethodRector::class, [
// @see https://github.com/sulu/sulu/pull/6071
Expand All @@ -17,8 +40,8 @@
),
new MethodCallRename(
'Sulu\Component\Localization\Localization',
'getXDefault',
'getDefault',
'getLocalization',
'getLocale',
),
new MethodCallRename(
'Sulu\Component\Localization\Localization',
Expand Down
148 changes: 147 additions & 1 deletion config/sets/sulu/sulu-25.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,154 @@

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\TypeDeclaration\Rector\ClassMethod\AddReturnTypeDeclarationRector;
use Rector\TypeDeclaration\ValueObject\AddReturnTypeDeclaration;

return static function (RectorConfig $rectorConfig): void {
// TODO configure upgrades
$rectorConfig->ruleWithConfiguration(
AddReturnTypeDeclarationRector::class,
[
// @see https://github.com/sulu/sulu/pull/6582
new AddReturnTypeDeclaration(
'Sulu\Bundle\SecurityBundle\Entity\User',
'getRoles',
new ArrayType(new IntegerType(), new StringType()),
),
new AddReturnTypeDeclaration(
'Sulu\Bundle\SecurityBundle\Entity\User',
'isEqualTo',
new BooleanType(),
),
// @see https://github.com/sulu/sulu/pull/6601
new AddReturnTypeDeclaration(
'Sulu\Bundle\HttpCacheBundle\Cache\SuluHttpCache',
'fetch',
new ObjectType('Symfony\Component\HttpFoundation\Response'),
),
new AddReturnTypeDeclaration(
'Sulu\Bundle\HttpCacheBundle\Cache\SuluHttpCache',
'createStore',
new ObjectType('Symfony\Component\HttpKernel\HttpCache\StoreInterface'),
),
// @see https://github.com/sulu/sulu/pull/6583
new AddReturnTypeDeclaration(
'Sulu\Bundle\SecurityBundle\Security\AuthenticationHandler',
'onAuthenticationSuccess',
new ObjectType('Symfony\Component\HttpFoundation\Response'),
),
new AddReturnTypeDeclaration(
'Sulu\Bundle\SecurityBundle\Security\AuthenticationHandler',
'onAuthenticationFailure',
new ObjectType('Symfony\Component\HttpFoundation\Response'),
),
// @see https://github.com/sulu/sulu/pull/6580
new AddReturnTypeDeclaration(
'Sulu\Bundle\WebsiteBundle\Controller\WebsiteController',
'getSubscribedServices',
new ArrayType(new StringType(), new StringType()),
),
// @see https://github.com/sulu/sulu/pull/6562
new AddReturnTypeDeclaration(
'Sulu\Component\HttpKernel\SuluKernel',
'registerBundles',
new IterableType(new StringType(), new StringType()),
),
new AddReturnTypeDeclaration(
'Sulu\Component\HttpKernel\SuluKernel',
'getContainerClass',
new StringType(),
),
new AddReturnTypeDeclaration(
'Sulu\Component\HttpKernel\SuluKernel',
'getCacheDir',
new StringType(),
),
new AddReturnTypeDeclaration(
'Sulu\Component\HttpKernel\SuluKernel',
'getCommonCacheDir',
new StringType(),
),
new AddReturnTypeDeclaration(
'Sulu\Component\HttpKernel\SuluKernel',
'getLogDir',
new StringType(),
),
new AddReturnTypeDeclaration(
'Sulu\Component\HttpKernel\SuluKernel',
'getKernelParameters',
new ArrayType(new StringType(), new StringType()),
),
new AddReturnTypeDeclaration(
'Sulu\Component\HttpKernel\SuluKernel',
'getEnvironment',
new StringType(),
),
new AddReturnTypeDeclaration(
'Sulu\Component\HttpKernel\SuluKernel',
'isDebug',
new BooleanType(),
),
new AddReturnTypeDeclaration(
'Sulu\Component\HttpKernel\SuluKernel',
'getCharset',
new StringType(),
),
new AddReturnTypeDeclaration(
'Sulu\Component\HttpKernel\SuluKernel',
'getStartTime',
new FloatType(),
),
new AddReturnTypeDeclaration(
'Sulu\Component\HttpKernel\SuluKernel',
'getContainer',
new ObjectType('Symfony\Component\DependencyInjection\ContainerInterface'),
),
new AddReturnTypeDeclaration(
'Sulu\Component\HttpKernel\SuluKernel',
'getBundle',
new ObjectType('Symfony\Component\HttpKernel\Bundle\BundleInterface'),
),
new AddReturnTypeDeclaration(
'Sulu\Component\HttpKernel\SuluKernel',
'getBundles',
new ArrayType(new IntegerType(), new ObjectType('Symfony\Component\HttpKernel\Bundle\BundleInterface')),
),
new AddReturnTypeDeclaration(
'Sulu\Component\HttpKernel\SuluKernel',
'locateResource',
new StringType(),
),
// @see https://github.com/sulu/sulu/pull/6581
new AddReturnTypeDeclaration(
'Symfony\Cmf\Component\Routing\RouteProviderInterface',
'getRouteCollectionForRequest',
new ObjectType('Symfony\Component\Routing\RouteCollection'),
),
new AddReturnTypeDeclaration(
'Symfony\Cmf\Component\Routing\RouteProviderInterface',
'getRouteByName',
new ObjectType('Symfony\Component\Routing\Route'),
),
new AddReturnTypeDeclaration(
'Symfony\Cmf\Component\Routing\RouteProviderInterface',
'getRoutesByNames',
new IterableType(new StringType(), new ObjectType('Symfony\Component\Routing\RouteCollection')),
),
// @see https://github.com/sulu/sulu/pull/6581
new AddReturnTypeDeclaration(
'Symfony\Cmf\Component\Routing\Enhancer\RouteEnhancerInterface',
'enhance',
new ArrayType(new MixedType(), new MixedType()),
),
],
);
};
1 change: 0 additions & 1 deletion rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use Rector\Set\ValueObject\SetList;

return static function (RectorConfig $rectorConfig): void {
$services = $rectorConfig->services();
$rectorConfig->importNames();
$rectorConfig->paths([__DIR__ . '/src', __DIR__ . '/tests']);

Expand Down
4 changes: 2 additions & 2 deletions src/Set/SuluLevelSetList.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ final class SuluLevelSetList implements SetListInterface
/**
* @var string
*/
final public const UP_TO_SULU_24 = __DIR__ . '/../../config/sets/symfony/level/up-to-symfony-24.php';
final public const UP_TO_SULU_24 = __DIR__ . '/../../config/sets/sulu/level/up-to-sulu-24.php';

/**
* @var string
*/
final public const UP_TO_SULU_25 = __DIR__ . '/../../config/sets/symfony/level/up-to-symfony-25.php';
final public const UP_TO_SULU_25 = __DIR__ . '/../../config/sets/sulu/level/up-to-sulu-25.php';
}
6 changes: 4 additions & 2 deletions tests/Set/Sulu24/Fixture/localization.php.inc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ class SomeClassLocalization {
public function someMethod(\Sulu\Component\Localization\Localization $localization)
{
$localization->setXDefault('en');
$localization->getXDefault();
$localization->getLocalization('_');
$localization->getLocalization('-');
$localization->isXDefault();
}
}
Expand All @@ -21,7 +22,8 @@ class SomeClassLocalization {
public function someMethod(\Sulu\Component\Localization\Localization $localization)
{
$localization->setDefault('en');
$localization->getDefault();
$localization->getLocale(\Sulu\Component\Localization\Localization::UNDERSCORE);
$localization->getLocale(\Sulu\Component\Localization\Localization::DASH);
$localization->isDefault();
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

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

class AuthenticationHandlerReturnTypes extends \Sulu\Bundle\SecurityBundle\Security\AuthenticationHandler {
public function onAuthenticationSuccess(\Symfony\Component\HttpFoundation\Request $request, \Symfony\Component\Security\Core\Authentication\Token\TokenInterface $token)
{
return parent::onAuthenticationSuccess($request, $token);
}

public function onAuthenticationFailure(\Symfony\Component\HttpFoundation\Request $request, \Symfony\Component\Security\Core\Exception\AuthenticationException $exception)
{
return parent::onAuthenticationSuccess($request, $exception);
}
}

?>
-----
<?php

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

class AuthenticationHandlerReturnTypes extends \Sulu\Bundle\SecurityBundle\Security\AuthenticationHandler {
public function onAuthenticationSuccess(\Symfony\Component\HttpFoundation\Request $request, \Symfony\Component\Security\Core\Authentication\Token\TokenInterface $token): \Symfony\Component\HttpFoundation\Response
{
return parent::onAuthenticationSuccess($request, $token);
}

public function onAuthenticationFailure(\Symfony\Component\HttpFoundation\Request $request, \Symfony\Component\Security\Core\Exception\AuthenticationException $exception): \Symfony\Component\HttpFoundation\Response
{
return parent::onAuthenticationSuccess($request, $exception);
}
}

?>
Loading

0 comments on commit 8226ae5

Please sign in to comment.