xref: /dokuwiki/_test/rector.php (revision a0aeafaa2be80428767dc89e2f806edd8de8c981)
1077b7fe2SAndreas Gohr<?php
2077b7fe2SAndreas Gohr
3077b7fe2SAndreas Gohrdeclare(strict_types=1);
4077b7fe2SAndreas Gohr
5077b7fe2SAndreas Gohruse Rector\Caching\ValueObject\Storage\FileCacheStorage;
6077b7fe2SAndreas Gohruse Rector\CodeQuality\Rector\Array_\CallableThisArrayToAnonymousFunctionRector;
7e2d055f5SAndreas Gohruse Rector\CodeQuality\Rector\Concat\JoinStringConcatRector;
8077b7fe2SAndreas Gohruse Rector\CodeQuality\Rector\FunctionLike\SimplifyUselessVariableRector;
9077b7fe2SAndreas Gohruse Rector\CodeQuality\Rector\If_\CombineIfRector;
10077b7fe2SAndreas Gohruse Rector\CodeQuality\Rector\If_\ExplicitBoolCompareRector;
11077b7fe2SAndreas Gohruse Rector\CodeQuality\Rector\If_\SimplifyIfElseToTernaryRector;
121490c177SAndreas Gohruse Rector\CodeQuality\Rector\If_\SimplifyIfReturnBoolRector;
13077b7fe2SAndreas Gohruse Rector\CodeQuality\Rector\Isset_\IssetOnPropertyObjectToPropertyExistsRector;
14077b7fe2SAndreas Gohruse Rector\CodingStyle\Rector\Catch_\CatchExceptionNameMatchingTypeRector;
15104a3b7cSAndreas Gohruse Rector\CodingStyle\Rector\Class_\AddArrayDefaultToArrayPropertyRector;
16077b7fe2SAndreas Gohruse Rector\CodingStyle\Rector\Closure\StaticClosureRector;
17077b7fe2SAndreas Gohruse Rector\CodingStyle\Rector\Encapsed\EncapsedStringsToSprintfRector;
186723156fSAndreas Gohruse Rector\CodingStyle\Rector\Encapsed\WrapEncapsedVariableInCurlyBracesRector;
19a469bafbSAndreas Gohruse Rector\CodingStyle\Rector\FuncCall\StrictArraySearchRector;
20077b7fe2SAndreas Gohruse Rector\CodingStyle\Rector\PostInc\PostIncDecToPreIncDecRector;
21077b7fe2SAndreas Gohruse Rector\CodingStyle\Rector\Stmt\NewlineAfterStatementRector;
22077b7fe2SAndreas Gohruse Rector\CodingStyle\Rector\String_\SymplifyQuoteEscapeRector;
23077b7fe2SAndreas Gohruse Rector\Config\RectorConfig;
24077b7fe2SAndreas Gohruse Rector\DeadCode\Rector\ClassMethod\RemoveUselessParamTagRector;
2524870174SAndreas Gohruse Rector\DeadCode\Rector\If_\RemoveAlwaysTrueIfConditionRector;
26bcaec9f4SAndreas Gohruse Rector\DeadCode\Rector\If_\RemoveUnusedNonEmptyArrayBeforeForeachRector;
27104a3b7cSAndreas Gohruse Rector\DeadCode\Rector\Property\RemoveUselessVarTagRector;
286723156fSAndreas Gohruse Rector\DeadCode\Rector\StaticCall\RemoveParentCallWithoutParentRector;
2924870174SAndreas Gohruse Rector\DeadCode\Rector\Stmt\RemoveUnreachableStatementRector;
300603e565SAndreas Gohruse Rector\Php71\Rector\FuncCall\CountOnNullRector;
316e695190SAndreas Gohruse Rector\Php71\Rector\FuncCall\RemoveExtraParametersRector;
32*a0aeafaaSAndreas Gohruse Rector\Renaming\Rector\FuncCall\RenameFunctionRector;
33*a0aeafaaSAndreas Gohruse Rector\Renaming\Rector\Name\RenameClassRector;
34077b7fe2SAndreas Gohruse Rector\Set\ValueObject\LevelSetList;
35077b7fe2SAndreas Gohruse Rector\Set\ValueObject\SetList;
36077b7fe2SAndreas Gohruse Rector\Strict\Rector\Empty_\DisallowedEmptyRuleFixerRector;
37104a3b7cSAndreas Gohruse Rector\TypeDeclaration\Rector\Property\TypedPropertyFromAssignsRector;
38077b7fe2SAndreas Gohr
39077b7fe2SAndreas Gohrreturn static function (RectorConfig $rectorConfig): void {
40077b7fe2SAndreas Gohr    $rectorConfig->paths([
41b1f206e1SAndreas Gohr        __DIR__ . '/../inc/',
42b1f206e1SAndreas Gohr        __DIR__ . '/../lib/',
43b1f206e1SAndreas Gohr        __DIR__ . '/../bin/',
44b1f206e1SAndreas Gohr        __DIR__ . '/../*.php',
45077b7fe2SAndreas Gohr    ]);
46077b7fe2SAndreas Gohr
471490c177SAndreas Gohr    $rectorConfig->bootstrapFiles([
4824870174SAndreas Gohr        __DIR__ . '/../inc/init.php',
491490c177SAndreas Gohr    ]);
501490c177SAndreas Gohr
51077b7fe2SAndreas Gohr    $rectorConfig->importNames();
52077b7fe2SAndreas Gohr    $rectorConfig->importShortClasses(false);
53077b7fe2SAndreas Gohr    $rectorConfig->cacheClass(FileCacheStorage::class);
54077b7fe2SAndreas Gohr    $rectorConfig->cacheDirectory(__DIR__ . '/.rector-cache');
55077b7fe2SAndreas Gohr
56077b7fe2SAndreas Gohr    // define sets of rules
57077b7fe2SAndreas Gohr    $rectorConfig->sets([
58077b7fe2SAndreas Gohr        LevelSetList::UP_TO_PHP_74,
59077b7fe2SAndreas Gohr        SetList::CODE_QUALITY,
60077b7fe2SAndreas Gohr        SetList::DEAD_CODE,
61077b7fe2SAndreas Gohr        SetList::CODING_STYLE,
62077b7fe2SAndreas Gohr    ]);
63077b7fe2SAndreas Gohr
64077b7fe2SAndreas Gohr    $rectorConfig->skip([
65077b7fe2SAndreas Gohr        // skip paths
66077b7fe2SAndreas Gohr        __DIR__ . '/../inc/lang/*',
67077b7fe2SAndreas Gohr        __DIR__ . '/../lib/plugins/*/_test/*',
68077b7fe2SAndreas Gohr        __DIR__ . '/../lib/tpl/*/_test/*',
69077b7fe2SAndreas Gohr        __DIR__ . '/../lib/plugins/*/lang/*',
70077b7fe2SAndreas Gohr        __DIR__ . '/../lib/tpl/*/lang/*',
71467c1427SAndreas Gohr        __DIR__ . '/../lib/plugins/*/conf/*', // maybe later
72467c1427SAndreas Gohr        __DIR__ . '/../lib/tpl/*/conf/*',  // maybe later
73077b7fe2SAndreas Gohr        __DIR__ . '/../lib/plugins/*/vendor/*',
74077b7fe2SAndreas Gohr        __DIR__ . '/../lib/tpl/*/vendor/*',
75077b7fe2SAndreas Gohr        __DIR__ . '/../lib/plugins/*/skel/*', // dev plugin
7624870174SAndreas Gohr        __DIR__ . '/../inc/deprecated.php',
7724870174SAndreas Gohr        __DIR__ . '/../inc/form.php',
78077b7fe2SAndreas Gohr
79077b7fe2SAndreas Gohr        // third party libs, not yet moved to composer
80077b7fe2SAndreas Gohr        __DIR__ . '/../inc/DifferenceEngine.php',
81077b7fe2SAndreas Gohr        __DIR__ . '/../inc/JpegMeta.php',
82077b7fe2SAndreas Gohr        __DIR__ . '/../lib/plugins/authad/adLDAP',
83077b7fe2SAndreas Gohr
84077b7fe2SAndreas Gohr        // skip rules
85077b7fe2SAndreas Gohr        SimplifyIfElseToTernaryRector::class,
86077b7fe2SAndreas Gohr        NewlineAfterStatementRector::class,
87077b7fe2SAndreas Gohr        CombineIfRector::class,
88077b7fe2SAndreas Gohr        ExplicitBoolCompareRector::class,
89077b7fe2SAndreas Gohr        IssetOnPropertyObjectToPropertyExistsRector::class, // maybe?
90077b7fe2SAndreas Gohr        SymplifyQuoteEscapeRector::class,
91077b7fe2SAndreas Gohr        CatchExceptionNameMatchingTypeRector::class,
92077b7fe2SAndreas Gohr        EncapsedStringsToSprintfRector::class,
93077b7fe2SAndreas Gohr        CallableThisArrayToAnonymousFunctionRector::class,
94077b7fe2SAndreas Gohr        StaticClosureRector::class,
95077b7fe2SAndreas Gohr        SimplifyUselessVariableRector::class, // seems to strip constructor property initializations
96077b7fe2SAndreas Gohr        PostIncDecToPreIncDecRector::class,
97077b7fe2SAndreas Gohr        RemoveUselessParamTagRector::class,
98077b7fe2SAndreas Gohr        DisallowedEmptyRuleFixerRector::class,
990603e565SAndreas Gohr        CountOnNullRector::class, // adds unwanted is_countable checks?
1006723156fSAndreas Gohr        RemoveParentCallWithoutParentRector::class,
1016723156fSAndreas Gohr        WrapEncapsedVariableInCurlyBracesRector::class,
1021490c177SAndreas Gohr        SimplifyIfReturnBoolRector::class,
103a469bafbSAndreas Gohr        StrictArraySearchRector::class, // we cannot assume strict search is always wanted
104104a3b7cSAndreas Gohr        AddArrayDefaultToArrayPropertyRector::class, // may break code differentiating between null and empty array
105104a3b7cSAndreas Gohr        RemoveUselessVarTagRector::class,
106104a3b7cSAndreas Gohr        TypedPropertyFromAssignsRector::class, // maybe?
107e2d055f5SAndreas Gohr        JoinStringConcatRector::class, // this does not count variables, so it creates overlong lines
1086e695190SAndreas Gohr        RemoveExtraParametersRector::class, // this actually broke code
109bcaec9f4SAndreas Gohr        RemoveUnusedNonEmptyArrayBeforeForeachRector::class, // seems unreliable when checking on array keys
11024870174SAndreas Gohr        RemoveAlwaysTrueIfConditionRector::class, // fails with if(defined(...)) constructs
111ab9790caSAndreas Gohr        RemoveUnreachableStatementRector::class, // fails GOTO in authpdo -> should be rewritten with exceptions
112077b7fe2SAndreas Gohr    ]);
113*a0aeafaaSAndreas Gohr
114*a0aeafaaSAndreas Gohr    $rectorConfig->ruleWithConfiguration(RenameClassRector::class, [
115*a0aeafaaSAndreas Gohr        // see inc/deprecated.php
116*a0aeafaaSAndreas Gohr        'RemoteAccessDeniedException' => 'dokuwiki\Remote\AccessDeniedException',
117*a0aeafaaSAndreas Gohr        'RemoteException' => 'dokuwiki\Remote\RemoteException',
118*a0aeafaaSAndreas Gohr        'setting' => 'dokuwiki\plugin\config\core\Setting\Setting',
119*a0aeafaaSAndreas Gohr        'setting_authtype' => 'dokuwiki\plugin\config\core\Setting\SettingAuthtype',
120*a0aeafaaSAndreas Gohr        'setting_string' => 'dokuwiki\plugin\config\core\Setting\SettingString',
121*a0aeafaaSAndreas Gohr        'PageChangelog' => 'dokuwiki\ChangeLog\PageChangeLog',
122*a0aeafaaSAndreas Gohr        'MediaChangelog' => 'dokuwiki\ChangeLog\MediaChangeLog',
123*a0aeafaaSAndreas Gohr        'Input' => 'dokuwiki\Input\Input',
124*a0aeafaaSAndreas Gohr        'PostInput' => 'dokuwiki\Input\Post',
125*a0aeafaaSAndreas Gohr        'GetInput' => 'dokuwiki\Input\Get',
126*a0aeafaaSAndreas Gohr        'ServerInput' => 'dokuwiki\Input\Server',
127*a0aeafaaSAndreas Gohr        'PassHash' => 'dokuwiki\PassHash',
128*a0aeafaaSAndreas Gohr        'HTTPClientException' => 'dokuwiki\HTTP\HTTPClientException',
129*a0aeafaaSAndreas Gohr        'HTTPClient' => 'dokuwiki\HTTP\HTTPClient',
130*a0aeafaaSAndreas Gohr        'DokuHTTPClient' => 'dokuwiki\HTTP\DokuHTTPClient',
131*a0aeafaaSAndreas Gohr        'Doku_Plugin_Controller' => 'dokuwiki\Extension\PluginController',
132*a0aeafaaSAndreas Gohr        'Doku_Indexer' => 'dokuwiki\Search\Indexer',
133*a0aeafaaSAndreas Gohr        'IXR_Client' => 'dokuwiki\Remote\IXR\Client',
134*a0aeafaaSAndreas Gohr        'IXR_ClientMulticall' => 'IXR\Client\ClientMulticall',
135*a0aeafaaSAndreas Gohr        'IXR_Server' => 'IXR\Server\Server',
136*a0aeafaaSAndreas Gohr        'IXR_IntrospectionServer' => 'IXR\Server\IntrospectionServer',
137*a0aeafaaSAndreas Gohr        'IXR_Request' => 'IXR\Request\Request',
138*a0aeafaaSAndreas Gohr        'IXR_Message' => 'R\Message\Message',
139*a0aeafaaSAndreas Gohr        'IXR_Error' => 'XR\Message\Error',
140*a0aeafaaSAndreas Gohr        'IXR_Date' => 'IXR\DataType\Date',
141*a0aeafaaSAndreas Gohr        'IXR_Base64' => 'IXR\DataType\Base64',
142*a0aeafaaSAndreas Gohr        'IXR_Value' => 'IXR\DataType\Value',
143*a0aeafaaSAndreas Gohr
144*a0aeafaaSAndreas Gohr        // see inc/legacy.php
145*a0aeafaaSAndreas Gohr        'Doku_Event_Handler' => 'dokuwiki\Extension\EventHandler',
146*a0aeafaaSAndreas Gohr        'Doku_Event' => 'dokuwiki\Extension\Event',
147*a0aeafaaSAndreas Gohr        'DokuWiki_Action_Plugin' => 'dokuwiki\Extension\ActionPlugin',
148*a0aeafaaSAndreas Gohr        'DokuWiki_Admin_Plugin' => 'dokuwiki\Extension\AdminPlugin',
149*a0aeafaaSAndreas Gohr        'DokuWiki_Auth_Plugin' => 'dokuwiki\Extension\AuthPlugin',
150*a0aeafaaSAndreas Gohr        'DokuWiki_CLI_Plugin' => 'dokuwiki\Extension\CLIPlugin',
151*a0aeafaaSAndreas Gohr        'DokuWiki_Plugin' => 'dokuwiki\Extension\Plugin',
152*a0aeafaaSAndreas Gohr        'DokuWiki_Remote_Plugin' => 'dokuwiki\Extension\RemotePlugin',
153*a0aeafaaSAndreas Gohr        'DokuWiki_Syntax_Plugin' => 'dokuwiki\Extension\SyntaxPlugin',
154*a0aeafaaSAndreas Gohr    ]);
155*a0aeafaaSAndreas Gohr
156*a0aeafaaSAndreas Gohr    $rectorConfig->ruleWithConfiguration(RenameFunctionRector::class, [
157*a0aeafaaSAndreas Gohr        // see inc/deprecated.php
158*a0aeafaaSAndreas Gohr        'Doku_Lexer_Escape' => 'dokuwiki\Parsing\Lexer\Lexer::escape',
159*a0aeafaaSAndreas Gohr
160*a0aeafaaSAndreas Gohr        // see inc/utf8.php
161*a0aeafaaSAndreas Gohr        'utf8_isASCII' => 'dokuwiki\Utf8\Clean::isASCII',
162*a0aeafaaSAndreas Gohr        'utf8_strip' => 'dokuwiki\Utf8\Clean::strip',
163*a0aeafaaSAndreas Gohr        'utf8_check' => 'dokuwiki\Utf8\Clean::isUtf8',
164*a0aeafaaSAndreas Gohr        'utf8_basename' => 'dokuwiki\Utf8\PhpString::basename',
165*a0aeafaaSAndreas Gohr        'utf8_strlen' => 'dokuwiki\Utf8\PhpString::strlen',
166*a0aeafaaSAndreas Gohr        'utf8_substr' => 'dokuwiki\Utf8\PhpString::substr',
167*a0aeafaaSAndreas Gohr        'utf8_substr_replace' => 'dokuwiki\Utf8\PhpString::substr_replace',
168*a0aeafaaSAndreas Gohr        'utf8_ltrim' => 'dokuwiki\Utf8\PhpString::ltrim',
169*a0aeafaaSAndreas Gohr        'utf8_rtrim' => 'dokuwiki\Utf8\PhpString::rtrim',
170*a0aeafaaSAndreas Gohr        'utf8_trim' => 'dokuwiki\Utf8\PhpString::trim',
171*a0aeafaaSAndreas Gohr        'utf8_strtolower' => 'dokuwiki\Utf8\PhpString::strtolower',
172*a0aeafaaSAndreas Gohr        'utf8_strtoupper' => 'dokuwiki\Utf8\PhpString::strtoupper',
173*a0aeafaaSAndreas Gohr        'utf8_ucfirst' => 'dokuwiki\Utf8\PhpString::ucfirst',
174*a0aeafaaSAndreas Gohr        'utf8_ucwords' => 'dokuwiki\Utf8\PhpString::ucwords',
175*a0aeafaaSAndreas Gohr        'utf8_deaccent' => 'dokuwiki\Utf8\Clean::deaccent',
176*a0aeafaaSAndreas Gohr        'utf8_romanize' => 'dokuwiki\Utf8\Clean::romanize',
177*a0aeafaaSAndreas Gohr        'utf8_stripspecials' => 'dokuwiki\Utf8\Clean::stripspecials',
178*a0aeafaaSAndreas Gohr        'utf8_strpos' => 'dokuwiki\Utf8\PhpString::strpos',
179*a0aeafaaSAndreas Gohr        'utf8_tohtml' => 'dokuwiki\Utf8\Conversion::toHtml',
180*a0aeafaaSAndreas Gohr        'utf8_unhtml' => 'dokuwiki\Utf8\Conversion::fromHtml',
181*a0aeafaaSAndreas Gohr        'utf8_to_unicode' => 'dokuwiki\Utf8\Conversion::fromUtf8',
182*a0aeafaaSAndreas Gohr        'unicode_to_utf8' => 'dokuwiki\Utf8\Conversion::toUtf8',
183*a0aeafaaSAndreas Gohr        'utf8_to_utf16be' => 'dokuwiki\Utf8\Conversion::toUtf16be',
184*a0aeafaaSAndreas Gohr        'utf16be_to_utf8' => 'dokuwiki\Utf8\Conversion::fromUtf16be',
185*a0aeafaaSAndreas Gohr        'utf8_bad_replace' => 'dokuwiki\Utf8\Clean::replaceBadBytes',
186*a0aeafaaSAndreas Gohr        'utf8_correctIdx' => 'dokuwiki\Utf8\Clean::correctIdx',
187*a0aeafaaSAndreas Gohr    ]);
188077b7fe2SAndreas Gohr};
189