-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrector.php
130 lines (107 loc) · 6.4 KB
/
rector.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
<?php
declare(strict_types=1);
/*
* This file is part of the package thucke/timezones.
*
* For the full copyright and license information, please read the
* LICENSE file that was distributed with this source code.
*/
use Rector\Core\Configuration\Option;
use Rector\Core\ValueObject\PhpVersion;
use Rector\Php55\Rector\String_\StringClassNameToClassConstantRector;
use Ssch\TYPO3Rector\Configuration\Typo3Option;
use Ssch\TYPO3Rector\FileProcessor\Composer\Rector\ExtensionComposerRector;
use Ssch\TYPO3Rector\FileProcessor\TypoScript\Rector\ExtbasePersistenceTypoScriptRector;
use Ssch\TYPO3Rector\FileProcessor\TypoScript\Rector\FileIncludeToImportStatementTypoScriptRector;
use Ssch\TYPO3Rector\Rector\General\ConvertImplicitVariablesToExplicitGlobalsRector;
use Ssch\TYPO3Rector\Rector\General\ExtEmConfRector;
use Ssch\TYPO3Rector\Rector\v9\v0\InjectAnnotationRector;
use Ssch\TYPO3Rector\Set\Typo3LevelSetList;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
return static function (ContainerConfigurator $containerConfigurator): void {
$parameters = $containerConfigurator->parameters();
$containerConfigurator->import(Typo3LevelSetList::UP_TO_TYPO3_11);
// In order to have a better analysis from phpstan we teach it here some more things
$parameters->set(Option::PHPSTAN_FOR_RECTOR_PATH, Typo3Option::PHPSTAN_FOR_RECTOR_PATH);
// FQN classes are not imported by default. If you don't do it manually after every Rector run, enable it by:
$parameters->set(Option::AUTO_IMPORT_NAMES, true);
// this will not import root namespace classes, like \DateTime or \Exception
$parameters->set(Option::IMPORT_SHORT_CLASSES, false);
// this will not import classes used in PHP DocBlocks, like in /** @var \Some\Class */
$parameters->set(Option::IMPORT_DOC_BLOCKS, false);
// Define your target version which you want to support
//TODO raise to 74 after dropping support for PHP 7.3
$parameters->set(Option::PHP_VERSION_FEATURES, PhpVersion::PHP_73);
// If you have an editorconfig and changed files should keep their format enable it here
// $parameters->set(Option::ENABLE_EDITORCONFIG, true);
// If you only want to process one/some TYPO3 extension(s), you can specify its path(s) here.
// If you use the option --config change __DIR__ to getcwd()
// $parameters->set(Option::PATHS, [
// __DIR__ . '/packages/acme_demo/',
// ]);
// If you use the option --config change __DIR__ to getcwd()
$parameters->set(Option::SKIP, [
// @see https://github.com/sabbelasichon/typo3-rector/issues/2536
__DIR__ . '/**/Configuration/ExtensionBuilder/*',
// We skip those directories on purpose as there might be node_modules or similar
// that include typescript which would result in false positive processing
__DIR__ . '/**/Resources/**/node_modules/*',
__DIR__ . '/**/Resources/**/NodeModules/*',
__DIR__ . '/**/Resources/**/BowerComponents/*',
__DIR__ . '/**/Resources/**/bower_components/*',
__DIR__ . '/**/Resources/**/build/*',
__DIR__ . '/vendor/*',
__DIR__ . '/Build/*',
__DIR__ . '/public/*',
__DIR__ . '/.github/*',
__DIR__ . '/.Build/*',
__DIR__ . '/.ddev/*',
__DIR__ . '/.git/*',
]);
// This is used by the class \Ssch\TYPO3Rector\Rector\PostRector\FullQualifiedNamePostRector to force FQN in this paths and files
$parameters->set(Typo3Option::PATHS_FULL_QUALIFIED_NAMESPACES, [
// If you are targeting TYPO3 Version 11 use can now use Short namespace
// @see namespace https://docs.typo3.org/m/typo3/reference-coreapi/master/en-us/ExtensionArchitecture/ConfigurationFiles/Index.html
'ext_localconf.php',
'ext_tables.php',
'ClassAliasMap.php',
__DIR__ . '/**/Configuration/*.php',
__DIR__ . '/**/Configuration/**/*.php',
]);
// If you have trouble that rector cannot run because some TYPO3 constants are not defined add an additional constants file
// @see https://github.com/sabbelasichon/typo3-rector/blob/master/typo3.constants.php
// @see https://github.com/rectorphp/rector/blob/main/docs/static_reflection_and_autoload.md#include-files
// $parameters->set(Option::BOOTSTRAP_FILES, [
// __DIR__ . '/typo3.constants.php'
// ]);
// get services (needed for register a single rule)
$services = $containerConfigurator->services();
// register a single rule
// $services->set(InjectAnnotationRector::class);
/**
* Useful rule from RectorPHP itself to transform i.e. GeneralUtility::makeInstance('TYPO3\CMS\Core\Log\LogManager')
* to GeneralUtility::makeInstance(\TYPO3\CMS\Core\Log\LogManager::class) calls.
* But be warned, sometimes it produces false positives (edge cases), so watch out
*/
// $services->set(StringClassNameToClassConstantRector::class);
// Optional non-php file functionalities:
// @see https://github.com/sabbelasichon/typo3-rector/blob/main/docs/beyond_php_file_processors.md
// Adapt your composer.json dependencies to the latest available version for the defined SetList
// $containerConfigurator->import(Typo3SetList::COMPOSER_PACKAGES_104_CORE);
// $containerConfigurator->import(Typo3SetList::COMPOSER_PACKAGES_104_EXTENSIONS);
// Rewrite your extbase persistence class mapping from typoscript into php according to official docs.
// This processor will create a summarized file with all of the typoscript rewrites combined into a single file.
// The filename can be passed as argument, "Configuration_Extbase_Persistence_Classes.php" is default.
$services->set(ExtbasePersistenceTypoScriptRector::class)
->call('configure', [[ExtbasePersistenceTypoScriptRector::FILENAME => 'Configuration/Extbase/Persistence/Classes.php']]);
// Add some general TYPO3 rules
$services->set(ConvertImplicitVariablesToExplicitGlobalsRector::class);
$services->set(ExtEmConfRector::class)->configure([
ExtEmConfRector::ADDITIONAL_VALUES_TO_BE_REMOVED => [],
]);
$services->set(ExtensionComposerRector::class)->configure([
ExtensionComposerRector::TYPO3_VERSION_CONSTRAINT => '^9.5 || ^10.4 || ^11.5',
]);
// Do you want to modernize your TypoScript include statements for files and move from <INCLUDE /> to @import use the FileIncludeToImportStatementVisitor
// $services->set(FileIncludeToImportStatementTypoScriptRector::class);
};