xref: /dokuwiki/_test/rector.php (revision 8553d24d33ab5f260c6e19959de764dd8472d438)
1<?php
2
3declare(strict_types=1);
4
5use Rector\Caching\ValueObject\Storage\FileCacheStorage;
6use Rector\CodeQuality\Rector\Array_\CallableThisArrayToAnonymousFunctionRector;
7use Rector\CodeQuality\Rector\Concat\JoinStringConcatRector;
8use Rector\CodeQuality\Rector\FunctionLike\SimplifyUselessVariableRector;
9use Rector\CodeQuality\Rector\If_\CombineIfRector;
10use Rector\CodeQuality\Rector\If_\ExplicitBoolCompareRector;
11use Rector\CodeQuality\Rector\If_\SimplifyIfElseToTernaryRector;
12use Rector\CodeQuality\Rector\If_\SimplifyIfReturnBoolRector;
13use Rector\CodeQuality\Rector\Isset_\IssetOnPropertyObjectToPropertyExistsRector;
14use Rector\CodingStyle\Rector\Catch_\CatchExceptionNameMatchingTypeRector;
15use Rector\CodingStyle\Rector\Class_\AddArrayDefaultToArrayPropertyRector;
16use Rector\CodingStyle\Rector\Closure\StaticClosureRector;
17use Rector\CodingStyle\Rector\Encapsed\EncapsedStringsToSprintfRector;
18use Rector\CodingStyle\Rector\Encapsed\WrapEncapsedVariableInCurlyBracesRector;
19use Rector\CodingStyle\Rector\FuncCall\StrictArraySearchRector;
20use Rector\CodingStyle\Rector\PostInc\PostIncDecToPreIncDecRector;
21use Rector\CodingStyle\Rector\Stmt\NewlineAfterStatementRector;
22use Rector\CodingStyle\Rector\String_\SymplifyQuoteEscapeRector;
23use Rector\Config\RectorConfig;
24use Rector\DeadCode\Rector\ClassMethod\RemoveUselessParamTagRector;
25use Rector\DeadCode\Rector\If_\RemoveAlwaysTrueIfConditionRector;
26use Rector\DeadCode\Rector\If_\RemoveUnusedNonEmptyArrayBeforeForeachRector;
27use Rector\DeadCode\Rector\Property\RemoveUselessVarTagRector;
28use Rector\DeadCode\Rector\StaticCall\RemoveParentCallWithoutParentRector;
29use Rector\DeadCode\Rector\Stmt\RemoveUnreachableStatementRector;
30use Rector\Php71\Rector\FuncCall\CountOnNullRector;
31use Rector\Php71\Rector\FuncCall\RemoveExtraParametersRector;
32use Rector\Renaming\Rector\FuncCall\RenameFunctionRector;
33use Rector\Renaming\Rector\Name\RenameClassRector;
34use Rector\Set\ValueObject\LevelSetList;
35use Rector\Set\ValueObject\SetList;
36use Rector\Strict\Rector\Empty_\DisallowedEmptyRuleFixerRector;
37use Rector\TypeDeclaration\Rector\Property\TypedPropertyFromAssignsRector;
38
39return static function (RectorConfig $rectorConfig): void {
40    $rectorConfig->paths([
41        __DIR__ . '/../inc/',
42        __DIR__ . '/../lib/',
43        __DIR__ . '/../bin/',
44        __DIR__ . '/../*.php',
45    ]);
46
47    $rectorConfig->bootstrapFiles([
48        __DIR__ . '/../inc/init.php',
49    ]);
50
51    $rectorConfig->importNames();
52    $rectorConfig->importShortClasses(false);
53    $rectorConfig->cacheClass(FileCacheStorage::class);
54    $rectorConfig->cacheDirectory(__DIR__ . '/.rector-cache');
55
56    // define sets of rules
57    $rectorConfig->sets([
58        LevelSetList::UP_TO_PHP_74,
59        SetList::CODE_QUALITY,
60        SetList::DEAD_CODE,
61        SetList::CODING_STYLE,
62    ]);
63
64    $rectorConfig->skip([
65        // skip paths
66        __DIR__ . '/../inc/lang/*',
67        __DIR__ . '/../lib/plugins/*/_test/*',
68        __DIR__ . '/../lib/tpl/*/_test/*',
69        __DIR__ . '/../lib/plugins/*/lang/*',
70        __DIR__ . '/../lib/tpl/*/lang/*',
71        __DIR__ . '/../lib/plugins/*/conf/*', // maybe later
72        __DIR__ . '/../lib/tpl/*/conf/*',  // maybe later
73        __DIR__ . '/../lib/plugins/*/vendor/*',
74        __DIR__ . '/../lib/tpl/*/vendor/*',
75        __DIR__ . '/../lib/plugins/*/skel/*', // dev plugin
76        __DIR__ . '/../inc/deprecated.php',
77        __DIR__ . '/../inc/form.php',
78
79        // third party libs, not yet moved to composer
80        __DIR__ . '/../inc/DifferenceEngine.php',
81        __DIR__ . '/../inc/JpegMeta.php',
82        __DIR__ . '/../lib/plugins/authad/adLDAP',
83
84        // skip rules
85        SimplifyIfElseToTernaryRector::class,
86        NewlineAfterStatementRector::class,
87        CombineIfRector::class,
88        ExplicitBoolCompareRector::class,
89        IssetOnPropertyObjectToPropertyExistsRector::class, // maybe?
90        SymplifyQuoteEscapeRector::class,
91        CatchExceptionNameMatchingTypeRector::class,
92        EncapsedStringsToSprintfRector::class,
93        CallableThisArrayToAnonymousFunctionRector::class,
94        StaticClosureRector::class,
95        SimplifyUselessVariableRector::class, // seems to strip constructor property initializations
96        PostIncDecToPreIncDecRector::class,
97        RemoveUselessParamTagRector::class,
98        DisallowedEmptyRuleFixerRector::class,
99        CountOnNullRector::class, // adds unwanted is_countable checks?
100        RemoveParentCallWithoutParentRector::class,
101        WrapEncapsedVariableInCurlyBracesRector::class,
102        SimplifyIfReturnBoolRector::class,
103        StrictArraySearchRector::class, // we cannot assume strict search is always wanted
104        AddArrayDefaultToArrayPropertyRector::class, // may break code differentiating between null and empty array
105        RemoveUselessVarTagRector::class,
106        TypedPropertyFromAssignsRector::class, // maybe?
107        JoinStringConcatRector::class, // this does not count variables, so it creates overlong lines
108        RemoveExtraParametersRector::class, // this actually broke code
109        RemoveUnusedNonEmptyArrayBeforeForeachRector::class, // seems unreliable when checking on array keys
110        RemoveAlwaysTrueIfConditionRector::class, // fails with if(defined(...)) constructs
111        RemoveUnreachableStatementRector::class, // fails GOTO in authpdo -> should be rewritten with exceptions
112    ]);
113
114    $rectorConfig->ruleWithConfiguration(RenameClassRector::class, [
115        // see inc/deprecated.php
116        'RemoteAccessDeniedException' => 'dokuwiki\Remote\AccessDeniedException',
117        'RemoteException' => 'dokuwiki\Remote\RemoteException',
118        'setting' => 'dokuwiki\plugin\config\core\Setting\Setting',
119        'setting_authtype' => 'dokuwiki\plugin\config\core\Setting\SettingAuthtype',
120        'setting_string' => 'dokuwiki\plugin\config\core\Setting\SettingString',
121        'PageChangelog' => 'dokuwiki\ChangeLog\PageChangeLog',
122        'MediaChangelog' => 'dokuwiki\ChangeLog\MediaChangeLog',
123        'Input' => 'dokuwiki\Input\Input',
124        'PostInput' => 'dokuwiki\Input\Post',
125        'GetInput' => 'dokuwiki\Input\Get',
126        'ServerInput' => 'dokuwiki\Input\Server',
127        'PassHash' => 'dokuwiki\PassHash',
128        'HTTPClientException' => 'dokuwiki\HTTP\HTTPClientException',
129        'HTTPClient' => 'dokuwiki\HTTP\HTTPClient',
130        'DokuHTTPClient' => 'dokuwiki\HTTP\DokuHTTPClient',
131        'Doku_Plugin_Controller' => 'dokuwiki\Extension\PluginController',
132        'Doku_Indexer' => 'dokuwiki\Search\Indexer',
133        'IXR_Client' => 'dokuwiki\Remote\IXR\Client',
134        'IXR_ClientMulticall' => 'IXR\Client\ClientMulticall',
135        'IXR_Server' => 'IXR\Server\Server',
136        'IXR_IntrospectionServer' => 'IXR\Server\IntrospectionServer',
137        'IXR_Request' => 'IXR\Request\Request',
138        'IXR_Message' => 'R\Message\Message',
139        'IXR_Error' => 'XR\Message\Error',
140        'IXR_Date' => 'IXR\DataType\Date',
141        'IXR_Base64' => 'IXR\DataType\Base64',
142        'IXR_Value' => 'IXR\DataType\Value',
143
144        // see inc/legacy.php
145        'Doku_Event_Handler' => 'dokuwiki\Extension\EventHandler',
146        'Doku_Event' => 'dokuwiki\Extension\Event',
147        'DokuWiki_Action_Plugin' => 'dokuwiki\Extension\ActionPlugin',
148        'DokuWiki_Admin_Plugin' => 'dokuwiki\Extension\AdminPlugin',
149        'DokuWiki_Auth_Plugin' => 'dokuwiki\Extension\AuthPlugin',
150        'DokuWiki_CLI_Plugin' => 'dokuwiki\Extension\CLIPlugin',
151        'DokuWiki_Plugin' => 'dokuwiki\Extension\Plugin',
152        'DokuWiki_Remote_Plugin' => 'dokuwiki\Extension\RemotePlugin',
153        'DokuWiki_Syntax_Plugin' => 'dokuwiki\Extension\SyntaxPlugin',
154    ]);
155
156    $rectorConfig->ruleWithConfiguration(RenameFunctionRector::class, [
157        // see inc/deprecated.php
158        'Doku_Lexer_Escape' => 'dokuwiki\Parsing\Lexer\Lexer::escape',
159
160        // see inc/utf8.php
161        'utf8_isASCII' => 'dokuwiki\Utf8\Clean::isASCII',
162        'utf8_strip' => 'dokuwiki\Utf8\Clean::strip',
163        'utf8_check' => 'dokuwiki\Utf8\Clean::isUtf8',
164        'utf8_basename' => 'dokuwiki\Utf8\PhpString::basename',
165        'utf8_strlen' => 'dokuwiki\Utf8\PhpString::strlen',
166        'utf8_substr' => 'dokuwiki\Utf8\PhpString::substr',
167        'utf8_substr_replace' => 'dokuwiki\Utf8\PhpString::substr_replace',
168        'utf8_ltrim' => 'dokuwiki\Utf8\PhpString::ltrim',
169        'utf8_rtrim' => 'dokuwiki\Utf8\PhpString::rtrim',
170        'utf8_trim' => 'dokuwiki\Utf8\PhpString::trim',
171        'utf8_strtolower' => 'dokuwiki\Utf8\PhpString::strtolower',
172        'utf8_strtoupper' => 'dokuwiki\Utf8\PhpString::strtoupper',
173        'utf8_ucfirst' => 'dokuwiki\Utf8\PhpString::ucfirst',
174        'utf8_ucwords' => 'dokuwiki\Utf8\PhpString::ucwords',
175        'utf8_deaccent' => 'dokuwiki\Utf8\Clean::deaccent',
176        'utf8_romanize' => 'dokuwiki\Utf8\Clean::romanize',
177        'utf8_stripspecials' => 'dokuwiki\Utf8\Clean::stripspecials',
178        'utf8_strpos' => 'dokuwiki\Utf8\PhpString::strpos',
179        'utf8_tohtml' => 'dokuwiki\Utf8\Conversion::toHtml',
180        'utf8_unhtml' => 'dokuwiki\Utf8\Conversion::fromHtml',
181        'utf8_to_unicode' => 'dokuwiki\Utf8\Conversion::fromUtf8',
182        'unicode_to_utf8' => 'dokuwiki\Utf8\Conversion::toUtf8',
183        'utf8_to_utf16be' => 'dokuwiki\Utf8\Conversion::toUtf16be',
184        'utf16be_to_utf8' => 'dokuwiki\Utf8\Conversion::fromUtf16be',
185        'utf8_bad_replace' => 'dokuwiki\Utf8\Clean::replaceBadBytes',
186        'utf8_correctIdx' => 'dokuwiki\Utf8\Clean::correctIdx',
187    ]);
188};
189