update create-pull-request action to v6
[dokuwiki.git] / _test / rector.php
blobc16e3559b466406a68f4109267542ce19aa7c656
1 <?php
3 declare(strict_types=1);
5 use dokuwiki\test\rector\DokuWikiPtlnRector;
6 use dokuwiki\test\rector\DokuWikiRenamePrintToEcho;
7 use Rector\Caching\ValueObject\Storage\FileCacheStorage;
8 use Rector\CodeQuality\Rector\Array_\CallableThisArrayToAnonymousFunctionRector;
9 use Rector\CodeQuality\Rector\Concat\JoinStringConcatRector;
10 use Rector\CodeQuality\Rector\FunctionLike\SimplifyUselessVariableRector;
11 use Rector\CodeQuality\Rector\If_\CombineIfRector;
12 use Rector\CodeQuality\Rector\If_\CompleteMissingIfElseBracketRector;
13 use Rector\CodeQuality\Rector\If_\ExplicitBoolCompareRector;
14 use Rector\CodeQuality\Rector\If_\SimplifyIfElseToTernaryRector;
15 use Rector\CodeQuality\Rector\If_\SimplifyIfReturnBoolRector;
16 use Rector\CodeQuality\Rector\Isset_\IssetOnPropertyObjectToPropertyExistsRector;
17 use Rector\CodingStyle\Rector\Catch_\CatchExceptionNameMatchingTypeRector;
18 use Rector\CodingStyle\Rector\Closure\StaticClosureRector;
19 use Rector\CodingStyle\Rector\Encapsed\EncapsedStringsToSprintfRector;
20 use Rector\CodingStyle\Rector\Encapsed\WrapEncapsedVariableInCurlyBracesRector;
21 use Rector\CodingStyle\Rector\FuncCall\StrictArraySearchRector;
22 use Rector\CodingStyle\Rector\PostInc\PostIncDecToPreIncDecRector;
23 use Rector\CodingStyle\Rector\Stmt\NewlineAfterStatementRector;
24 use Rector\CodingStyle\Rector\String_\SymplifyQuoteEscapeRector;
25 use Rector\Config\RectorConfig;
26 use Rector\DeadCode\Rector\ClassMethod\RemoveUnusedConstructorParamRector;
27 use Rector\DeadCode\Rector\ClassMethod\RemoveUselessParamTagRector;
28 use Rector\DeadCode\Rector\ClassMethod\RemoveUselessReturnTagRector;
29 use Rector\DeadCode\Rector\If_\RemoveAlwaysTrueIfConditionRector;
30 use Rector\DeadCode\Rector\If_\RemoveUnusedNonEmptyArrayBeforeForeachRector;
31 use Rector\DeadCode\Rector\Property\RemoveUselessVarTagRector;
32 use Rector\DeadCode\Rector\StaticCall\RemoveParentCallWithoutParentRector;
33 use Rector\DeadCode\Rector\Stmt\RemoveUnreachableStatementRector;
34 use Rector\Php71\Rector\FuncCall\RemoveExtraParametersRector;
35 use Rector\Php80\Rector\Identical\StrEndsWithRector;
36 use Rector\Php80\Rector\Identical\StrStartsWithRector;
37 use Rector\Php80\Rector\NotIdentical\StrContainsRector;
38 use Rector\Renaming\Rector\FuncCall\RenameFunctionRector;
39 use Rector\Renaming\Rector\Name\RenameClassRector;
40 use Rector\Set\ValueObject\LevelSetList;
41 use Rector\Set\ValueObject\SetList;
42 use Rector\Strict\Rector\Empty_\DisallowedEmptyRuleFixerRector;
43 use Rector\TypeDeclaration\Rector\ClassMethod\ReturnNeverTypeRector;
44 use Rector\TypeDeclaration\Rector\Property\TypedPropertyFromAssignsRector;
46 return static function (RectorConfig $rectorConfig): void {
47 // FIXME we may want to autoload these later
48 require_once __DIR__ . '/rector/DokuWikiPtlnRector.php';
49 require_once __DIR__ . '/rector/DokuWikiRenamePrintToEcho.php';
51 // tune parallel task settings (see rectorphp/rector#8396)
52 $rectorConfig->parallel(120, 16, 10);
54 $rectorConfig->paths([
55 __DIR__ . '/../inc/',
56 __DIR__ . '/../lib/',
57 __DIR__ . '/../bin/',
58 __DIR__ . '/../*.php',
59 ]);
61 $rectorConfig->bootstrapFiles([
62 __DIR__ . '/../inc/init.php',
63 ]);
65 $rectorConfig->importNames();
66 $rectorConfig->importShortClasses(false);
67 $rectorConfig->cacheClass(FileCacheStorage::class);
68 $rectorConfig->cacheDirectory(__DIR__ . '/.rector-cache');
70 // supported minimum PHP version can be overridden by environment variable
71 [$major, $minor] = explode('.', $_SERVER['RECTOR_MIN_PHP'] ?? '' ?: '7.4');
72 $phpset = LevelSetList::class . '::UP_TO_PHP_' . $major . $minor;
73 fwrite(STDERR, "Using PHP set $phpset\n");
75 // define sets of rules
76 $rectorConfig->sets([
77 constant($phpset),
78 SetList::CODE_QUALITY,
79 SetList::DEAD_CODE,
80 SetList::CODING_STYLE,
81 ]);
83 // future rules for which we have polyfills
84 $rectorConfig->rule(StrContainsRector::class);
85 $rectorConfig->rule(StrEndsWithRector::class);
86 $rectorConfig->rule(StrStartsWithRector::class);
88 $rectorConfig->skip([
89 // skip paths
90 __DIR__ . '/../inc/lang/*',
91 __DIR__ . '/../lib/plugins/*/_test/*',
92 __DIR__ . '/../lib/tpl/*/_test/*',
93 __DIR__ . '/../lib/plugins/*/lang/*',
94 __DIR__ . '/../lib/tpl/*/lang/*',
95 __DIR__ . '/../lib/plugins/*/conf/*', // maybe later
96 __DIR__ . '/../lib/tpl/*/conf/*', // maybe later
97 __DIR__ . '/../lib/plugins/*/vendor/*',
98 __DIR__ . '/../lib/tpl/*/vendor/*',
99 __DIR__ . '/../lib/plugins/*/skel/*', // dev plugin
100 __DIR__ . '/../inc/deprecated.php',
101 __DIR__ . '/../inc/form.php',
103 // third party libs, not yet moved to composer
104 __DIR__ . '/../inc/DifferenceEngine.php',
105 __DIR__ . '/../inc/JpegMeta.php',
106 __DIR__ . '/../lib/plugins/authad/adLDAP',
108 // skip rules
109 CompleteMissingIfElseBracketRector::class, // keep one-line guardians
110 SimplifyIfElseToTernaryRector::class,
111 NewlineAfterStatementRector::class,
112 CombineIfRector::class,
113 ExplicitBoolCompareRector::class,
114 IssetOnPropertyObjectToPropertyExistsRector::class, // maybe?
115 SymplifyQuoteEscapeRector::class,
116 CatchExceptionNameMatchingTypeRector::class,
117 EncapsedStringsToSprintfRector::class,
118 CallableThisArrayToAnonymousFunctionRector::class,
119 StaticClosureRector::class,
120 SimplifyUselessVariableRector::class, // seems to strip constructor property initializations
121 PostIncDecToPreIncDecRector::class,
122 DisallowedEmptyRuleFixerRector::class,
123 RemoveParentCallWithoutParentRector::class,
124 WrapEncapsedVariableInCurlyBracesRector::class,
125 SimplifyIfReturnBoolRector::class,
126 StrictArraySearchRector::class, // we cannot assume strict search is always wanted
127 TypedPropertyFromAssignsRector::class, // maybe?
128 JoinStringConcatRector::class, // this does not count variables, so it creates overlong lines
129 RemoveExtraParametersRector::class, // this actually broke code
130 RemoveUnusedConstructorParamRector::class, // see rectorphp/rector#8580
131 RemoveUnusedNonEmptyArrayBeforeForeachRector::class, // seems unreliable when checking on array keys
132 RemoveAlwaysTrueIfConditionRector::class, // fails with if(defined(...)) constructs
133 RemoveUnreachableStatementRector::class, // fails GOTO in authpdo -> should be rewritten with exceptions
134 ReturnNeverTypeRector::class,
135 RemoveUselessParamTagRector::class, // keep doc blocks
136 RemoveUselessVarTagRector::class, // keep doc blocks
137 RemoveUselessReturnTagRector::class, // keep doc blocks
140 $rectorConfig->ruleWithConfiguration(RenameClassRector::class, [
141 // see inc/deprecated.php
142 'RemoteAccessDeniedException' => 'dokuwiki\Remote\AccessDeniedException',
143 'RemoteException' => 'dokuwiki\Remote\RemoteException',
144 'setting' => 'dokuwiki\plugin\config\core\Setting\Setting',
145 'setting_authtype' => 'dokuwiki\plugin\config\core\Setting\SettingAuthtype',
146 'setting_string' => 'dokuwiki\plugin\config\core\Setting\SettingString',
147 'PageChangelog' => 'dokuwiki\ChangeLog\PageChangeLog',
148 'MediaChangelog' => 'dokuwiki\ChangeLog\MediaChangeLog',
149 'Input' => 'dokuwiki\Input\Input',
150 'PostInput' => 'dokuwiki\Input\Post',
151 'GetInput' => 'dokuwiki\Input\Get',
152 'ServerInput' => 'dokuwiki\Input\Server',
153 'PassHash' => 'dokuwiki\PassHash',
154 'HTTPClientException' => 'dokuwiki\HTTP\HTTPClientException',
155 'HTTPClient' => 'dokuwiki\HTTP\HTTPClient',
156 'DokuHTTPClient' => 'dokuwiki\HTTP\DokuHTTPClient',
157 'Doku_Plugin_Controller' => 'dokuwiki\Extension\PluginController',
158 'Doku_Indexer' => 'dokuwiki\Search\Indexer',
159 'IXR_Client' => 'dokuwiki\Remote\IXR\Client',
160 'IXR_ClientMulticall' => 'IXR\Client\ClientMulticall',
161 'IXR_Server' => 'IXR\Server\Server',
162 'IXR_IntrospectionServer' => 'IXR\Server\IntrospectionServer',
163 'IXR_Request' => 'IXR\Request\Request',
164 'IXR_Message' => 'R\Message\Message',
165 'IXR_Error' => 'XR\Message\Error',
166 'IXR_Date' => 'IXR\DataType\Date',
167 'IXR_Base64' => 'IXR\DataType\Base64',
168 'IXR_Value' => 'IXR\DataType\Value',
170 // see inc/legacy.php
171 'Doku_Event_Handler' => 'dokuwiki\Extension\EventHandler',
172 'Doku_Event' => 'dokuwiki\Extension\Event',
173 'DokuWiki_Action_Plugin' => 'dokuwiki\Extension\ActionPlugin',
174 'DokuWiki_Admin_Plugin' => 'dokuwiki\Extension\AdminPlugin',
175 'DokuWiki_Auth_Plugin' => 'dokuwiki\Extension\AuthPlugin',
176 'DokuWiki_CLI_Plugin' => 'dokuwiki\Extension\CLIPlugin',
177 'DokuWiki_Plugin' => 'dokuwiki\Extension\Plugin',
178 'DokuWiki_Remote_Plugin' => 'dokuwiki\Extension\RemotePlugin',
179 'DokuWiki_Syntax_Plugin' => 'dokuwiki\Extension\SyntaxPlugin',
182 $rectorConfig->ruleWithConfiguration(RenameFunctionRector::class, [
183 // see inc/deprecated.php
184 'Doku_Lexer_Escape' => 'dokuwiki\Parsing\Lexer\Lexer::escape',
186 // see inc/utf8.php
187 'utf8_isASCII' => 'dokuwiki\Utf8\Clean::isASCII',
188 'utf8_strip' => 'dokuwiki\Utf8\Clean::strip',
189 'utf8_check' => 'dokuwiki\Utf8\Clean::isUtf8',
190 'utf8_basename' => 'dokuwiki\Utf8\PhpString::basename',
191 'utf8_strlen' => 'dokuwiki\Utf8\PhpString::strlen',
192 'utf8_substr' => 'dokuwiki\Utf8\PhpString::substr',
193 'utf8_substr_replace' => 'dokuwiki\Utf8\PhpString::substr_replace',
194 'utf8_ltrim' => 'dokuwiki\Utf8\PhpString::ltrim',
195 'utf8_rtrim' => 'dokuwiki\Utf8\PhpString::rtrim',
196 'utf8_trim' => 'dokuwiki\Utf8\PhpString::trim',
197 'utf8_strtolower' => 'dokuwiki\Utf8\PhpString::strtolower',
198 'utf8_strtoupper' => 'dokuwiki\Utf8\PhpString::strtoupper',
199 'utf8_ucfirst' => 'dokuwiki\Utf8\PhpString::ucfirst',
200 'utf8_ucwords' => 'dokuwiki\Utf8\PhpString::ucwords',
201 'utf8_deaccent' => 'dokuwiki\Utf8\Clean::deaccent',
202 'utf8_romanize' => 'dokuwiki\Utf8\Clean::romanize',
203 'utf8_stripspecials' => 'dokuwiki\Utf8\Clean::stripspecials',
204 'utf8_strpos' => 'dokuwiki\Utf8\PhpString::strpos',
205 'utf8_tohtml' => 'dokuwiki\Utf8\Conversion::toHtml',
206 'utf8_unhtml' => 'dokuwiki\Utf8\Conversion::fromHtml',
207 'utf8_to_unicode' => 'dokuwiki\Utf8\Conversion::fromUtf8',
208 'unicode_to_utf8' => 'dokuwiki\Utf8\Conversion::toUtf8',
209 'utf8_to_utf16be' => 'dokuwiki\Utf8\Conversion::toUtf16be',
210 'utf16be_to_utf8' => 'dokuwiki\Utf8\Conversion::fromUtf16be',
211 'utf8_bad_replace' => 'dokuwiki\Utf8\Clean::replaceBadBytes',
212 'utf8_correctIdx' => 'dokuwiki\Utf8\Clean::correctIdx',
215 $rectorConfig->rule(DokuWikiPtlnRector::class);
216 $rectorConfig->rule(DokuWikiRenamePrintToEcho::class);