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