1077b7fe2SAndreas Gohr<?php 2077b7fe2SAndreas Gohr 3077b7fe2SAndreas Gohrdeclare(strict_types=1); 4077b7fe2SAndreas Gohr 52e0b7f74SAndreas Gohrdefine('DOKU_INC', __DIR__ . '/../'); 62e0b7f74SAndreas Gohr 7f9a94e78SAndreas Gohruse dokuwiki\test\rector\DokuWikiPtlnRector; 826dfc232SAndreas Gohruse dokuwiki\test\rector\DokuWikiRenamePrintToEcho; 9077b7fe2SAndreas Gohruse Rector\Caching\ValueObject\Storage\FileCacheStorage; 101e467458SAndreas Gohruse Rector\CodeQuality\Rector\ClassMethod\ExplicitReturnNullRector; 11e2d055f5SAndreas Gohruse Rector\CodeQuality\Rector\Concat\JoinStringConcatRector; 121e467458SAndreas Gohruse Rector\CodeQuality\Rector\Equal\UseIdenticalOverEqualWithSameTypeRector; 13077b7fe2SAndreas Gohruse Rector\CodeQuality\Rector\FunctionLike\SimplifyUselessVariableRector; 14077b7fe2SAndreas Gohruse Rector\CodeQuality\Rector\If_\CombineIfRector; 151fc5061dSAndreas Gohruse Rector\CodeQuality\Rector\If_\CompleteMissingIfElseBracketRector; 16077b7fe2SAndreas Gohruse Rector\CodeQuality\Rector\If_\ExplicitBoolCompareRector; 17077b7fe2SAndreas Gohruse Rector\CodeQuality\Rector\If_\SimplifyIfElseToTernaryRector; 181490c177SAndreas Gohruse Rector\CodeQuality\Rector\If_\SimplifyIfReturnBoolRector; 19077b7fe2SAndreas Gohruse Rector\CodeQuality\Rector\Isset_\IssetOnPropertyObjectToPropertyExistsRector; 20077b7fe2SAndreas Gohruse Rector\CodingStyle\Rector\Catch_\CatchExceptionNameMatchingTypeRector; 21*093fe67eSAndreas Gohruse Rector\CodingStyle\Rector\ClassLike\NewlineBetweenClassLikeStmtsRector; 22077b7fe2SAndreas Gohruse Rector\CodingStyle\Rector\Encapsed\EncapsedStringsToSprintfRector; 236723156fSAndreas Gohruse Rector\CodingStyle\Rector\Encapsed\WrapEncapsedVariableInCurlyBracesRector; 24a469bafbSAndreas Gohruse Rector\CodingStyle\Rector\FuncCall\StrictArraySearchRector; 25077b7fe2SAndreas Gohruse Rector\CodingStyle\Rector\Stmt\NewlineAfterStatementRector; 26*093fe67eSAndreas Gohruse Rector\CodingStyle\Rector\String_\SimplifyQuoteEscapeRector; 27077b7fe2SAndreas Gohruse Rector\Config\RectorConfig; 28*093fe67eSAndreas Gohruse Rector\DeadCode\Rector\Block\ReplaceBlockToItsStmtsRector; 29ed46af86SAndreas Gohruse Rector\DeadCode\Rector\ClassMethod\RemoveUnusedConstructorParamRector; 30077b7fe2SAndreas Gohruse Rector\DeadCode\Rector\ClassMethod\RemoveUselessParamTagRector; 3105fd0e83SAndreas Gohruse Rector\DeadCode\Rector\ClassMethod\RemoveUselessReturnTagRector; 3224870174SAndreas Gohruse Rector\DeadCode\Rector\If_\RemoveAlwaysTrueIfConditionRector; 33*093fe67eSAndreas Gohruse Rector\DeadCode\Rector\If_\RemoveDeadIfBlockRector; 34bcaec9f4SAndreas Gohruse Rector\DeadCode\Rector\If_\RemoveUnusedNonEmptyArrayBeforeForeachRector; 35104a3b7cSAndreas Gohruse Rector\DeadCode\Rector\Property\RemoveUselessVarTagRector; 366723156fSAndreas Gohruse Rector\DeadCode\Rector\StaticCall\RemoveParentCallWithoutParentRector; 3724870174SAndreas Gohruse Rector\DeadCode\Rector\Stmt\RemoveUnreachableStatementRector; 386e695190SAndreas Gohruse Rector\Php71\Rector\FuncCall\RemoveExtraParametersRector; 39*093fe67eSAndreas Gohruse Rector\Php80\Rector\Class_\ClassPropertyAssignToConstructorPromotionRector; 40*093fe67eSAndreas Gohruse Rector\Php81\Rector\FuncCall\NullToStrictStringFuncCallArgRector; 41*093fe67eSAndreas Gohruse Rector\Php82\Rector\FuncCall\Utf8DecodeEncodeToMbConvertEncodingRector; 42a0aeafaaSAndreas Gohruse Rector\Renaming\Rector\FuncCall\RenameFunctionRector; 43a0aeafaaSAndreas Gohruse Rector\Renaming\Rector\Name\RenameClassRector; 44077b7fe2SAndreas Gohruse Rector\Set\ValueObject\LevelSetList; 45077b7fe2SAndreas Gohruse Rector\Set\ValueObject\SetList; 46077b7fe2SAndreas Gohruse Rector\Strict\Rector\Empty_\DisallowedEmptyRuleFixerRector; 4705fd0e83SAndreas Gohruse Rector\TypeDeclaration\Rector\ClassMethod\ReturnNeverTypeRector; 488b9fc108SAndreas Gohruse Rector\DeadCode\Rector\If_\ReduceAlwaysFalseIfOrRector; 49077b7fe2SAndreas Gohr 50077b7fe2SAndreas Gohrreturn static function (RectorConfig $rectorConfig): void { 51f9a94e78SAndreas Gohr // FIXME we may want to autoload these later 52f9a94e78SAndreas Gohr require_once __DIR__ . '/rector/DokuWikiPtlnRector.php'; 5326dfc232SAndreas Gohr require_once __DIR__ . '/rector/DokuWikiRenamePrintToEcho.php'; 54f9a94e78SAndreas Gohr 55462a5601SAndreas Gohr // tune parallel task settings (see rectorphp/rector#8396) 56462a5601SAndreas Gohr $rectorConfig->parallel(120, 16, 10); 57462a5601SAndreas Gohr 58077b7fe2SAndreas Gohr $rectorConfig->paths([ 59b1f206e1SAndreas Gohr __DIR__ . '/../inc/', 60b1f206e1SAndreas Gohr __DIR__ . '/../lib/', 61b1f206e1SAndreas Gohr __DIR__ . '/../bin/', 62b1f206e1SAndreas Gohr __DIR__ . '/../*.php', 63077b7fe2SAndreas Gohr ]); 64077b7fe2SAndreas Gohr 651490c177SAndreas Gohr $rectorConfig->bootstrapFiles([ 6624870174SAndreas Gohr __DIR__ . '/../inc/init.php', 671490c177SAndreas Gohr ]); 681490c177SAndreas Gohr 69077b7fe2SAndreas Gohr $rectorConfig->importNames(); 70077b7fe2SAndreas Gohr $rectorConfig->importShortClasses(false); 71077b7fe2SAndreas Gohr $rectorConfig->cacheClass(FileCacheStorage::class); 72077b7fe2SAndreas Gohr $rectorConfig->cacheDirectory(__DIR__ . '/.rector-cache'); 73077b7fe2SAndreas Gohr 7426586410SAndreas Gohr // supported minimum PHP version can be overridden by environment variable 75*093fe67eSAndreas Gohr [$major, $minor] = explode('.', $_SERVER['RECTOR_MIN_PHP'] ?? '' ?: '8.2'); 7626586410SAndreas Gohr $phpset = LevelSetList::class . '::UP_TO_PHP_' . $major . $minor; 77108f17cfSAndreas Gohr fwrite(STDERR, "Using PHP set $phpset\n"); 7826586410SAndreas Gohr 79077b7fe2SAndreas Gohr // define sets of rules 80077b7fe2SAndreas Gohr $rectorConfig->sets([ 8126586410SAndreas Gohr constant($phpset), 82077b7fe2SAndreas Gohr SetList::CODE_QUALITY, 83077b7fe2SAndreas Gohr SetList::DEAD_CODE, 84077b7fe2SAndreas Gohr SetList::CODING_STYLE, 85077b7fe2SAndreas Gohr ]); 86077b7fe2SAndreas Gohr 87077b7fe2SAndreas Gohr $rectorConfig->skip([ 88077b7fe2SAndreas Gohr // skip paths 89077b7fe2SAndreas Gohr __DIR__ . '/../inc/lang/*', 90077b7fe2SAndreas Gohr __DIR__ . '/../lib/plugins/*/_test/*', 91077b7fe2SAndreas Gohr __DIR__ . '/../lib/tpl/*/_test/*', 92077b7fe2SAndreas Gohr __DIR__ . '/../lib/plugins/*/lang/*', 93077b7fe2SAndreas Gohr __DIR__ . '/../lib/tpl/*/lang/*', 94467c1427SAndreas Gohr __DIR__ . '/../lib/plugins/*/conf/*', // maybe later 95467c1427SAndreas Gohr __DIR__ . '/../lib/tpl/*/conf/*', // maybe later 96077b7fe2SAndreas Gohr __DIR__ . '/../lib/plugins/*/vendor/*', 97077b7fe2SAndreas Gohr __DIR__ . '/../lib/tpl/*/vendor/*', 98077b7fe2SAndreas Gohr __DIR__ . '/../lib/plugins/*/skel/*', // dev plugin 9924870174SAndreas Gohr __DIR__ . '/../inc/deprecated.php', 10024870174SAndreas Gohr __DIR__ . '/../inc/form.php', 101077b7fe2SAndreas Gohr 102077b7fe2SAndreas Gohr // third party libs, not yet moved to composer 103077b7fe2SAndreas Gohr __DIR__ . '/../inc/DifferenceEngine.php', 104077b7fe2SAndreas Gohr __DIR__ . '/../inc/JpegMeta.php', 105077b7fe2SAndreas Gohr __DIR__ . '/../lib/plugins/authad/adLDAP', 106077b7fe2SAndreas Gohr 107077b7fe2SAndreas Gohr // skip rules 1081fc5061dSAndreas Gohr CompleteMissingIfElseBracketRector::class, // keep one-line guardians 109077b7fe2SAndreas Gohr SimplifyIfElseToTernaryRector::class, 110077b7fe2SAndreas Gohr NewlineAfterStatementRector::class, 111077b7fe2SAndreas Gohr CombineIfRector::class, 112077b7fe2SAndreas Gohr ExplicitBoolCompareRector::class, 113077b7fe2SAndreas Gohr IssetOnPropertyObjectToPropertyExistsRector::class, // maybe? 114*093fe67eSAndreas Gohr SimplifyQuoteEscapeRector::class, 115077b7fe2SAndreas Gohr CatchExceptionNameMatchingTypeRector::class, 116077b7fe2SAndreas Gohr EncapsedStringsToSprintfRector::class, 117077b7fe2SAndreas Gohr SimplifyUselessVariableRector::class, // seems to strip constructor property initializations 118077b7fe2SAndreas Gohr DisallowedEmptyRuleFixerRector::class, 1196723156fSAndreas Gohr RemoveParentCallWithoutParentRector::class, 1206723156fSAndreas Gohr WrapEncapsedVariableInCurlyBracesRector::class, 1211490c177SAndreas Gohr SimplifyIfReturnBoolRector::class, 122a469bafbSAndreas Gohr StrictArraySearchRector::class, // we cannot assume strict search is always wanted 123e2d055f5SAndreas Gohr JoinStringConcatRector::class, // this does not count variables, so it creates overlong lines 1246e695190SAndreas Gohr RemoveExtraParametersRector::class, // this actually broke code 125ed46af86SAndreas Gohr RemoveUnusedConstructorParamRector::class, // see rectorphp/rector#8580 126bcaec9f4SAndreas Gohr RemoveUnusedNonEmptyArrayBeforeForeachRector::class, // seems unreliable when checking on array keys 12724870174SAndreas Gohr RemoveAlwaysTrueIfConditionRector::class, // fails with if(defined(...)) constructs 128ab9790caSAndreas Gohr RemoveUnreachableStatementRector::class, // fails GOTO in authpdo -> should be rewritten with exceptions 12905fd0e83SAndreas Gohr ReturnNeverTypeRector::class, 13005fd0e83SAndreas Gohr RemoveUselessParamTagRector::class, // keep doc blocks 13105fd0e83SAndreas Gohr RemoveUselessVarTagRector::class, // keep doc blocks 13205fd0e83SAndreas Gohr RemoveUselessReturnTagRector::class, // keep doc blocks 1331e467458SAndreas Gohr ExplicitReturnNullRector::class, // we sometimes return void or string intentionally 1341e467458SAndreas Gohr UseIdenticalOverEqualWithSameTypeRector::class, // probably a good idea, maybe later 1358b9fc108SAndreas Gohr ReduceAlwaysFalseIfOrRector::class, // see rectorphp/rector#8916 136*093fe67eSAndreas Gohr NewlineBetweenClassLikeStmtsRector::class, // looks ugly 137*093fe67eSAndreas Gohr NullToStrictStringFuncCallArgRector::class, // might hide warnings we want to see explicitly 138*093fe67eSAndreas Gohr ClassPropertyAssignToConstructorPromotionRector::class, // not sure I like the syntax, maybe later 139*093fe67eSAndreas Gohr ReplaceBlockToItsStmtsRector::class, // blocks sometimes help readability 140*093fe67eSAndreas Gohr Utf8DecodeEncodeToMbConvertEncodingRector::class, // we probably want our own mapping to the UTF8/* functions 141*093fe67eSAndreas Gohr RemoveDeadIfBlockRector::class, // creates harder to read statements 142077b7fe2SAndreas Gohr ]); 143a0aeafaaSAndreas Gohr 144a0aeafaaSAndreas Gohr $rectorConfig->ruleWithConfiguration(RenameClassRector::class, [ 145a0aeafaaSAndreas Gohr // see inc/deprecated.php 146a0aeafaaSAndreas Gohr 'RemoteAccessDeniedException' => 'dokuwiki\Remote\AccessDeniedException', 147a0aeafaaSAndreas Gohr 'RemoteException' => 'dokuwiki\Remote\RemoteException', 148a0aeafaaSAndreas Gohr 'setting' => 'dokuwiki\plugin\config\core\Setting\Setting', 149a0aeafaaSAndreas Gohr 'setting_authtype' => 'dokuwiki\plugin\config\core\Setting\SettingAuthtype', 150a0aeafaaSAndreas Gohr 'setting_string' => 'dokuwiki\plugin\config\core\Setting\SettingString', 151a0aeafaaSAndreas Gohr 'PageChangelog' => 'dokuwiki\ChangeLog\PageChangeLog', 152a0aeafaaSAndreas Gohr 'MediaChangelog' => 'dokuwiki\ChangeLog\MediaChangeLog', 153a0aeafaaSAndreas Gohr 'Input' => 'dokuwiki\Input\Input', 154a0aeafaaSAndreas Gohr 'PostInput' => 'dokuwiki\Input\Post', 155a0aeafaaSAndreas Gohr 'GetInput' => 'dokuwiki\Input\Get', 156a0aeafaaSAndreas Gohr 'ServerInput' => 'dokuwiki\Input\Server', 157a0aeafaaSAndreas Gohr 'PassHash' => 'dokuwiki\PassHash', 158a0aeafaaSAndreas Gohr 'HTTPClientException' => 'dokuwiki\HTTP\HTTPClientException', 159a0aeafaaSAndreas Gohr 'HTTPClient' => 'dokuwiki\HTTP\HTTPClient', 160a0aeafaaSAndreas Gohr 'DokuHTTPClient' => 'dokuwiki\HTTP\DokuHTTPClient', 161a0aeafaaSAndreas Gohr 'Doku_Plugin_Controller' => 'dokuwiki\Extension\PluginController', 162a0aeafaaSAndreas Gohr 'Doku_Indexer' => 'dokuwiki\Search\Indexer', 163a0aeafaaSAndreas Gohr 'IXR_Client' => 'dokuwiki\Remote\IXR\Client', 164a0aeafaaSAndreas Gohr 'IXR_ClientMulticall' => 'IXR\Client\ClientMulticall', 165a0aeafaaSAndreas Gohr 'IXR_Server' => 'IXR\Server\Server', 166a0aeafaaSAndreas Gohr 'IXR_IntrospectionServer' => 'IXR\Server\IntrospectionServer', 167a0aeafaaSAndreas Gohr 'IXR_Request' => 'IXR\Request\Request', 168a0aeafaaSAndreas Gohr 'IXR_Message' => 'R\Message\Message', 169a0aeafaaSAndreas Gohr 'IXR_Error' => 'XR\Message\Error', 170a0aeafaaSAndreas Gohr 'IXR_Date' => 'IXR\DataType\Date', 171a0aeafaaSAndreas Gohr 'IXR_Base64' => 'IXR\DataType\Base64', 172a0aeafaaSAndreas Gohr 'IXR_Value' => 'IXR\DataType\Value', 173a0aeafaaSAndreas Gohr 174a0aeafaaSAndreas Gohr // see inc/legacy.php 175a0aeafaaSAndreas Gohr 'Doku_Event_Handler' => 'dokuwiki\Extension\EventHandler', 176a0aeafaaSAndreas Gohr 'Doku_Event' => 'dokuwiki\Extension\Event', 177a0aeafaaSAndreas Gohr 'DokuWiki_Action_Plugin' => 'dokuwiki\Extension\ActionPlugin', 178a0aeafaaSAndreas Gohr 'DokuWiki_Admin_Plugin' => 'dokuwiki\Extension\AdminPlugin', 179a0aeafaaSAndreas Gohr 'DokuWiki_Auth_Plugin' => 'dokuwiki\Extension\AuthPlugin', 180a0aeafaaSAndreas Gohr 'DokuWiki_CLI_Plugin' => 'dokuwiki\Extension\CLIPlugin', 181a0aeafaaSAndreas Gohr 'DokuWiki_Plugin' => 'dokuwiki\Extension\Plugin', 182a0aeafaaSAndreas Gohr 'DokuWiki_Remote_Plugin' => 'dokuwiki\Extension\RemotePlugin', 183a0aeafaaSAndreas Gohr 'DokuWiki_Syntax_Plugin' => 'dokuwiki\Extension\SyntaxPlugin', 184a0aeafaaSAndreas Gohr ]); 185a0aeafaaSAndreas Gohr 186a0aeafaaSAndreas Gohr $rectorConfig->ruleWithConfiguration(RenameFunctionRector::class, [ 187a0aeafaaSAndreas Gohr // see inc/deprecated.php 188a0aeafaaSAndreas Gohr 'Doku_Lexer_Escape' => 'dokuwiki\Parsing\Lexer\Lexer::escape', 189a0aeafaaSAndreas Gohr 190a0aeafaaSAndreas Gohr // see inc/utf8.php 191a0aeafaaSAndreas Gohr 'utf8_isASCII' => 'dokuwiki\Utf8\Clean::isASCII', 192a0aeafaaSAndreas Gohr 'utf8_strip' => 'dokuwiki\Utf8\Clean::strip', 193a0aeafaaSAndreas Gohr 'utf8_check' => 'dokuwiki\Utf8\Clean::isUtf8', 194a0aeafaaSAndreas Gohr 'utf8_basename' => 'dokuwiki\Utf8\PhpString::basename', 195a0aeafaaSAndreas Gohr 'utf8_strlen' => 'dokuwiki\Utf8\PhpString::strlen', 196a0aeafaaSAndreas Gohr 'utf8_substr' => 'dokuwiki\Utf8\PhpString::substr', 197a0aeafaaSAndreas Gohr 'utf8_substr_replace' => 'dokuwiki\Utf8\PhpString::substr_replace', 198a0aeafaaSAndreas Gohr 'utf8_ltrim' => 'dokuwiki\Utf8\PhpString::ltrim', 199a0aeafaaSAndreas Gohr 'utf8_rtrim' => 'dokuwiki\Utf8\PhpString::rtrim', 200a0aeafaaSAndreas Gohr 'utf8_trim' => 'dokuwiki\Utf8\PhpString::trim', 201a0aeafaaSAndreas Gohr 'utf8_strtolower' => 'dokuwiki\Utf8\PhpString::strtolower', 202a0aeafaaSAndreas Gohr 'utf8_strtoupper' => 'dokuwiki\Utf8\PhpString::strtoupper', 203a0aeafaaSAndreas Gohr 'utf8_ucfirst' => 'dokuwiki\Utf8\PhpString::ucfirst', 204a0aeafaaSAndreas Gohr 'utf8_ucwords' => 'dokuwiki\Utf8\PhpString::ucwords', 205a0aeafaaSAndreas Gohr 'utf8_deaccent' => 'dokuwiki\Utf8\Clean::deaccent', 206a0aeafaaSAndreas Gohr 'utf8_romanize' => 'dokuwiki\Utf8\Clean::romanize', 207a0aeafaaSAndreas Gohr 'utf8_stripspecials' => 'dokuwiki\Utf8\Clean::stripspecials', 208a0aeafaaSAndreas Gohr 'utf8_strpos' => 'dokuwiki\Utf8\PhpString::strpos', 209a0aeafaaSAndreas Gohr 'utf8_tohtml' => 'dokuwiki\Utf8\Conversion::toHtml', 210a0aeafaaSAndreas Gohr 'utf8_unhtml' => 'dokuwiki\Utf8\Conversion::fromHtml', 211a0aeafaaSAndreas Gohr 'utf8_to_unicode' => 'dokuwiki\Utf8\Conversion::fromUtf8', 212a0aeafaaSAndreas Gohr 'unicode_to_utf8' => 'dokuwiki\Utf8\Conversion::toUtf8', 213a0aeafaaSAndreas Gohr 'utf8_to_utf16be' => 'dokuwiki\Utf8\Conversion::toUtf16be', 214a0aeafaaSAndreas Gohr 'utf16be_to_utf8' => 'dokuwiki\Utf8\Conversion::fromUtf16be', 215a0aeafaaSAndreas Gohr 'utf8_bad_replace' => 'dokuwiki\Utf8\Clean::replaceBadBytes', 216a0aeafaaSAndreas Gohr 'utf8_correctIdx' => 'dokuwiki\Utf8\Clean::correctIdx', 217a0aeafaaSAndreas Gohr ]); 218f9a94e78SAndreas Gohr 219f9a94e78SAndreas Gohr $rectorConfig->rule(DokuWikiPtlnRector::class); 22026dfc232SAndreas Gohr $rectorConfig->rule(DokuWikiRenamePrintToEcho::class); 221077b7fe2SAndreas Gohr}; 222