Skip to content

Commit

Permalink
TASK: Add rector configuration (#3119)
Browse files Browse the repository at this point in the history
Resolves: #3105
  • Loading branch information
sabbelasichon authored Aug 21, 2022
1 parent 4a62031 commit 43c823d
Show file tree
Hide file tree
Showing 8 changed files with 274 additions and 3 deletions.
107 changes: 104 additions & 3 deletions config/v12/typo3-120.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
declare(strict_types=1);

use Rector\Config\RectorConfig;
use Rector\Renaming\Rector\ClassConstFetch\RenameClassConstFetchRector;
use Rector\Renaming\ValueObject\RenameClassAndConstFetch;
use Rector\Renaming\ValueObject\RenameClassConstFetch;
use Ssch\TYPO3Rector\FileProcessor\Resources\Files\Rector\v12\v0\RenameExtTypoScriptFilesFileRector;
use Ssch\TYPO3Rector\Rector\Migrations\RenameClassMapAliasRector;
use Ssch\TYPO3Rector\Rector\v12\v0\ReplacePreviewUrlMethodRector;
Expand All @@ -20,13 +23,14 @@
use Ssch\TYPO3Rector\Rector\v12\v0\typo3\ReplaceTSFEWithContextMethodsRector;
use Ssch\TYPO3Rector\Rector\v12\v0\typo3\SubstituteCompositeExpressionAddMethodsRector;
use Ssch\TYPO3Rector\Rector\v12\v0\typo3\UseCompositeExpressionStaticMethodsRector;
use TYPO3\CMS\Core\Messaging\AbstractMessage;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->import(__DIR__ . '/../config.php');
$rectorConfig->import(__DIR__.'/../config.php');
$rectorConfig->rule(RenameExtTypoScriptFilesFileRector::class);
$rectorConfig->ruleWithConfiguration(RenameClassMapAliasRector::class, [
__DIR__ . '/../../Migrations/TYPO3/12.0/typo3/sysext/backend/Migrations/Code/ClassAliasMap.php',
__DIR__ . '/../../Migrations/TYPO3/12.0/typo3/sysext/frontend/Migrations/Code/ClassAliasMap.php',
__DIR__.'/../../Migrations/TYPO3/12.0/typo3/sysext/backend/Migrations/Code/ClassAliasMap.php',
__DIR__.'/../../Migrations/TYPO3/12.0/typo3/sysext/frontend/Migrations/Code/ClassAliasMap.php',
]);
$rectorConfig->rule(ReplacePreviewUrlMethodRector::class);
$rectorConfig->rule(AddMethodToWidgetInterfaceClassesRector::class);
Expand All @@ -43,4 +47,101 @@
$rectorConfig->rule(ReplaceTSFEWithContextMethodsRector::class);
$rectorConfig->rule(SubstituteCompositeExpressionAddMethodsRector::class);
$rectorConfig->rule(UseCompositeExpressionStaticMethodsRector::class);

# https://docs.typo3.org/c/typo3/cms-core/master/en-us/Changelog/12.0/Deprecation-97787-SeveritiesOfFlashMessagesAndReportsDeprecated.html
$rectorConfig->ruleWithConfiguration(
RenameClassConstFetchRector::class,
[
new RenameClassAndConstFetch(
'TYPO3\CMS\Core\Messaging\AbstractMessage',
'NOTICE',
'TYPO3\CMS\Core\Type\ContextualFeedbackSeverity',
'NOTICE'
),
new RenameClassAndConstFetch(
'TYPO3\CMS\Core\Messaging\AbstractMessage',
'INFO',
'TYPO3\CMS\Core\Type\ContextualFeedbackSeverity',
'INFO'
),
new RenameClassAndConstFetch(
'TYPO3\CMS\Core\Messaging\AbstractMessage',
'OK',
'TYPO3\CMS\Core\Type\ContextualFeedbackSeverity',
'OK'
),
new RenameClassAndConstFetch(
'TYPO3\CMS\Core\Messaging\AbstractMessage',
'WARNING',
'TYPO3\CMS\Core\Type\ContextualFeedbackSeverity',
'WARNING'
),
new RenameClassAndConstFetch(
'TYPO3\CMS\Core\Messaging\AbstractMessage',
'ERROR',
'TYPO3\CMS\Core\Type\ContextualFeedbackSeverity',
'ERROR'
),
new RenameClassAndConstFetch(
'TYPO3\CMS\Core\Messaging\FlashMessage',
'NOTICE',
'TYPO3\CMS\Core\Type\ContextualFeedbackSeverity',
'NOTICE'
),
new RenameClassAndConstFetch(
'TYPO3\CMS\Core\Messaging\FlashMessage',
'INFO',
'TYPO3\CMS\Core\Type\ContextualFeedbackSeverity',
'INFO'
),
new RenameClassAndConstFetch(
'TYPO3\CMS\Core\Messaging\FlashMessage',
'OK',
'TYPO3\CMS\Core\Type\ContextualFeedbackSeverity',
'OK'
),
new RenameClassAndConstFetch(
'TYPO3\CMS\Core\Messaging\FlashMessage',
'WARNING',
'TYPO3\CMS\Core\Type\ContextualFeedbackSeverity',
'WARNING'
),
new RenameClassAndConstFetch(
'TYPO3\CMS\Core\Messaging\FlashMessage',
'ERROR',
'TYPO3\CMS\Core\Type\ContextualFeedbackSeverity',
'ERROR'
),
new RenameClassAndConstFetch(
'TYPO3\CMS\Reports\Status',
'NOTICE',
'TYPO3\CMS\Core\Type\ContextualFeedbackSeverity',
'NOTICE'
),
new RenameClassAndConstFetch(
'TYPO3\CMS\Reports\Status',
'INFO',
'TYPO3\CMS\Core\Type\ContextualFeedbackSeverity',
'INFO'
),
new RenameClassAndConstFetch(
'TYPO3\CMS\Reports\Status',
'OK',
'TYPO3\CMS\Core\Type\ContextualFeedbackSeverity',
'OK'
),
new RenameClassAndConstFetch(
'TYPO3\CMS\Reports\Status',
'WARNING',
'TYPO3\CMS\Core\Type\ContextualFeedbackSeverity',
'WARNING'
),
new RenameClassAndConstFetch(
'TYPO3\CMS\Reports\Status',
'ERROR',
'TYPO3\CMS\Core\Type\ContextualFeedbackSeverity',
'ERROR'
),
]
);
};
22 changes: 22 additions & 0 deletions stubs/TYPO3/CMS/Core/Messaging/AbstractMessage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php
namespace TYPO3\CMS\Core\Messaging;

use TYPO3\CMS\Core\Type\ContextualFeedbackSeverity;

if (class_exists('TYPO3\CMS\Core\Messaging\AbstractMessage')) {
return;
}

abstract class AbstractMessage implements \JsonSerializable
{
const NOTICE = -2;
const INFO = -1;
const OK = 0;
const WARNING = 1;
const ERROR = 2;

public function setSeverity($severity = ContextualFeedbackSeverity::OK): void
{

}
}
14 changes: 14 additions & 0 deletions stubs/TYPO3/CMS/Core/Messaging/FlashMessage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php
namespace TYPO3\CMS\Core\Messaging;

if (class_exists('TYPO3\CMS\Core\Messaging\FlashMessage')) {
return;
}

class FlashMessage extends AbstractMessage
{
public function jsonSerialize()
{
return [];
}
}
15 changes: 15 additions & 0 deletions stubs/TYPO3/CMS/Core/Type/ContextualFeedbackSeverity.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php
namespace TYPO3\CMS\Core\Type;

if (class_exists('TYPO3\CMS\Core\Type\ContextualFeedbackSeverity')) {
return;
}

class ContextualFeedbackSeverity
{
const NOTICE = -2;
const INFO = -1;
const OK = 0;
const WARNING = 1;
const ERROR = 2;
}
29 changes: 29 additions & 0 deletions stubs/TYPO3/CMS/Reports/Status.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php
namespace TYPO3\CMS\Reports;

use TYPO3\CMS\Core\Type\ContextualFeedbackSeverity;

if (class_exists('TYPO3\CMS\Reports\Status')) {
return;
}

class Status
{
const NOTICE = -2;
const INFO = -1;
const OK = 0;
const WARNING = 1;
const ERROR = 2;

private int $severity;

public function __construct($severity = ContextualFeedbackSeverity::OK)
{
$this->severity = $severity;
}

public function getSeverity(): int
{
return $this->severity;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

namespace Ssch\TYPO3Rector\Tests\Rector\v12\v0\typo3\ReplaceSeveritiesFlashMessageAndReportsRector\Fixture;

use TYPO3\CMS\Core\Messaging\FlashMessage;
use TYPO3\CMS\Reports\Status;

$flashMessage = new FlashMessage();
$flashMessage->setSeverity(FlashMessage::NOTICE);
$flashMessage->setSeverity(FlashMessage::ERROR);
$flashMessage->setSeverity(FlashMessage::INFO);
$flashMessage->setSeverity(FlashMessage::OK);
$flashMessage->setSeverity(FlashMessage::WARNING);

$statusNotice = new Status(Status::NOTICE);
$statusInfo = new Status(Status::INFO);
$statusWarning = new Status(Status::WARNING);
$statusOk = new Status(Status::OK);
$statusError = new Status(Status::ERROR);

?>
-----
<?php

namespace Ssch\TYPO3Rector\Tests\Rector\v12\v0\typo3\ReplaceSeveritiesFlashMessageAndReportsRector\Fixture;

use TYPO3\CMS\Core\Type\ContextualFeedbackSeverity;
use TYPO3\CMS\Core\Messaging\FlashMessage;
use TYPO3\CMS\Reports\Status;

$flashMessage = new FlashMessage();
$flashMessage->setSeverity(ContextualFeedbackSeverity::NOTICE);
$flashMessage->setSeverity(ContextualFeedbackSeverity::ERROR);
$flashMessage->setSeverity(ContextualFeedbackSeverity::INFO);
$flashMessage->setSeverity(ContextualFeedbackSeverity::OK);
$flashMessage->setSeverity(ContextualFeedbackSeverity::WARNING);

$statusNotice = new Status(ContextualFeedbackSeverity::NOTICE);
$statusInfo = new Status(ContextualFeedbackSeverity::INFO);
$statusWarning = new Status(ContextualFeedbackSeverity::WARNING);
$statusOk = new Status(ContextualFeedbackSeverity::OK);
$statusError = new Status(ContextualFeedbackSeverity::ERROR);

?>
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php
declare(strict_types=1);


namespace Ssch\TYPO3Rector\Tests\Rector\v12\v0\typo3\ReplaceSeveritiesFlashMessageAndReportsRector;


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

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

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

public function provideConfigFilePath(): string
{
return __DIR__ . '/config/configured_rule.php';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

declare(strict_types=1);

use Rector\Config\RectorConfig;

use Ssch\TYPO3Rector\Rector\v12\v0\typo3\ReplaceExpressionBuilderMethodsRector;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->import(__DIR__ . '/../../../../../../../config/config_test.php');
$rectorConfig->import(__DIR__ . '/../../../../../../../config/v12/typo3-120.php');
};

0 comments on commit 43c823d

Please sign in to comment.