xref: /dokuwiki/_test/rector.php (revision f9a94e78392d6a178b0e7f29a005688fc44e5cc3)
1077b7fe2SAndreas Gohr<?php
2077b7fe2SAndreas Gohr
3077b7fe2SAndreas Gohrdeclare(strict_types=1);
4077b7fe2SAndreas Gohr
5*f9a94e78SAndreas Gohruse dokuwiki\test\rector\DokuWikiPtlnRector;
6077b7fe2SAndreas Gohruse Rector\Caching\ValueObject\Storage\FileCacheStorage;
7077b7fe2SAndreas Gohruse Rector\CodeQuality\Rector\Array_\CallableThisArrayToAnonymousFunctionRector;
8e2d055f5SAndreas Gohruse Rector\CodeQuality\Rector\Concat\JoinStringConcatRector;
9077b7fe2SAndreas Gohruse Rector\CodeQuality\Rector\FunctionLike\SimplifyUselessVariableRector;
10077b7fe2SAndreas Gohruse Rector\CodeQuality\Rector\If_\CombineIfRector;
11077b7fe2SAndreas Gohruse Rector\CodeQuality\Rector\If_\ExplicitBoolCompareRector;
12077b7fe2SAndreas Gohruse Rector\CodeQuality\Rector\If_\SimplifyIfElseToTernaryRector;
131490c177SAndreas Gohruse Rector\CodeQuality\Rector\If_\SimplifyIfReturnBoolRector;
14077b7fe2SAndreas Gohruse Rector\CodeQuality\Rector\Isset_\IssetOnPropertyObjectToPropertyExistsRector;
15077b7fe2SAndreas Gohruse Rector\CodingStyle\Rector\Catch_\CatchExceptionNameMatchingTypeRector;
16104a3b7cSAndreas Gohruse Rector\CodingStyle\Rector\Class_\AddArrayDefaultToArrayPropertyRector;
17077b7fe2SAndreas Gohruse Rector\CodingStyle\Rector\Closure\StaticClosureRector;
18077b7fe2SAndreas Gohruse Rector\CodingStyle\Rector\Encapsed\EncapsedStringsToSprintfRector;
196723156fSAndreas Gohruse Rector\CodingStyle\Rector\Encapsed\WrapEncapsedVariableInCurlyBracesRector;
20a469bafbSAndreas Gohruse Rector\CodingStyle\Rector\FuncCall\StrictArraySearchRector;
21077b7fe2SAndreas Gohruse Rector\CodingStyle\Rector\PostInc\PostIncDecToPreIncDecRector;
22077b7fe2SAndreas Gohruse Rector\CodingStyle\Rector\Stmt\NewlineAfterStatementRector;
23077b7fe2SAndreas Gohruse Rector\CodingStyle\Rector\String_\SymplifyQuoteEscapeRector;
24077b7fe2SAndreas Gohruse Rector\Config\RectorConfig;
25077b7fe2SAndreas Gohruse Rector\DeadCode\Rector\ClassMethod\RemoveUselessParamTagRector;
2624870174SAndreas Gohruse Rector\DeadCode\Rector\If_\RemoveAlwaysTrueIfConditionRector;
27bcaec9f4SAndreas Gohruse Rector\DeadCode\Rector\If_\RemoveUnusedNonEmptyArrayBeforeForeachRector;
28104a3b7cSAndreas Gohruse Rector\DeadCode\Rector\Property\RemoveUselessVarTagRector;
296723156fSAndreas Gohruse Rector\DeadCode\Rector\StaticCall\RemoveParentCallWithoutParentRector;
3024870174SAndreas Gohruse Rector\DeadCode\Rector\Stmt\RemoveUnreachableStatementRector;
310603e565SAndreas Gohruse Rector\Php71\Rector\FuncCall\CountOnNullRector;
326e695190SAndreas Gohruse Rector\Php71\Rector\FuncCall\RemoveExtraParametersRector;
33a0aeafaaSAndreas Gohruse Rector\Renaming\Rector\FuncCall\RenameFunctionRector;
34a0aeafaaSAndreas Gohruse Rector\Renaming\Rector\Name\RenameClassRector;
35077b7fe2SAndreas Gohruse Rector\Set\ValueObject\LevelSetList;
36077b7fe2SAndreas Gohruse Rector\Set\ValueObject\SetList;
37077b7fe2SAndreas Gohruse Rector\Strict\Rector\Empty_\DisallowedEmptyRuleFixerRector;
38104a3b7cSAndreas Gohruse Rector\TypeDeclaration\Rector\Property\TypedPropertyFromAssignsRector;
39077b7fe2SAndreas Gohr
40077b7fe2SAndreas Gohrreturn static function (RectorConfig $rectorConfig): void {
41*f9a94e78SAndreas Gohr    // FIXME we may want to autoload these later
42*f9a94e78SAndreas Gohr    require_once __DIR__ . '/rector/DokuWikiPtlnRector.php';
43*f9a94e78SAndreas Gohr
44077b7fe2SAndreas Gohr    $rectorConfig->paths([
45b1f206e1SAndreas Gohr        __DIR__ . '/../inc/',
46b1f206e1SAndreas Gohr        __DIR__ . '/../lib/',
47b1f206e1SAndreas Gohr        __DIR__ . '/../bin/',
48b1f206e1SAndreas Gohr        __DIR__ . '/../*.php',
49077b7fe2SAndreas Gohr    ]);
50077b7fe2SAndreas Gohr
511490c177SAndreas Gohr    $rectorConfig->bootstrapFiles([
5224870174SAndreas Gohr        __DIR__ . '/../inc/init.php',
531490c177SAndreas Gohr    ]);
541490c177SAndreas Gohr
55077b7fe2SAndreas Gohr    $rectorConfig->importNames();
56077b7fe2SAndreas Gohr    $rectorConfig->importShortClasses(false);
57077b7fe2SAndreas Gohr    $rectorConfig->cacheClass(FileCacheStorage::class);
58077b7fe2SAndreas Gohr    $rectorConfig->cacheDirectory(__DIR__ . '/.rector-cache');
59077b7fe2SAndreas Gohr
60077b7fe2SAndreas Gohr    // define sets of rules
61077b7fe2SAndreas Gohr    $rectorConfig->sets([
62077b7fe2SAndreas Gohr        LevelSetList::UP_TO_PHP_74,
63077b7fe2SAndreas Gohr        SetList::CODE_QUALITY,
64077b7fe2SAndreas Gohr        SetList::DEAD_CODE,
65077b7fe2SAndreas Gohr        SetList::CODING_STYLE,
66077b7fe2SAndreas Gohr    ]);
67077b7fe2SAndreas Gohr
68077b7fe2SAndreas Gohr    $rectorConfig->skip([
69077b7fe2SAndreas Gohr        // skip paths
70077b7fe2SAndreas Gohr        __DIR__ . '/../inc/lang/*',
71077b7fe2SAndreas Gohr        __DIR__ . '/../lib/plugins/*/_test/*',
72077b7fe2SAndreas Gohr        __DIR__ . '/../lib/tpl/*/_test/*',
73077b7fe2SAndreas Gohr        __DIR__ . '/../lib/plugins/*/lang/*',
74077b7fe2SAndreas Gohr        __DIR__ . '/../lib/tpl/*/lang/*',
75467c1427SAndreas Gohr        __DIR__ . '/../lib/plugins/*/conf/*', // maybe later
76467c1427SAndreas Gohr        __DIR__ . '/../lib/tpl/*/conf/*',  // maybe later
77077b7fe2SAndreas Gohr        __DIR__ . '/../lib/plugins/*/vendor/*',
78077b7fe2SAndreas Gohr        __DIR__ . '/../lib/tpl/*/vendor/*',
79077b7fe2SAndreas Gohr        __DIR__ . '/../lib/plugins/*/skel/*', // dev plugin
8024870174SAndreas Gohr        __DIR__ . '/../inc/deprecated.php',
8124870174SAndreas Gohr        __DIR__ . '/../inc/form.php',
82077b7fe2SAndreas Gohr
83077b7fe2SAndreas Gohr        // third party libs, not yet moved to composer
84077b7fe2SAndreas Gohr        __DIR__ . '/../inc/DifferenceEngine.php',
85077b7fe2SAndreas Gohr        __DIR__ . '/../inc/JpegMeta.php',
86077b7fe2SAndreas Gohr        __DIR__ . '/../lib/plugins/authad/adLDAP',
87077b7fe2SAndreas Gohr
88077b7fe2SAndreas Gohr        // skip rules
89077b7fe2SAndreas Gohr        SimplifyIfElseToTernaryRector::class,
90077b7fe2SAndreas Gohr        NewlineAfterStatementRector::class,
91077b7fe2SAndreas Gohr        CombineIfRector::class,
92077b7fe2SAndreas Gohr        ExplicitBoolCompareRector::class,
93077b7fe2SAndreas Gohr        IssetOnPropertyObjectToPropertyExistsRector::class, // maybe?
94077b7fe2SAndreas Gohr        SymplifyQuoteEscapeRector::class,
95077b7fe2SAndreas Gohr        CatchExceptionNameMatchingTypeRector::class,
96077b7fe2SAndreas Gohr        EncapsedStringsToSprintfRector::class,
97077b7fe2SAndreas Gohr        CallableThisArrayToAnonymousFunctionRector::class,
98077b7fe2SAndreas Gohr        StaticClosureRector::class,
99077b7fe2SAndreas Gohr        SimplifyUselessVariableRector::class, // seems to strip constructor property initializations
100077b7fe2SAndreas Gohr        PostIncDecToPreIncDecRector::class,
101077b7fe2SAndreas Gohr        RemoveUselessParamTagRector::class,
102077b7fe2SAndreas Gohr        DisallowedEmptyRuleFixerRector::class,
1030603e565SAndreas Gohr        CountOnNullRector::class, // adds unwanted is_countable checks?
1046723156fSAndreas Gohr        RemoveParentCallWithoutParentRector::class,
1056723156fSAndreas Gohr        WrapEncapsedVariableInCurlyBracesRector::class,
1061490c177SAndreas Gohr        SimplifyIfReturnBoolRector::class,
107a469bafbSAndreas Gohr        StrictArraySearchRector::class, // we cannot assume strict search is always wanted
108104a3b7cSAndreas Gohr        AddArrayDefaultToArrayPropertyRector::class, // may break code differentiating between null and empty array
109104a3b7cSAndreas Gohr        RemoveUselessVarTagRector::class,
110104a3b7cSAndreas Gohr        TypedPropertyFromAssignsRector::class, // maybe?
111e2d055f5SAndreas Gohr        JoinStringConcatRector::class, // this does not count variables, so it creates overlong lines
1126e695190SAndreas Gohr        RemoveExtraParametersRector::class, // this actually broke code
113bcaec9f4SAndreas Gohr        RemoveUnusedNonEmptyArrayBeforeForeachRector::class, // seems unreliable when checking on array keys
11424870174SAndreas Gohr        RemoveAlwaysTrueIfConditionRector::class, // fails with if(defined(...)) constructs
115ab9790caSAndreas Gohr        RemoveUnreachableStatementRector::class, // fails GOTO in authpdo -> should be rewritten with exceptions
116077b7fe2SAndreas Gohr    ]);
117a0aeafaaSAndreas Gohr
118a0aeafaaSAndreas Gohr    $rectorConfig->ruleWithConfiguration(RenameClassRector::class, [
119a0aeafaaSAndreas Gohr        // see inc/deprecated.php
120a0aeafaaSAndreas Gohr        'RemoteAccessDeniedException' => 'dokuwiki\Remote\AccessDeniedException',
121a0aeafaaSAndreas Gohr        'RemoteException' => 'dokuwiki\Remote\RemoteException',
122a0aeafaaSAndreas Gohr        'setting' => 'dokuwiki\plugin\config\core\Setting\Setting',
123a0aeafaaSAndreas Gohr        'setting_authtype' => 'dokuwiki\plugin\config\core\Setting\SettingAuthtype',
124a0aeafaaSAndreas Gohr        'setting_string' => 'dokuwiki\plugin\config\core\Setting\SettingString',
125a0aeafaaSAndreas Gohr        'PageChangelog' => 'dokuwiki\ChangeLog\PageChangeLog',
126a0aeafaaSAndreas Gohr        'MediaChangelog' => 'dokuwiki\ChangeLog\MediaChangeLog',
127a0aeafaaSAndreas Gohr        'Input' => 'dokuwiki\Input\Input',
128a0aeafaaSAndreas Gohr        'PostInput' => 'dokuwiki\Input\Post',
129a0aeafaaSAndreas Gohr        'GetInput' => 'dokuwiki\Input\Get',
130a0aeafaaSAndreas Gohr        'ServerInput' => 'dokuwiki\Input\Server',
131a0aeafaaSAndreas Gohr        'PassHash' => 'dokuwiki\PassHash',
132a0aeafaaSAndreas Gohr        'HTTPClientException' => 'dokuwiki\HTTP\HTTPClientException',
133a0aeafaaSAndreas Gohr        'HTTPClient' => 'dokuwiki\HTTP\HTTPClient',
134a0aeafaaSAndreas Gohr        'DokuHTTPClient' => 'dokuwiki\HTTP\DokuHTTPClient',
135a0aeafaaSAndreas Gohr        'Doku_Plugin_Controller' => 'dokuwiki\Extension\PluginController',
136a0aeafaaSAndreas Gohr        'Doku_Indexer' => 'dokuwiki\Search\Indexer',
137a0aeafaaSAndreas Gohr        'IXR_Client' => 'dokuwiki\Remote\IXR\Client',
138a0aeafaaSAndreas Gohr        'IXR_ClientMulticall' => 'IXR\Client\ClientMulticall',
139a0aeafaaSAndreas Gohr        'IXR_Server' => 'IXR\Server\Server',
140a0aeafaaSAndreas Gohr        'IXR_IntrospectionServer' => 'IXR\Server\IntrospectionServer',
141a0aeafaaSAndreas Gohr        'IXR_Request' => 'IXR\Request\Request',
142a0aeafaaSAndreas Gohr        'IXR_Message' => 'R\Message\Message',
143a0aeafaaSAndreas Gohr        'IXR_Error' => 'XR\Message\Error',
144a0aeafaaSAndreas Gohr        'IXR_Date' => 'IXR\DataType\Date',
145a0aeafaaSAndreas Gohr        'IXR_Base64' => 'IXR\DataType\Base64',
146a0aeafaaSAndreas Gohr        'IXR_Value' => 'IXR\DataType\Value',
147a0aeafaaSAndreas Gohr
148a0aeafaaSAndreas Gohr        // see inc/legacy.php
149a0aeafaaSAndreas Gohr        'Doku_Event_Handler' => 'dokuwiki\Extension\EventHandler',
150a0aeafaaSAndreas Gohr        'Doku_Event' => 'dokuwiki\Extension\Event',
151a0aeafaaSAndreas Gohr        'DokuWiki_Action_Plugin' => 'dokuwiki\Extension\ActionPlugin',
152a0aeafaaSAndreas Gohr        'DokuWiki_Admin_Plugin' => 'dokuwiki\Extension\AdminPlugin',
153a0aeafaaSAndreas Gohr        'DokuWiki_Auth_Plugin' => 'dokuwiki\Extension\AuthPlugin',
154a0aeafaaSAndreas Gohr        'DokuWiki_CLI_Plugin' => 'dokuwiki\Extension\CLIPlugin',
155a0aeafaaSAndreas Gohr        'DokuWiki_Plugin' => 'dokuwiki\Extension\Plugin',
156a0aeafaaSAndreas Gohr        'DokuWiki_Remote_Plugin' => 'dokuwiki\Extension\RemotePlugin',
157a0aeafaaSAndreas Gohr        'DokuWiki_Syntax_Plugin' => 'dokuwiki\Extension\SyntaxPlugin',
158a0aeafaaSAndreas Gohr    ]);
159a0aeafaaSAndreas Gohr
160a0aeafaaSAndreas Gohr    $rectorConfig->ruleWithConfiguration(RenameFunctionRector::class, [
161a0aeafaaSAndreas Gohr        // see inc/deprecated.php
162a0aeafaaSAndreas Gohr        'Doku_Lexer_Escape' => 'dokuwiki\Parsing\Lexer\Lexer::escape',
163a0aeafaaSAndreas Gohr
164a0aeafaaSAndreas Gohr        // see inc/utf8.php
165a0aeafaaSAndreas Gohr        'utf8_isASCII' => 'dokuwiki\Utf8\Clean::isASCII',
166a0aeafaaSAndreas Gohr        'utf8_strip' => 'dokuwiki\Utf8\Clean::strip',
167a0aeafaaSAndreas Gohr        'utf8_check' => 'dokuwiki\Utf8\Clean::isUtf8',
168a0aeafaaSAndreas Gohr        'utf8_basename' => 'dokuwiki\Utf8\PhpString::basename',
169a0aeafaaSAndreas Gohr        'utf8_strlen' => 'dokuwiki\Utf8\PhpString::strlen',
170a0aeafaaSAndreas Gohr        'utf8_substr' => 'dokuwiki\Utf8\PhpString::substr',
171a0aeafaaSAndreas Gohr        'utf8_substr_replace' => 'dokuwiki\Utf8\PhpString::substr_replace',
172a0aeafaaSAndreas Gohr        'utf8_ltrim' => 'dokuwiki\Utf8\PhpString::ltrim',
173a0aeafaaSAndreas Gohr        'utf8_rtrim' => 'dokuwiki\Utf8\PhpString::rtrim',
174a0aeafaaSAndreas Gohr        'utf8_trim' => 'dokuwiki\Utf8\PhpString::trim',
175a0aeafaaSAndreas Gohr        'utf8_strtolower' => 'dokuwiki\Utf8\PhpString::strtolower',
176a0aeafaaSAndreas Gohr        'utf8_strtoupper' => 'dokuwiki\Utf8\PhpString::strtoupper',
177a0aeafaaSAndreas Gohr        'utf8_ucfirst' => 'dokuwiki\Utf8\PhpString::ucfirst',
178a0aeafaaSAndreas Gohr        'utf8_ucwords' => 'dokuwiki\Utf8\PhpString::ucwords',
179a0aeafaaSAndreas Gohr        'utf8_deaccent' => 'dokuwiki\Utf8\Clean::deaccent',
180a0aeafaaSAndreas Gohr        'utf8_romanize' => 'dokuwiki\Utf8\Clean::romanize',
181a0aeafaaSAndreas Gohr        'utf8_stripspecials' => 'dokuwiki\Utf8\Clean::stripspecials',
182a0aeafaaSAndreas Gohr        'utf8_strpos' => 'dokuwiki\Utf8\PhpString::strpos',
183a0aeafaaSAndreas Gohr        'utf8_tohtml' => 'dokuwiki\Utf8\Conversion::toHtml',
184a0aeafaaSAndreas Gohr        'utf8_unhtml' => 'dokuwiki\Utf8\Conversion::fromHtml',
185a0aeafaaSAndreas Gohr        'utf8_to_unicode' => 'dokuwiki\Utf8\Conversion::fromUtf8',
186a0aeafaaSAndreas Gohr        'unicode_to_utf8' => 'dokuwiki\Utf8\Conversion::toUtf8',
187a0aeafaaSAndreas Gohr        'utf8_to_utf16be' => 'dokuwiki\Utf8\Conversion::toUtf16be',
188a0aeafaaSAndreas Gohr        'utf16be_to_utf8' => 'dokuwiki\Utf8\Conversion::fromUtf16be',
189a0aeafaaSAndreas Gohr        'utf8_bad_replace' => 'dokuwiki\Utf8\Clean::replaceBadBytes',
190a0aeafaaSAndreas Gohr        'utf8_correctIdx' => 'dokuwiki\Utf8\Clean::correctIdx',
191a0aeafaaSAndreas Gohr    ]);
192*f9a94e78SAndreas Gohr
193*f9a94e78SAndreas Gohr    $rectorConfig->rule(DokuWikiPtlnRector::class);
194077b7fe2SAndreas Gohr};
195