xref: /dokuwiki/_test/rector.php (revision 80d854030a338fd60c2d6967dc10dd113ab16d40)
1077b7fe2SAndreas Gohr<?php
2077b7fe2SAndreas Gohr
3077b7fe2SAndreas Gohrdeclare(strict_types=1);
4077b7fe2SAndreas Gohr
5f9a94e78SAndreas Gohruse dokuwiki\test\rector\DokuWikiPtlnRector;
626dfc232SAndreas Gohruse dokuwiki\test\rector\DokuWikiRenamePrintToEcho;
7077b7fe2SAndreas Gohruse Rector\Caching\ValueObject\Storage\FileCacheStorage;
8077b7fe2SAndreas Gohruse Rector\CodeQuality\Rector\Array_\CallableThisArrayToAnonymousFunctionRector;
9e2d055f5SAndreas Gohruse Rector\CodeQuality\Rector\Concat\JoinStringConcatRector;
10077b7fe2SAndreas Gohruse Rector\CodeQuality\Rector\FunctionLike\SimplifyUselessVariableRector;
11077b7fe2SAndreas Gohruse Rector\CodeQuality\Rector\If_\CombineIfRector;
12077b7fe2SAndreas Gohruse Rector\CodeQuality\Rector\If_\ExplicitBoolCompareRector;
13077b7fe2SAndreas Gohruse Rector\CodeQuality\Rector\If_\SimplifyIfElseToTernaryRector;
141490c177SAndreas Gohruse Rector\CodeQuality\Rector\If_\SimplifyIfReturnBoolRector;
15077b7fe2SAndreas Gohruse Rector\CodeQuality\Rector\Isset_\IssetOnPropertyObjectToPropertyExistsRector;
16077b7fe2SAndreas Gohruse Rector\CodingStyle\Rector\Catch_\CatchExceptionNameMatchingTypeRector;
17104a3b7cSAndreas Gohruse Rector\CodingStyle\Rector\Class_\AddArrayDefaultToArrayPropertyRector;
18077b7fe2SAndreas Gohruse Rector\CodingStyle\Rector\Closure\StaticClosureRector;
19077b7fe2SAndreas Gohruse Rector\CodingStyle\Rector\Encapsed\EncapsedStringsToSprintfRector;
206723156fSAndreas Gohruse Rector\CodingStyle\Rector\Encapsed\WrapEncapsedVariableInCurlyBracesRector;
21a469bafbSAndreas Gohruse Rector\CodingStyle\Rector\FuncCall\StrictArraySearchRector;
22077b7fe2SAndreas Gohruse Rector\CodingStyle\Rector\PostInc\PostIncDecToPreIncDecRector;
23077b7fe2SAndreas Gohruse Rector\CodingStyle\Rector\Stmt\NewlineAfterStatementRector;
24077b7fe2SAndreas Gohruse Rector\CodingStyle\Rector\String_\SymplifyQuoteEscapeRector;
25077b7fe2SAndreas Gohruse Rector\Config\RectorConfig;
26077b7fe2SAndreas Gohruse Rector\DeadCode\Rector\ClassMethod\RemoveUselessParamTagRector;
2724870174SAndreas Gohruse Rector\DeadCode\Rector\If_\RemoveAlwaysTrueIfConditionRector;
28bcaec9f4SAndreas Gohruse Rector\DeadCode\Rector\If_\RemoveUnusedNonEmptyArrayBeforeForeachRector;
29104a3b7cSAndreas Gohruse Rector\DeadCode\Rector\Property\RemoveUselessVarTagRector;
306723156fSAndreas Gohruse Rector\DeadCode\Rector\StaticCall\RemoveParentCallWithoutParentRector;
3124870174SAndreas Gohruse Rector\DeadCode\Rector\Stmt\RemoveUnreachableStatementRector;
320603e565SAndreas Gohruse Rector\Php71\Rector\FuncCall\CountOnNullRector;
336e695190SAndreas Gohruse Rector\Php71\Rector\FuncCall\RemoveExtraParametersRector;
34*80d85403SAndreas Gohruse Rector\Php80\Rector\Identical\StrEndsWithRector;
35*80d85403SAndreas Gohruse Rector\Php80\Rector\Identical\StrStartsWithRector;
36*80d85403SAndreas Gohruse Rector\Php80\Rector\NotIdentical\StrContainsRector;
37a0aeafaaSAndreas Gohruse Rector\Renaming\Rector\FuncCall\RenameFunctionRector;
38a0aeafaaSAndreas Gohruse Rector\Renaming\Rector\Name\RenameClassRector;
39077b7fe2SAndreas Gohruse Rector\Set\ValueObject\LevelSetList;
40077b7fe2SAndreas Gohruse Rector\Set\ValueObject\SetList;
41077b7fe2SAndreas Gohruse Rector\Strict\Rector\Empty_\DisallowedEmptyRuleFixerRector;
42104a3b7cSAndreas Gohruse Rector\TypeDeclaration\Rector\Property\TypedPropertyFromAssignsRector;
43077b7fe2SAndreas Gohr
44077b7fe2SAndreas Gohrreturn static function (RectorConfig $rectorConfig): void {
45f9a94e78SAndreas Gohr    // FIXME we may want to autoload these later
46f9a94e78SAndreas Gohr    require_once __DIR__ . '/rector/DokuWikiPtlnRector.php';
4726dfc232SAndreas Gohr    require_once __DIR__ . '/rector/DokuWikiRenamePrintToEcho.php';
48f9a94e78SAndreas Gohr
49077b7fe2SAndreas Gohr    $rectorConfig->paths([
50b1f206e1SAndreas Gohr        __DIR__ . '/../inc/',
51b1f206e1SAndreas Gohr        __DIR__ . '/../lib/',
52b1f206e1SAndreas Gohr        __DIR__ . '/../bin/',
53b1f206e1SAndreas Gohr        __DIR__ . '/../*.php',
54077b7fe2SAndreas Gohr    ]);
55077b7fe2SAndreas Gohr
561490c177SAndreas Gohr    $rectorConfig->bootstrapFiles([
5724870174SAndreas Gohr        __DIR__ . '/../inc/init.php',
581490c177SAndreas Gohr    ]);
591490c177SAndreas Gohr
60077b7fe2SAndreas Gohr    $rectorConfig->importNames();
61077b7fe2SAndreas Gohr    $rectorConfig->importShortClasses(false);
62077b7fe2SAndreas Gohr    $rectorConfig->cacheClass(FileCacheStorage::class);
63077b7fe2SAndreas Gohr    $rectorConfig->cacheDirectory(__DIR__ . '/.rector-cache');
64077b7fe2SAndreas Gohr
65077b7fe2SAndreas Gohr    // define sets of rules
66077b7fe2SAndreas Gohr    $rectorConfig->sets([
67077b7fe2SAndreas Gohr        LevelSetList::UP_TO_PHP_74,
68077b7fe2SAndreas Gohr        SetList::CODE_QUALITY,
69077b7fe2SAndreas Gohr        SetList::DEAD_CODE,
70077b7fe2SAndreas Gohr        SetList::CODING_STYLE,
71077b7fe2SAndreas Gohr    ]);
72077b7fe2SAndreas Gohr
73*80d85403SAndreas Gohr    // future rules for which we have polyfills
74*80d85403SAndreas Gohr    $rectorConfig->rule(StrContainsRector::class);
75*80d85403SAndreas Gohr    $rectorConfig->rule(StrEndsWithRector::class);
76*80d85403SAndreas Gohr    $rectorConfig->rule(StrStartsWithRector::class);
77*80d85403SAndreas Gohr
78077b7fe2SAndreas Gohr    $rectorConfig->skip([
79077b7fe2SAndreas Gohr        // skip paths
80077b7fe2SAndreas Gohr        __DIR__ . '/../inc/lang/*',
81077b7fe2SAndreas Gohr        __DIR__ . '/../lib/plugins/*/_test/*',
82077b7fe2SAndreas Gohr        __DIR__ . '/../lib/tpl/*/_test/*',
83077b7fe2SAndreas Gohr        __DIR__ . '/../lib/plugins/*/lang/*',
84077b7fe2SAndreas Gohr        __DIR__ . '/../lib/tpl/*/lang/*',
85467c1427SAndreas Gohr        __DIR__ . '/../lib/plugins/*/conf/*', // maybe later
86467c1427SAndreas Gohr        __DIR__ . '/../lib/tpl/*/conf/*',  // maybe later
87077b7fe2SAndreas Gohr        __DIR__ . '/../lib/plugins/*/vendor/*',
88077b7fe2SAndreas Gohr        __DIR__ . '/../lib/tpl/*/vendor/*',
89077b7fe2SAndreas Gohr        __DIR__ . '/../lib/plugins/*/skel/*', // dev plugin
9024870174SAndreas Gohr        __DIR__ . '/../inc/deprecated.php',
9124870174SAndreas Gohr        __DIR__ . '/../inc/form.php',
92077b7fe2SAndreas Gohr
93077b7fe2SAndreas Gohr        // third party libs, not yet moved to composer
94077b7fe2SAndreas Gohr        __DIR__ . '/../inc/DifferenceEngine.php',
95077b7fe2SAndreas Gohr        __DIR__ . '/../inc/JpegMeta.php',
96077b7fe2SAndreas Gohr        __DIR__ . '/../lib/plugins/authad/adLDAP',
97077b7fe2SAndreas Gohr
98077b7fe2SAndreas Gohr        // skip rules
99077b7fe2SAndreas Gohr        SimplifyIfElseToTernaryRector::class,
100077b7fe2SAndreas Gohr        NewlineAfterStatementRector::class,
101077b7fe2SAndreas Gohr        CombineIfRector::class,
102077b7fe2SAndreas Gohr        ExplicitBoolCompareRector::class,
103077b7fe2SAndreas Gohr        IssetOnPropertyObjectToPropertyExistsRector::class, // maybe?
104077b7fe2SAndreas Gohr        SymplifyQuoteEscapeRector::class,
105077b7fe2SAndreas Gohr        CatchExceptionNameMatchingTypeRector::class,
106077b7fe2SAndreas Gohr        EncapsedStringsToSprintfRector::class,
107077b7fe2SAndreas Gohr        CallableThisArrayToAnonymousFunctionRector::class,
108077b7fe2SAndreas Gohr        StaticClosureRector::class,
109077b7fe2SAndreas Gohr        SimplifyUselessVariableRector::class, // seems to strip constructor property initializations
110077b7fe2SAndreas Gohr        PostIncDecToPreIncDecRector::class,
111077b7fe2SAndreas Gohr        RemoveUselessParamTagRector::class,
112077b7fe2SAndreas Gohr        DisallowedEmptyRuleFixerRector::class,
1130603e565SAndreas Gohr        CountOnNullRector::class, // adds unwanted is_countable checks?
1146723156fSAndreas Gohr        RemoveParentCallWithoutParentRector::class,
1156723156fSAndreas Gohr        WrapEncapsedVariableInCurlyBracesRector::class,
1161490c177SAndreas Gohr        SimplifyIfReturnBoolRector::class,
117a469bafbSAndreas Gohr        StrictArraySearchRector::class, // we cannot assume strict search is always wanted
118104a3b7cSAndreas Gohr        AddArrayDefaultToArrayPropertyRector::class, // may break code differentiating between null and empty array
119104a3b7cSAndreas Gohr        RemoveUselessVarTagRector::class,
120104a3b7cSAndreas Gohr        TypedPropertyFromAssignsRector::class, // maybe?
121e2d055f5SAndreas Gohr        JoinStringConcatRector::class, // this does not count variables, so it creates overlong lines
1226e695190SAndreas Gohr        RemoveExtraParametersRector::class, // this actually broke code
123bcaec9f4SAndreas Gohr        RemoveUnusedNonEmptyArrayBeforeForeachRector::class, // seems unreliable when checking on array keys
12424870174SAndreas Gohr        RemoveAlwaysTrueIfConditionRector::class, // fails with if(defined(...)) constructs
125ab9790caSAndreas Gohr        RemoveUnreachableStatementRector::class, // fails GOTO in authpdo -> should be rewritten with exceptions
126077b7fe2SAndreas Gohr    ]);
127a0aeafaaSAndreas Gohr
128a0aeafaaSAndreas Gohr    $rectorConfig->ruleWithConfiguration(RenameClassRector::class, [
129a0aeafaaSAndreas Gohr        // see inc/deprecated.php
130a0aeafaaSAndreas Gohr        'RemoteAccessDeniedException' => 'dokuwiki\Remote\AccessDeniedException',
131a0aeafaaSAndreas Gohr        'RemoteException' => 'dokuwiki\Remote\RemoteException',
132a0aeafaaSAndreas Gohr        'setting' => 'dokuwiki\plugin\config\core\Setting\Setting',
133a0aeafaaSAndreas Gohr        'setting_authtype' => 'dokuwiki\plugin\config\core\Setting\SettingAuthtype',
134a0aeafaaSAndreas Gohr        'setting_string' => 'dokuwiki\plugin\config\core\Setting\SettingString',
135a0aeafaaSAndreas Gohr        'PageChangelog' => 'dokuwiki\ChangeLog\PageChangeLog',
136a0aeafaaSAndreas Gohr        'MediaChangelog' => 'dokuwiki\ChangeLog\MediaChangeLog',
137a0aeafaaSAndreas Gohr        'Input' => 'dokuwiki\Input\Input',
138a0aeafaaSAndreas Gohr        'PostInput' => 'dokuwiki\Input\Post',
139a0aeafaaSAndreas Gohr        'GetInput' => 'dokuwiki\Input\Get',
140a0aeafaaSAndreas Gohr        'ServerInput' => 'dokuwiki\Input\Server',
141a0aeafaaSAndreas Gohr        'PassHash' => 'dokuwiki\PassHash',
142a0aeafaaSAndreas Gohr        'HTTPClientException' => 'dokuwiki\HTTP\HTTPClientException',
143a0aeafaaSAndreas Gohr        'HTTPClient' => 'dokuwiki\HTTP\HTTPClient',
144a0aeafaaSAndreas Gohr        'DokuHTTPClient' => 'dokuwiki\HTTP\DokuHTTPClient',
145a0aeafaaSAndreas Gohr        'Doku_Plugin_Controller' => 'dokuwiki\Extension\PluginController',
146a0aeafaaSAndreas Gohr        'Doku_Indexer' => 'dokuwiki\Search\Indexer',
147a0aeafaaSAndreas Gohr        'IXR_Client' => 'dokuwiki\Remote\IXR\Client',
148a0aeafaaSAndreas Gohr        'IXR_ClientMulticall' => 'IXR\Client\ClientMulticall',
149a0aeafaaSAndreas Gohr        'IXR_Server' => 'IXR\Server\Server',
150a0aeafaaSAndreas Gohr        'IXR_IntrospectionServer' => 'IXR\Server\IntrospectionServer',
151a0aeafaaSAndreas Gohr        'IXR_Request' => 'IXR\Request\Request',
152a0aeafaaSAndreas Gohr        'IXR_Message' => 'R\Message\Message',
153a0aeafaaSAndreas Gohr        'IXR_Error' => 'XR\Message\Error',
154a0aeafaaSAndreas Gohr        'IXR_Date' => 'IXR\DataType\Date',
155a0aeafaaSAndreas Gohr        'IXR_Base64' => 'IXR\DataType\Base64',
156a0aeafaaSAndreas Gohr        'IXR_Value' => 'IXR\DataType\Value',
157a0aeafaaSAndreas Gohr
158a0aeafaaSAndreas Gohr        // see inc/legacy.php
159a0aeafaaSAndreas Gohr        'Doku_Event_Handler' => 'dokuwiki\Extension\EventHandler',
160a0aeafaaSAndreas Gohr        'Doku_Event' => 'dokuwiki\Extension\Event',
161a0aeafaaSAndreas Gohr        'DokuWiki_Action_Plugin' => 'dokuwiki\Extension\ActionPlugin',
162a0aeafaaSAndreas Gohr        'DokuWiki_Admin_Plugin' => 'dokuwiki\Extension\AdminPlugin',
163a0aeafaaSAndreas Gohr        'DokuWiki_Auth_Plugin' => 'dokuwiki\Extension\AuthPlugin',
164a0aeafaaSAndreas Gohr        'DokuWiki_CLI_Plugin' => 'dokuwiki\Extension\CLIPlugin',
165a0aeafaaSAndreas Gohr        'DokuWiki_Plugin' => 'dokuwiki\Extension\Plugin',
166a0aeafaaSAndreas Gohr        'DokuWiki_Remote_Plugin' => 'dokuwiki\Extension\RemotePlugin',
167a0aeafaaSAndreas Gohr        'DokuWiki_Syntax_Plugin' => 'dokuwiki\Extension\SyntaxPlugin',
168a0aeafaaSAndreas Gohr    ]);
169a0aeafaaSAndreas Gohr
170a0aeafaaSAndreas Gohr    $rectorConfig->ruleWithConfiguration(RenameFunctionRector::class, [
171a0aeafaaSAndreas Gohr        // see inc/deprecated.php
172a0aeafaaSAndreas Gohr        'Doku_Lexer_Escape' => 'dokuwiki\Parsing\Lexer\Lexer::escape',
173a0aeafaaSAndreas Gohr
174a0aeafaaSAndreas Gohr        // see inc/utf8.php
175a0aeafaaSAndreas Gohr        'utf8_isASCII' => 'dokuwiki\Utf8\Clean::isASCII',
176a0aeafaaSAndreas Gohr        'utf8_strip' => 'dokuwiki\Utf8\Clean::strip',
177a0aeafaaSAndreas Gohr        'utf8_check' => 'dokuwiki\Utf8\Clean::isUtf8',
178a0aeafaaSAndreas Gohr        'utf8_basename' => 'dokuwiki\Utf8\PhpString::basename',
179a0aeafaaSAndreas Gohr        'utf8_strlen' => 'dokuwiki\Utf8\PhpString::strlen',
180a0aeafaaSAndreas Gohr        'utf8_substr' => 'dokuwiki\Utf8\PhpString::substr',
181a0aeafaaSAndreas Gohr        'utf8_substr_replace' => 'dokuwiki\Utf8\PhpString::substr_replace',
182a0aeafaaSAndreas Gohr        'utf8_ltrim' => 'dokuwiki\Utf8\PhpString::ltrim',
183a0aeafaaSAndreas Gohr        'utf8_rtrim' => 'dokuwiki\Utf8\PhpString::rtrim',
184a0aeafaaSAndreas Gohr        'utf8_trim' => 'dokuwiki\Utf8\PhpString::trim',
185a0aeafaaSAndreas Gohr        'utf8_strtolower' => 'dokuwiki\Utf8\PhpString::strtolower',
186a0aeafaaSAndreas Gohr        'utf8_strtoupper' => 'dokuwiki\Utf8\PhpString::strtoupper',
187a0aeafaaSAndreas Gohr        'utf8_ucfirst' => 'dokuwiki\Utf8\PhpString::ucfirst',
188a0aeafaaSAndreas Gohr        'utf8_ucwords' => 'dokuwiki\Utf8\PhpString::ucwords',
189a0aeafaaSAndreas Gohr        'utf8_deaccent' => 'dokuwiki\Utf8\Clean::deaccent',
190a0aeafaaSAndreas Gohr        'utf8_romanize' => 'dokuwiki\Utf8\Clean::romanize',
191a0aeafaaSAndreas Gohr        'utf8_stripspecials' => 'dokuwiki\Utf8\Clean::stripspecials',
192a0aeafaaSAndreas Gohr        'utf8_strpos' => 'dokuwiki\Utf8\PhpString::strpos',
193a0aeafaaSAndreas Gohr        'utf8_tohtml' => 'dokuwiki\Utf8\Conversion::toHtml',
194a0aeafaaSAndreas Gohr        'utf8_unhtml' => 'dokuwiki\Utf8\Conversion::fromHtml',
195a0aeafaaSAndreas Gohr        'utf8_to_unicode' => 'dokuwiki\Utf8\Conversion::fromUtf8',
196a0aeafaaSAndreas Gohr        'unicode_to_utf8' => 'dokuwiki\Utf8\Conversion::toUtf8',
197a0aeafaaSAndreas Gohr        'utf8_to_utf16be' => 'dokuwiki\Utf8\Conversion::toUtf16be',
198a0aeafaaSAndreas Gohr        'utf16be_to_utf8' => 'dokuwiki\Utf8\Conversion::fromUtf16be',
199a0aeafaaSAndreas Gohr        'utf8_bad_replace' => 'dokuwiki\Utf8\Clean::replaceBadBytes',
200a0aeafaaSAndreas Gohr        'utf8_correctIdx' => 'dokuwiki\Utf8\Clean::correctIdx',
201a0aeafaaSAndreas Gohr    ]);
202f9a94e78SAndreas Gohr
203f9a94e78SAndreas Gohr    $rectorConfig->rule(DokuWikiPtlnRector::class);
20426dfc232SAndreas Gohr    $rectorConfig->rule(DokuWikiRenamePrintToEcho::class);
205077b7fe2SAndreas Gohr};
206