Updated Rector to commit 340f5b999c86387ef9b8fb6297516c564208ee2a

340f5b999c [DowngradePhp80] Add DowngradeEnumToConstantListClassRector (#2416)
This commit is contained in:
Tomas Votruba 2022-06-02 12:02:30 +00:00
parent 56db9b2ff8
commit e58cb04bad
14 changed files with 273 additions and 26 deletions

View File

@ -0,0 +1,61 @@
<?php
declare (strict_types=1);
namespace Rector\DowngradePhp80\Rector\Enum_;
use PhpParser\Node;
use PhpParser\Node\Stmt\Class_;
use PhpParser\Node\Stmt\Enum_;
use Rector\Core\Rector\AbstractRector;
use Rector\Php81\NodeFactory\ClassFromEnumFactory;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
/**
* @see \Rector\Tests\DowngradePhp80\Rector\Enum_\DowngradeEnumToConstantListClassRector\DowngradeEnumToConstantListClassRectorTest
*/
final class DowngradeEnumToConstantListClassRector extends \Rector\Core\Rector\AbstractRector
{
/**
* @readonly
* @var \Rector\Php81\NodeFactory\ClassFromEnumFactory
*/
private $classFromEnumFactory;
public function __construct(\Rector\Php81\NodeFactory\ClassFromEnumFactory $classFromEnumFactory)
{
$this->classFromEnumFactory = $classFromEnumFactory;
}
public function getRuleDefinition() : \Symplify\RuleDocGenerator\ValueObject\RuleDefinition
{
return new \Symplify\RuleDocGenerator\ValueObject\RuleDefinition('Downgrade enum to constant list class', [new \Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample(<<<'CODE_SAMPLE'
enum Direction
{
case LEFT;
case RIGHT;
}
CODE_SAMPLE
, <<<'CODE_SAMPLE'
class Direction
{
public const LEFT = 'left';
public const RIGHT = 'right';
}
CODE_SAMPLE
)]);
}
/**
* @return array<class-string<Node>>
*/
public function getNodeTypes() : array
{
return [\PhpParser\Node\Stmt\Enum_::class];
}
/**
* @param Enum_ $node
*/
public function refactor(\PhpParser\Node $node) : \PhpParser\Node\Stmt\Class_
{
return $this->classFromEnumFactory->createFromEnum($node);
}
}

View File

@ -0,0 +1,52 @@
<?php
declare (strict_types=1);
namespace Rector\Php81\NodeFactory;
use PhpParser\Node\Const_;
use PhpParser\Node\Expr;
use PhpParser\Node\Scalar\String_;
use PhpParser\Node\Stmt\Class_;
use PhpParser\Node\Stmt\ClassConst;
use PhpParser\Node\Stmt\Enum_;
use PhpParser\Node\Stmt\EnumCase;
use Rector\Core\ValueObject\Visibility;
use Rector\NodeNameResolver\NodeNameResolver;
final class ClassFromEnumFactory
{
/**
* @readonly
* @var \Rector\NodeNameResolver\NodeNameResolver
*/
private $nodeNameResolver;
public function __construct(\Rector\NodeNameResolver\NodeNameResolver $nodeNameResolver)
{
$this->nodeNameResolver = $nodeNameResolver;
}
public function createFromEnum(\PhpParser\Node\Stmt\Enum_ $enum) : \PhpParser\Node\Stmt\Class_
{
$shortClassName = $this->nodeNameResolver->getShortName($enum);
$classConsts = [];
foreach ($enum->stmts as $stmt) {
if (!$stmt instanceof \PhpParser\Node\Stmt\EnumCase) {
continue;
}
$constValue = $this->createConstValue($stmt);
$classConsts[] = new \PhpParser\Node\Stmt\ClassConst([new \PhpParser\Node\Const_($stmt->name, $constValue)], \Rector\Core\ValueObject\Visibility::PUBLIC);
}
$class = new \PhpParser\Node\Stmt\Class_($shortClassName, ['stmts' => $classConsts]);
$class->namespacedName = $enum->namespacedName;
return $class;
}
private function createConstValue(\PhpParser\Node\Stmt\EnumCase $enumCase) : \PhpParser\Node\Expr
{
if ($enumCase->expr instanceof \PhpParser\Node\Expr) {
return $enumCase->expr;
}
/** @var string $enumName */
$enumName = $this->nodeNameResolver->getName($enumCase);
// minimal convention
$lowercasedEnumValue = \strtolower($enumName);
return new \PhpParser\Node\Scalar\String_($lowercasedEnumValue);
}
}

View File

@ -16,11 +16,11 @@ final class VersionResolver
/**
* @var string
*/
public const PACKAGE_VERSION = 'a73dafd30a8e2cdc058080c866f7d2d6032f8ba2';
public const PACKAGE_VERSION = '340f5b999c86387ef9b8fb6297516c564208ee2a';
/**
* @var string
*/
public const RELEASE_DATE = '2022-06-02 10:58:19';
public const RELEASE_DATE = '2022-06-02 13:56:11';
/**
* @var int
*/

2
vendor/autoload.php vendored
View File

@ -9,4 +9,4 @@ if (PHP_VERSION_ID < 50600) {
require_once __DIR__ . '/composer/autoload_real.php';
return ComposerAutoloaderInitecab57cd86e1acfc1267198cfd0fd687::getLoader();
return ComposerAutoloaderInit5d1be6c7a55a96b27577953683119c6d::getLoader();

View File

@ -1994,6 +1994,7 @@ return array(
'Rector\\DowngradePhp80\\Rector\\ClassMethod\\DowngradeTrailingCommasInParamUseRector' => $baseDir . '/rules/DowngradePhp80/Rector/ClassMethod/DowngradeTrailingCommasInParamUseRector.php',
'Rector\\DowngradePhp80\\Rector\\Class_\\DowngradeAttributeToAnnotationRector' => $baseDir . '/rules/DowngradePhp80/Rector/Class_/DowngradeAttributeToAnnotationRector.php',
'Rector\\DowngradePhp80\\Rector\\Class_\\DowngradePropertyPromotionRector' => $baseDir . '/rules/DowngradePhp80/Rector/Class_/DowngradePropertyPromotionRector.php',
'Rector\\DowngradePhp80\\Rector\\Enum_\\DowngradeEnumToConstantListClassRector' => $baseDir . '/rules/DowngradePhp80/Rector/Enum_/DowngradeEnumToConstantListClassRector.php',
'Rector\\DowngradePhp80\\Rector\\Expression\\DowngradeMatchToSwitchRector' => $baseDir . '/rules/DowngradePhp80/Rector/Expression/DowngradeMatchToSwitchRector.php',
'Rector\\DowngradePhp80\\Rector\\Expression\\DowngradeThrowExprRector' => $baseDir . '/rules/DowngradePhp80/Rector/Expression/DowngradeThrowExprRector.php',
'Rector\\DowngradePhp80\\Rector\\FuncCall\\DowngradeArrayFilterNullableCallbackRector' => $baseDir . '/rules/DowngradePhp80/Rector/FuncCall/DowngradeArrayFilterNullableCallbackRector.php',
@ -2622,6 +2623,7 @@ return array(
'Rector\\Php80\\ValueObject\\PropertyPromotionCandidate' => $baseDir . '/rules/Php80/ValueObject/PropertyPromotionCandidate.php',
'Rector\\Php80\\ValueObject\\StrStartsWith' => $baseDir . '/rules/Php80/ValueObject/StrStartsWith.php',
'Rector\\Php81\\NodeAnalyzer\\ComplexNewAnalyzer' => $baseDir . '/rules/Php81/NodeAnalyzer/ComplexNewAnalyzer.php',
'Rector\\Php81\\NodeFactory\\ClassFromEnumFactory' => $baseDir . '/rules/Php81/NodeFactory/ClassFromEnumFactory.php',
'Rector\\Php81\\NodeFactory\\EnumFactory' => $baseDir . '/rules/Php81/NodeFactory/EnumFactory.php',
'Rector\\Php81\\Rector\\ClassConst\\FinalizePublicClassConstantRector' => $baseDir . '/rules/Php81/Rector/ClassConst/FinalizePublicClassConstantRector.php',
'Rector\\Php81\\Rector\\ClassMethod\\NewInInitializerRector' => $baseDir . '/rules/Php81/Rector/ClassMethod/NewInInitializerRector.php',
@ -3288,6 +3290,7 @@ return array(
'Ssch\\TYPO3Rector\\Rector\\v12\\v0\\ReplacePreviewUrlMethodRector' => $vendorDir . '/ssch/typo3-rector/src/Rector/v12/v0/ReplacePreviewUrlMethodRector.php',
'Ssch\\TYPO3Rector\\Rector\\v12\\v0\\typo3\\RemoveUpdateRootlineDataRector' => $vendorDir . '/ssch/typo3-rector/src/Rector/v12/v0/typo3/RemoveUpdateRootlineDataRector.php',
'Ssch\\TYPO3Rector\\Rector\\v12\\v0\\typo3\\ReplaceContentObjectRendererGetMailToWithEmailLinkBuilderRector' => $vendorDir . '/ssch/typo3-rector/src/Rector/v12/v0/typo3/ReplaceContentObjectRendererGetMailToWithEmailLinkBuilderRector.php',
'Ssch\\TYPO3Rector\\Rector\\v12\\v0\\typo3\\ReplaceTSFECheckEnableFieldsRector' => $vendorDir . '/ssch/typo3-rector/src/Rector/v12/v0/typo3/ReplaceTSFECheckEnableFieldsRector.php',
'Ssch\\TYPO3Rector\\Rector\\v7\\v0\\RemoveDivider2TabsConfigurationRector' => $vendorDir . '/ssch/typo3-rector/src/Rector/v7/v0/RemoveDivider2TabsConfigurationRector.php',
'Ssch\\TYPO3Rector\\Rector\\v7\\v0\\RemoveMethodCallConnectDbRector' => $vendorDir . '/ssch/typo3-rector/src/Rector/v7/v0/RemoveMethodCallConnectDbRector.php',
'Ssch\\TYPO3Rector\\Rector\\v7\\v0\\RemoveMethodCallLoadTcaRector' => $vendorDir . '/ssch/typo3-rector/src/Rector/v7/v0/RemoveMethodCallLoadTcaRector.php',

View File

@ -2,7 +2,7 @@
// autoload_real.php @generated by Composer
class ComposerAutoloaderInitecab57cd86e1acfc1267198cfd0fd687
class ComposerAutoloaderInit5d1be6c7a55a96b27577953683119c6d
{
private static $loader;
@ -22,19 +22,19 @@ class ComposerAutoloaderInitecab57cd86e1acfc1267198cfd0fd687
return self::$loader;
}
spl_autoload_register(array('ComposerAutoloaderInitecab57cd86e1acfc1267198cfd0fd687', 'loadClassLoader'), true, true);
spl_autoload_register(array('ComposerAutoloaderInit5d1be6c7a55a96b27577953683119c6d', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
spl_autoload_unregister(array('ComposerAutoloaderInitecab57cd86e1acfc1267198cfd0fd687', 'loadClassLoader'));
spl_autoload_unregister(array('ComposerAutoloaderInit5d1be6c7a55a96b27577953683119c6d', 'loadClassLoader'));
require __DIR__ . '/autoload_static.php';
call_user_func(\Composer\Autoload\ComposerStaticInitecab57cd86e1acfc1267198cfd0fd687::getInitializer($loader));
call_user_func(\Composer\Autoload\ComposerStaticInit5d1be6c7a55a96b27577953683119c6d::getInitializer($loader));
$loader->setClassMapAuthoritative(true);
$loader->register(true);
$includeFiles = \Composer\Autoload\ComposerStaticInitecab57cd86e1acfc1267198cfd0fd687::$files;
$includeFiles = \Composer\Autoload\ComposerStaticInit5d1be6c7a55a96b27577953683119c6d::$files;
foreach ($includeFiles as $fileIdentifier => $file) {
composerRequireecab57cd86e1acfc1267198cfd0fd687($fileIdentifier, $file);
composerRequire5d1be6c7a55a96b27577953683119c6d($fileIdentifier, $file);
}
return $loader;
@ -46,7 +46,7 @@ class ComposerAutoloaderInitecab57cd86e1acfc1267198cfd0fd687
* @param string $file
* @return void
*/
function composerRequireecab57cd86e1acfc1267198cfd0fd687($fileIdentifier, $file)
function composerRequire5d1be6c7a55a96b27577953683119c6d($fileIdentifier, $file)
{
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
$GLOBALS['__composer_autoload_files'][$fileIdentifier] = true;

View File

@ -4,7 +4,7 @@
namespace Composer\Autoload;
class ComposerStaticInitecab57cd86e1acfc1267198cfd0fd687
class ComposerStaticInit5d1be6c7a55a96b27577953683119c6d
{
public static $files = array (
'0e6d7bf4a5811bfa5cf40c5ccd6fae6a' => __DIR__ . '/..' . '/symfony/polyfill-mbstring/bootstrap.php',
@ -2321,6 +2321,7 @@ class ComposerStaticInitecab57cd86e1acfc1267198cfd0fd687
'Rector\\DowngradePhp80\\Rector\\ClassMethod\\DowngradeTrailingCommasInParamUseRector' => __DIR__ . '/../..' . '/rules/DowngradePhp80/Rector/ClassMethod/DowngradeTrailingCommasInParamUseRector.php',
'Rector\\DowngradePhp80\\Rector\\Class_\\DowngradeAttributeToAnnotationRector' => __DIR__ . '/../..' . '/rules/DowngradePhp80/Rector/Class_/DowngradeAttributeToAnnotationRector.php',
'Rector\\DowngradePhp80\\Rector\\Class_\\DowngradePropertyPromotionRector' => __DIR__ . '/../..' . '/rules/DowngradePhp80/Rector/Class_/DowngradePropertyPromotionRector.php',
'Rector\\DowngradePhp80\\Rector\\Enum_\\DowngradeEnumToConstantListClassRector' => __DIR__ . '/../..' . '/rules/DowngradePhp80/Rector/Enum_/DowngradeEnumToConstantListClassRector.php',
'Rector\\DowngradePhp80\\Rector\\Expression\\DowngradeMatchToSwitchRector' => __DIR__ . '/../..' . '/rules/DowngradePhp80/Rector/Expression/DowngradeMatchToSwitchRector.php',
'Rector\\DowngradePhp80\\Rector\\Expression\\DowngradeThrowExprRector' => __DIR__ . '/../..' . '/rules/DowngradePhp80/Rector/Expression/DowngradeThrowExprRector.php',
'Rector\\DowngradePhp80\\Rector\\FuncCall\\DowngradeArrayFilterNullableCallbackRector' => __DIR__ . '/../..' . '/rules/DowngradePhp80/Rector/FuncCall/DowngradeArrayFilterNullableCallbackRector.php',
@ -2949,6 +2950,7 @@ class ComposerStaticInitecab57cd86e1acfc1267198cfd0fd687
'Rector\\Php80\\ValueObject\\PropertyPromotionCandidate' => __DIR__ . '/../..' . '/rules/Php80/ValueObject/PropertyPromotionCandidate.php',
'Rector\\Php80\\ValueObject\\StrStartsWith' => __DIR__ . '/../..' . '/rules/Php80/ValueObject/StrStartsWith.php',
'Rector\\Php81\\NodeAnalyzer\\ComplexNewAnalyzer' => __DIR__ . '/../..' . '/rules/Php81/NodeAnalyzer/ComplexNewAnalyzer.php',
'Rector\\Php81\\NodeFactory\\ClassFromEnumFactory' => __DIR__ . '/../..' . '/rules/Php81/NodeFactory/ClassFromEnumFactory.php',
'Rector\\Php81\\NodeFactory\\EnumFactory' => __DIR__ . '/../..' . '/rules/Php81/NodeFactory/EnumFactory.php',
'Rector\\Php81\\Rector\\ClassConst\\FinalizePublicClassConstantRector' => __DIR__ . '/../..' . '/rules/Php81/Rector/ClassConst/FinalizePublicClassConstantRector.php',
'Rector\\Php81\\Rector\\ClassMethod\\NewInInitializerRector' => __DIR__ . '/../..' . '/rules/Php81/Rector/ClassMethod/NewInInitializerRector.php',
@ -3615,6 +3617,7 @@ class ComposerStaticInitecab57cd86e1acfc1267198cfd0fd687
'Ssch\\TYPO3Rector\\Rector\\v12\\v0\\ReplacePreviewUrlMethodRector' => __DIR__ . '/..' . '/ssch/typo3-rector/src/Rector/v12/v0/ReplacePreviewUrlMethodRector.php',
'Ssch\\TYPO3Rector\\Rector\\v12\\v0\\typo3\\RemoveUpdateRootlineDataRector' => __DIR__ . '/..' . '/ssch/typo3-rector/src/Rector/v12/v0/typo3/RemoveUpdateRootlineDataRector.php',
'Ssch\\TYPO3Rector\\Rector\\v12\\v0\\typo3\\ReplaceContentObjectRendererGetMailToWithEmailLinkBuilderRector' => __DIR__ . '/..' . '/ssch/typo3-rector/src/Rector/v12/v0/typo3/ReplaceContentObjectRendererGetMailToWithEmailLinkBuilderRector.php',
'Ssch\\TYPO3Rector\\Rector\\v12\\v0\\typo3\\ReplaceTSFECheckEnableFieldsRector' => __DIR__ . '/..' . '/ssch/typo3-rector/src/Rector/v12/v0/typo3/ReplaceTSFECheckEnableFieldsRector.php',
'Ssch\\TYPO3Rector\\Rector\\v7\\v0\\RemoveDivider2TabsConfigurationRector' => __DIR__ . '/..' . '/ssch/typo3-rector/src/Rector/v7/v0/RemoveDivider2TabsConfigurationRector.php',
'Ssch\\TYPO3Rector\\Rector\\v7\\v0\\RemoveMethodCallConnectDbRector' => __DIR__ . '/..' . '/ssch/typo3-rector/src/Rector/v7/v0/RemoveMethodCallConnectDbRector.php',
'Ssch\\TYPO3Rector\\Rector\\v7\\v0\\RemoveMethodCallLoadTcaRector' => __DIR__ . '/..' . '/ssch/typo3-rector/src/Rector/v7/v0/RemoveMethodCallLoadTcaRector.php',
@ -3787,9 +3790,9 @@ class ComposerStaticInitecab57cd86e1acfc1267198cfd0fd687
public static function getInitializer(ClassLoader $loader)
{
return \Closure::bind(function () use ($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticInitecab57cd86e1acfc1267198cfd0fd687::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInitecab57cd86e1acfc1267198cfd0fd687::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInitecab57cd86e1acfc1267198cfd0fd687::$classMap;
$loader->prefixLengthsPsr4 = ComposerStaticInit5d1be6c7a55a96b27577953683119c6d::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit5d1be6c7a55a96b27577953683119c6d::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInit5d1be6c7a55a96b27577953683119c6d::$classMap;
}, null, ClassLoader::class);
}

View File

@ -2554,12 +2554,12 @@
"source": {
"type": "git",
"url": "https:\/\/github.com\/sabbelasichon\/typo3-rector.git",
"reference": "127f33e9feee0ef426a261f4b181bc92e4ad3e33"
"reference": "30231477ac26fa550f45adfa3d37b94453e6f778"
},
"dist": {
"type": "zip",
"url": "https:\/\/api.github.com\/repos\/sabbelasichon\/typo3-rector\/zipball\/127f33e9feee0ef426a261f4b181bc92e4ad3e33",
"reference": "127f33e9feee0ef426a261f4b181bc92e4ad3e33",
"url": "https:\/\/api.github.com\/repos\/sabbelasichon\/typo3-rector\/zipball\/30231477ac26fa550f45adfa3d37b94453e6f778",
"reference": "30231477ac26fa550f45adfa3d37b94453e6f778",
"shasum": ""
},
"require": {
@ -2589,7 +2589,7 @@
"symplify\/vendor-patches": "^10.2",
"tracy\/tracy": "^2.8"
},
"time": "2022-06-02T01:23:01+00:00",
"time": "2022-06-02T11:25:04+00:00",
"default-branch": true,
"type": "rector-extension",
"extra": {

File diff suppressed because one or more lines are too long

View File

@ -9,7 +9,7 @@ namespace Rector\RectorInstaller;
*/
final class GeneratedConfig
{
public const EXTENSIONS = array('rector/rector-cakephp' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-cakephp', 'relative_install_path' => '../../rector-cakephp', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 1ba95e5'), 'rector/rector-doctrine' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-doctrine', 'relative_install_path' => '../../rector-doctrine', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main c745427'), 'rector/rector-generator' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-generator', 'relative_install_path' => '../../rector-generator', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 784271e'), 'rector/rector-laravel' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-laravel', 'relative_install_path' => '../../rector-laravel', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main e1d324e'), 'rector/rector-nette' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-nette', 'relative_install_path' => '../../rector-nette', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main b4026b1'), 'rector/rector-phpoffice' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-phpoffice', 'relative_install_path' => '../../rector-phpoffice', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 86b0213'), 'rector/rector-phpunit' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-phpunit', 'relative_install_path' => '../../rector-phpunit', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 31de140'), 'rector/rector-symfony' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-symfony', 'relative_install_path' => '../../rector-symfony', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 6ad431c'), 'ssch/typo3-rector' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/ssch/typo3-rector', 'relative_install_path' => '../../../ssch/typo3-rector', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 127f33e'));
public const EXTENSIONS = array('rector/rector-cakephp' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-cakephp', 'relative_install_path' => '../../rector-cakephp', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 1ba95e5'), 'rector/rector-doctrine' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-doctrine', 'relative_install_path' => '../../rector-doctrine', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main c745427'), 'rector/rector-generator' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-generator', 'relative_install_path' => '../../rector-generator', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 784271e'), 'rector/rector-laravel' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-laravel', 'relative_install_path' => '../../rector-laravel', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main e1d324e'), 'rector/rector-nette' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-nette', 'relative_install_path' => '../../rector-nette', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main b4026b1'), 'rector/rector-phpoffice' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-phpoffice', 'relative_install_path' => '../../rector-phpoffice', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 86b0213'), 'rector/rector-phpunit' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-phpunit', 'relative_install_path' => '../../rector-phpunit', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 31de140'), 'rector/rector-symfony' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-symfony', 'relative_install_path' => '../../rector-symfony', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 6ad431c'), 'ssch/typo3-rector' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/ssch/typo3-rector', 'relative_install_path' => '../../../ssch/typo3-rector', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 3023147'));
private function __construct()
{
}

View File

@ -9,8 +9,8 @@ $loader = require_once __DIR__.'/autoload.php';
if (!class_exists('AutoloadIncluder', false) && !interface_exists('AutoloadIncluder', false) && !trait_exists('AutoloadIncluder', false)) {
spl_autoload_call('RectorPrefix20220602\AutoloadIncluder');
}
if (!class_exists('ComposerAutoloaderInitecab57cd86e1acfc1267198cfd0fd687', false) && !interface_exists('ComposerAutoloaderInitecab57cd86e1acfc1267198cfd0fd687', false) && !trait_exists('ComposerAutoloaderInitecab57cd86e1acfc1267198cfd0fd687', false)) {
spl_autoload_call('RectorPrefix20220602\ComposerAutoloaderInitecab57cd86e1acfc1267198cfd0fd687');
if (!class_exists('ComposerAutoloaderInit5d1be6c7a55a96b27577953683119c6d', false) && !interface_exists('ComposerAutoloaderInit5d1be6c7a55a96b27577953683119c6d', false) && !trait_exists('ComposerAutoloaderInit5d1be6c7a55a96b27577953683119c6d', false)) {
spl_autoload_call('RectorPrefix20220602\ComposerAutoloaderInit5d1be6c7a55a96b27577953683119c6d');
}
if (!class_exists('Helmich\TypoScriptParser\Parser\AST\Statement', false) && !interface_exists('Helmich\TypoScriptParser\Parser\AST\Statement', false) && !trait_exists('Helmich\TypoScriptParser\Parser\AST\Statement', false)) {
spl_autoload_call('RectorPrefix20220602\Helmich\TypoScriptParser\Parser\AST\Statement');
@ -59,9 +59,9 @@ if (!function_exists('print_node')) {
return \RectorPrefix20220602\print_node(...func_get_args());
}
}
if (!function_exists('composerRequireecab57cd86e1acfc1267198cfd0fd687')) {
function composerRequireecab57cd86e1acfc1267198cfd0fd687() {
return \RectorPrefix20220602\composerRequireecab57cd86e1acfc1267198cfd0fd687(...func_get_args());
if (!function_exists('composerRequire5d1be6c7a55a96b27577953683119c6d')) {
function composerRequire5d1be6c7a55a96b27577953683119c6d() {
return \RectorPrefix20220602\composerRequire5d1be6c7a55a96b27577953683119c6d(...func_get_args());
}
}
if (!function_exists('scanPath')) {

View File

@ -17,6 +17,7 @@ return static function (\Rector\Config\RectorConfig $rectorConfig) : void {
$rectorConfig->ruleWithConfiguration(\Ssch\TYPO3Rector\Rector\Migrations\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']);
$rectorConfig->rule(\Ssch\TYPO3Rector\Rector\v12\v0\ReplacePreviewUrlMethodRector::class);
$rectorConfig->rule(\Ssch\TYPO3Rector\FileProcessor\Resources\Files\Rector\RenameExtTypoScriptFilesFileRector::class);
$rectorConfig->rule(\Ssch\TYPO3Rector\Rector\v12\v0\typo3\ReplaceTSFECheckEnableFieldsRector::class);
$rectorConfig->rule(\Ssch\TYPO3Rector\Rector\v12\v0\typo3\ReplaceContentObjectRendererGetMailToWithEmailLinkBuilderRector::class);
$rectorConfig->rule(\Ssch\TYPO3Rector\Rector\v12\v0\typo3\RemoveUpdateRootlineDataRector::class);
};

View File

@ -1,4 +1,4 @@
# 243 Rules Overview
# 244 Rules Overview
## AddRenderTypeToSelectFieldRector
@ -3617,6 +3617,33 @@ Replaces all direct calls to `$GLOBALS['TSFE']->ATagParams.`
<br>
## ReplaceTSFECheckEnableFieldsRector
Replace TSFE calls to checkEnableFields with new RecordAccessVoter->accessGranted method
- class: [`Ssch\TYPO3Rector\Rector\v12\v0\typo3\ReplaceTSFECheckEnableFieldsRector`](../src/Rector/v12/v0/typo3/ReplaceTSFECheckEnableFieldsRector.php)
```diff
+use TYPO3\CMS\Core\Domain\Access\RecordAccessVoter\RecordAccessVoter;
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
$row = [];
-$foo = $GLOBALS['TSFE']->checkEnableFields($row);
-$foofoo = $GLOBALS['TSFE']->checkPagerecordForIncludeSection($row);
+$foo = GeneralUtility::makeInstance(RecordAccessVoter::class)->accessGranted('pages', $row, $GLOBALS['TSFE']->getContext());
+$foofoo = GeneralUtility::makeInstance(RecordAccessVoter::class)->accessGrantedForPageInRootLine($row, $GLOBALS['TSFE']->getContext());
/** @var TypoScriptFrontendController $typoscriptFrontendController */
$typoscriptFrontendController = $GLOBALS['TSFE'];
-$bar = $typoscriptFrontendController->checkEnableFields($row);
-$baz = $typoscriptFrontendController->checkPagerecordForIncludeSection($row);
+$bar = GeneralUtility::makeInstance(RecordAccessVoter::class)->accessGranted('pages', $row, $typoscriptFrontendController->getContext());
+$baz = GeneralUtility::makeInstance(RecordAccessVoter::class)->accessGrantedForPageInRootLine($row, $typoscriptFrontendController->getContext());
```
<br>
## ReplacedGeneralUtilitySysLogWithLogginApiRector
Replaced GeneralUtility::sysLog with Logging API

View File

@ -0,0 +1,100 @@
<?php
declare (strict_types=1);
namespace Ssch\TYPO3Rector\Rector\v12\v0\typo3;
use PhpParser\Node;
use PhpParser\Node\Expr\Array_;
use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Scalar\String_;
use PHPStan\Type\ObjectType;
use Rector\Core\Rector\AbstractRector;
use Ssch\TYPO3Rector\Helper\Typo3NodeResolver;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
/**
* @changelog https://docs.typo3.org/c/typo3/cms-core/main/en-us/Changelog/12.0/Deprecation-96996-DeprecateTypoScriptFrontendController-checkEnableFields.html
* @see \Ssch\TYPO3Rector\Tests\Rector\v12\v0\typo3\ReplaceTSFECheckEnableFieldsRector\ReplaceTSFECheckEnableFieldsRectorTest
*/
final class ReplaceTSFECheckEnableFieldsRector extends \Rector\Core\Rector\AbstractRector
{
/**
* @readonly
* @var \Ssch\TYPO3Rector\Helper\Typo3NodeResolver
*/
private $typo3NodeResolver;
public function __construct(\Ssch\TYPO3Rector\Helper\Typo3NodeResolver $typo3NodeResolver)
{
$this->typo3NodeResolver = $typo3NodeResolver;
}
/**
* @return array<class-string<Node>>
*/
public function getNodeTypes() : array
{
return [\PhpParser\Node\Expr\MethodCall::class];
}
/**
* @param MethodCall $node
*/
public function refactor(\PhpParser\Node $node) : ?\PhpParser\Node
{
if ($this->shouldSkip($node)) {
return null;
}
if (!$this->isNames($node->name, ['checkEnableFields', 'checkPagerecordForIncludeSection'])) {
return null;
}
$contextCall = $this->nodeFactory->createMethodCall($node->var, 'getContext');
$rowArgument = $node->args[0] ?? new \PhpParser\Node\Expr\Array_();
if ($this->isName($node->name, 'checkEnableFields')) {
$arguments = [new \PhpParser\Node\Scalar\String_('pages'), $rowArgument, $contextCall];
$replacementMethod = 'accessGranted';
} else {
$arguments = [$rowArgument, $contextCall];
$replacementMethod = 'accessGrantedForPageInRootLine';
}
return $this->nodeFactory->createMethodCall($this->nodeFactory->createStaticCall('TYPO3\\CMS\\Core\\Utility\\GeneralUtility', 'makeInstance', [$this->nodeFactory->createClassConstReference('TYPO3\\CMS\\Core\\Domain\\Access\\RecordAccessVoter\\RecordAccessVoter')]), $replacementMethod, $arguments);
}
/**
* @codeCoverageIgnore
*/
public function getRuleDefinition() : \Symplify\RuleDocGenerator\ValueObject\RuleDefinition
{
return new \Symplify\RuleDocGenerator\ValueObject\RuleDefinition('Replace TSFE calls to checkEnableFields with new RecordAccessVoter->accessGranted method ', [new \Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample(<<<'CODE_SAMPLE'
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
$row = [];
$foo = $GLOBALS['TSFE']->checkEnableFields($row);
$foofoo = $GLOBALS['TSFE']->checkPagerecordForIncludeSection($row);
/** @var TypoScriptFrontendController $typoscriptFrontendController */
$typoscriptFrontendController = $GLOBALS['TSFE'];
$bar = $typoscriptFrontendController->checkEnableFields($row);
$baz = $typoscriptFrontendController->checkPagerecordForIncludeSection($row);
CODE_SAMPLE
, <<<'CODE_SAMPLE'
use TYPO3\CMS\Core\Domain\Access\RecordAccessVoter\RecordAccessVoter;
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
$row = [];
$foo = GeneralUtility::makeInstance(RecordAccessVoter::class)->accessGranted('pages', $row, $GLOBALS['TSFE']->getContext());
$foofoo = GeneralUtility::makeInstance(RecordAccessVoter::class)->accessGrantedForPageInRootLine($row, $GLOBALS['TSFE']->getContext());
/** @var TypoScriptFrontendController $typoscriptFrontendController */
$typoscriptFrontendController = $GLOBALS['TSFE'];
$bar = GeneralUtility::makeInstance(RecordAccessVoter::class)->accessGranted('pages', $row, $typoscriptFrontendController->getContext());
$baz = GeneralUtility::makeInstance(RecordAccessVoter::class)->accessGrantedForPageInRootLine($row, $typoscriptFrontendController->getContext());
CODE_SAMPLE
)]);
}
private function shouldSkip(\PhpParser\Node\Expr\MethodCall $methodCall) : bool
{
if ($this->typo3NodeResolver->isAnyMethodCallOnGlobals($methodCall, \Ssch\TYPO3Rector\Helper\Typo3NodeResolver::TYPO_SCRIPT_FRONTEND_CONTROLLER)) {
return \false;
}
return !$this->isObjectType($methodCall->var, new \PHPStan\Type\ObjectType('TYPO3\\CMS\\Frontend\\Controller\\TypoScriptFrontendController'));
}
}