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; 21093fe67eSAndreas 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; 26093fe67eSAndreas Gohruse Rector\CodingStyle\Rector\String_\SimplifyQuoteEscapeRector; 27077b7fe2SAndreas Gohruse Rector\Config\RectorConfig; 28093fe67eSAndreas 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; 33093fe67eSAndreas 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; 39093fe67eSAndreas Gohruse Rector\Php80\Rector\Class_\ClassPropertyAssignToConstructorPromotionRector; 40093fe67eSAndreas Gohruse Rector\Php81\Rector\FuncCall\NullToStrictStringFuncCallArgRector; 41093fe67eSAndreas 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; 49894c1577SAndreas Gohruse Rector\TypeDeclaration\Rector\StmtsAwareInterface\SafeDeclareStrictTypesRector; 50077b7fe2SAndreas Gohr 51077b7fe2SAndreas Gohrreturn static function (RectorConfig $rectorConfig): void { 52f9a94e78SAndreas Gohr // FIXME we may want to autoload these later 53f9a94e78SAndreas Gohr require_once __DIR__ . '/rector/DokuWikiPtlnRector.php'; 5426dfc232SAndreas Gohr require_once __DIR__ . '/rector/DokuWikiRenamePrintToEcho.php'; 55f9a94e78SAndreas Gohr 56462a5601SAndreas Gohr // tune parallel task settings (see rectorphp/rector#8396) 57462a5601SAndreas Gohr $rectorConfig->parallel(120, 16, 10); 58462a5601SAndreas Gohr 59077b7fe2SAndreas Gohr $rectorConfig->paths([ 60b1f206e1SAndreas Gohr __DIR__ . '/../inc/', 61b1f206e1SAndreas Gohr __DIR__ . '/../lib/', 62b1f206e1SAndreas Gohr __DIR__ . '/../bin/', 63b1f206e1SAndreas Gohr __DIR__ . '/../*.php', 64077b7fe2SAndreas Gohr ]); 65077b7fe2SAndreas Gohr 661490c177SAndreas Gohr $rectorConfig->bootstrapFiles([ 6724870174SAndreas Gohr __DIR__ . '/../inc/init.php', 681490c177SAndreas Gohr ]); 691490c177SAndreas Gohr 70077b7fe2SAndreas Gohr $rectorConfig->importNames(); 71077b7fe2SAndreas Gohr $rectorConfig->importShortClasses(false); 72077b7fe2SAndreas Gohr $rectorConfig->cacheClass(FileCacheStorage::class); 73077b7fe2SAndreas Gohr $rectorConfig->cacheDirectory(__DIR__ . '/.rector-cache'); 74077b7fe2SAndreas Gohr 7526586410SAndreas Gohr // supported minimum PHP version can be overridden by environment variable 76093fe67eSAndreas Gohr [$major, $minor] = explode('.', $_SERVER['RECTOR_MIN_PHP'] ?? '' ?: '8.2'); 7726586410SAndreas Gohr $phpset = LevelSetList::class . '::UP_TO_PHP_' . $major . $minor; 78108f17cfSAndreas Gohr fwrite(STDERR, "Using PHP set $phpset\n"); 7926586410SAndreas Gohr 80077b7fe2SAndreas Gohr // define sets of rules 81077b7fe2SAndreas Gohr $rectorConfig->sets([ 8226586410SAndreas Gohr constant($phpset), 83077b7fe2SAndreas Gohr SetList::CODE_QUALITY, 84077b7fe2SAndreas Gohr SetList::DEAD_CODE, 85077b7fe2SAndreas Gohr SetList::CODING_STYLE, 86077b7fe2SAndreas Gohr ]); 87077b7fe2SAndreas Gohr 88077b7fe2SAndreas Gohr $rectorConfig->skip([ 89077b7fe2SAndreas Gohr // skip paths 90077b7fe2SAndreas Gohr __DIR__ . '/../inc/lang/*', 91077b7fe2SAndreas Gohr __DIR__ . '/../lib/plugins/*/_test/*', 92077b7fe2SAndreas Gohr __DIR__ . '/../lib/tpl/*/_test/*', 93077b7fe2SAndreas Gohr __DIR__ . '/../lib/plugins/*/lang/*', 94077b7fe2SAndreas Gohr __DIR__ . '/../lib/tpl/*/lang/*', 95467c1427SAndreas Gohr __DIR__ . '/../lib/plugins/*/conf/*', // maybe later 96467c1427SAndreas Gohr __DIR__ . '/../lib/tpl/*/conf/*', // maybe later 97077b7fe2SAndreas Gohr __DIR__ . '/../lib/plugins/*/vendor/*', 98077b7fe2SAndreas Gohr __DIR__ . '/../lib/tpl/*/vendor/*', 99077b7fe2SAndreas Gohr __DIR__ . '/../lib/plugins/*/skel/*', // dev plugin 10024870174SAndreas Gohr __DIR__ . '/../inc/deprecated.php', 10124870174SAndreas Gohr __DIR__ . '/../inc/form.php', 102077b7fe2SAndreas Gohr 103077b7fe2SAndreas Gohr // third party libs, not yet moved to composer 104077b7fe2SAndreas Gohr __DIR__ . '/../inc/DifferenceEngine.php', 105077b7fe2SAndreas Gohr __DIR__ . '/../inc/JpegMeta.php', 106077b7fe2SAndreas Gohr __DIR__ . '/../lib/plugins/authad/adLDAP', 107077b7fe2SAndreas Gohr 108077b7fe2SAndreas Gohr // skip rules 1091fc5061dSAndreas Gohr CompleteMissingIfElseBracketRector::class, // keep one-line guardians 110077b7fe2SAndreas Gohr SimplifyIfElseToTernaryRector::class, 111077b7fe2SAndreas Gohr NewlineAfterStatementRector::class, 112077b7fe2SAndreas Gohr CombineIfRector::class, 113077b7fe2SAndreas Gohr ExplicitBoolCompareRector::class, 114077b7fe2SAndreas Gohr IssetOnPropertyObjectToPropertyExistsRector::class, // maybe? 115093fe67eSAndreas Gohr SimplifyQuoteEscapeRector::class, 116077b7fe2SAndreas Gohr CatchExceptionNameMatchingTypeRector::class, 117077b7fe2SAndreas Gohr EncapsedStringsToSprintfRector::class, 118077b7fe2SAndreas Gohr SimplifyUselessVariableRector::class, // seems to strip constructor property initializations 119077b7fe2SAndreas Gohr DisallowedEmptyRuleFixerRector::class, 1206723156fSAndreas Gohr RemoveParentCallWithoutParentRector::class, 1216723156fSAndreas Gohr WrapEncapsedVariableInCurlyBracesRector::class, 1221490c177SAndreas Gohr SimplifyIfReturnBoolRector::class, 123a469bafbSAndreas Gohr StrictArraySearchRector::class, // we cannot assume strict search is always wanted 124e2d055f5SAndreas Gohr JoinStringConcatRector::class, // this does not count variables, so it creates overlong lines 1256e695190SAndreas Gohr RemoveExtraParametersRector::class, // this actually broke code 126ed46af86SAndreas Gohr RemoveUnusedConstructorParamRector::class, // see rectorphp/rector#8580 127bcaec9f4SAndreas Gohr RemoveUnusedNonEmptyArrayBeforeForeachRector::class, // seems unreliable when checking on array keys 12824870174SAndreas Gohr RemoveAlwaysTrueIfConditionRector::class, // fails with if(defined(...)) constructs 129ab9790caSAndreas Gohr RemoveUnreachableStatementRector::class, // fails GOTO in authpdo -> should be rewritten with exceptions 13005fd0e83SAndreas Gohr ReturnNeverTypeRector::class, 13105fd0e83SAndreas Gohr RemoveUselessParamTagRector::class, // keep doc blocks 13205fd0e83SAndreas Gohr RemoveUselessVarTagRector::class, // keep doc blocks 13305fd0e83SAndreas Gohr RemoveUselessReturnTagRector::class, // keep doc blocks 1341e467458SAndreas Gohr ExplicitReturnNullRector::class, // we sometimes return void or string intentionally 1351e467458SAndreas Gohr UseIdenticalOverEqualWithSameTypeRector::class, // probably a good idea, maybe later 1368b9fc108SAndreas Gohr ReduceAlwaysFalseIfOrRector::class, // see rectorphp/rector#8916 137093fe67eSAndreas Gohr NewlineBetweenClassLikeStmtsRector::class, // looks ugly 138093fe67eSAndreas Gohr NullToStrictStringFuncCallArgRector::class, // might hide warnings we want to see explicitly 139093fe67eSAndreas Gohr ClassPropertyAssignToConstructorPromotionRector::class, // not sure I like the syntax, maybe later 140093fe67eSAndreas Gohr ReplaceBlockToItsStmtsRector::class, // blocks sometimes help readability 141093fe67eSAndreas Gohr Utf8DecodeEncodeToMbConvertEncodingRector::class, // we probably want our own mapping to the UTF8/* functions 142093fe67eSAndreas Gohr RemoveDeadIfBlockRector::class, // creates harder to read statements 143894c1577SAndreas Gohr 144894c1577SAndreas Gohr // we're not ready for full type safety. though this rule is probably safe I am not comfortable to add it yet 145894c1577SAndreas Gohr // https://getrector.com/blog/introducing-safe-and-progressive-strict-type-adoption-rule 146894c1577SAndreas Gohr SafeDeclareStrictTypesRector::class, 147077b7fe2SAndreas Gohr ]); 148a0aeafaaSAndreas Gohr 149a0aeafaaSAndreas Gohr $rectorConfig->ruleWithConfiguration(RenameClassRector::class, [ 150a0aeafaaSAndreas Gohr // see inc/deprecated.php 151a0aeafaaSAndreas Gohr 'RemoteAccessDeniedException' => 'dokuwiki\Remote\AccessDeniedException', 152a0aeafaaSAndreas Gohr 'RemoteException' => 'dokuwiki\Remote\RemoteException', 153a0aeafaaSAndreas Gohr 'setting' => 'dokuwiki\plugin\config\core\Setting\Setting', 154a0aeafaaSAndreas Gohr 'setting_authtype' => 'dokuwiki\plugin\config\core\Setting\SettingAuthtype', 155a0aeafaaSAndreas Gohr 'setting_string' => 'dokuwiki\plugin\config\core\Setting\SettingString', 156a0aeafaaSAndreas Gohr 'PageChangelog' => 'dokuwiki\ChangeLog\PageChangeLog', 157a0aeafaaSAndreas Gohr 'MediaChangelog' => 'dokuwiki\ChangeLog\MediaChangeLog', 158a0aeafaaSAndreas Gohr 'Input' => 'dokuwiki\Input\Input', 159a0aeafaaSAndreas Gohr 'PostInput' => 'dokuwiki\Input\Post', 160a0aeafaaSAndreas Gohr 'GetInput' => 'dokuwiki\Input\Get', 161a0aeafaaSAndreas Gohr 'ServerInput' => 'dokuwiki\Input\Server', 162a0aeafaaSAndreas Gohr 'PassHash' => 'dokuwiki\PassHash', 163a0aeafaaSAndreas Gohr 'HTTPClientException' => 'dokuwiki\HTTP\HTTPClientException', 164a0aeafaaSAndreas Gohr 'HTTPClient' => 'dokuwiki\HTTP\HTTPClient', 165a0aeafaaSAndreas Gohr 'DokuHTTPClient' => 'dokuwiki\HTTP\DokuHTTPClient', 166a0aeafaaSAndreas Gohr 'Doku_Plugin_Controller' => 'dokuwiki\Extension\PluginController', 167a0aeafaaSAndreas Gohr 'Doku_Indexer' => 'dokuwiki\Search\Indexer', 168a0aeafaaSAndreas Gohr 'IXR_Client' => 'dokuwiki\Remote\IXR\Client', 169a0aeafaaSAndreas Gohr 'IXR_ClientMulticall' => 'IXR\Client\ClientMulticall', 170a0aeafaaSAndreas Gohr 'IXR_Server' => 'IXR\Server\Server', 171a0aeafaaSAndreas Gohr 'IXR_IntrospectionServer' => 'IXR\Server\IntrospectionServer', 172a0aeafaaSAndreas Gohr 'IXR_Request' => 'IXR\Request\Request', 173a0aeafaaSAndreas Gohr 'IXR_Message' => 'R\Message\Message', 174a0aeafaaSAndreas Gohr 'IXR_Error' => 'XR\Message\Error', 175a0aeafaaSAndreas Gohr 'IXR_Date' => 'IXR\DataType\Date', 176a0aeafaaSAndreas Gohr 'IXR_Base64' => 'IXR\DataType\Base64', 177a0aeafaaSAndreas Gohr 'IXR_Value' => 'IXR\DataType\Value', 178a0aeafaaSAndreas Gohr 179a0aeafaaSAndreas Gohr // see inc/legacy.php 180a0aeafaaSAndreas Gohr 'Doku_Event_Handler' => 'dokuwiki\Extension\EventHandler', 181a0aeafaaSAndreas Gohr 'Doku_Event' => 'dokuwiki\Extension\Event', 182a0aeafaaSAndreas Gohr 'DokuWiki_Action_Plugin' => 'dokuwiki\Extension\ActionPlugin', 183a0aeafaaSAndreas Gohr 'DokuWiki_Admin_Plugin' => 'dokuwiki\Extension\AdminPlugin', 184a0aeafaaSAndreas Gohr 'DokuWiki_Auth_Plugin' => 'dokuwiki\Extension\AuthPlugin', 185a0aeafaaSAndreas Gohr 'DokuWiki_CLI_Plugin' => 'dokuwiki\Extension\CLIPlugin', 186a0aeafaaSAndreas Gohr 'DokuWiki_Plugin' => 'dokuwiki\Extension\Plugin', 187a0aeafaaSAndreas Gohr 'DokuWiki_Remote_Plugin' => 'dokuwiki\Extension\RemotePlugin', 188a0aeafaaSAndreas Gohr 'DokuWiki_Syntax_Plugin' => 'dokuwiki\Extension\SyntaxPlugin', 189*71096e46SAndreas Gohr 'Doku_Handler' => 'dokuwiki\Parsing\Handler', 190a0aeafaaSAndreas Gohr ]); 191a0aeafaaSAndreas Gohr 192a0aeafaaSAndreas Gohr $rectorConfig->ruleWithConfiguration(RenameFunctionRector::class, [ 193a0aeafaaSAndreas Gohr // see inc/deprecated.php 194a0aeafaaSAndreas Gohr 'Doku_Lexer_Escape' => 'dokuwiki\Parsing\Lexer\Lexer::escape', 195*71096e46SAndreas Gohr 'Doku_Handler_Parse_Media' => 'dokuwiki\Parsing\ParserMode\Media::parseMedia', 196a0aeafaaSAndreas Gohr 197a0aeafaaSAndreas Gohr // see inc/utf8.php 198a0aeafaaSAndreas Gohr 'utf8_isASCII' => 'dokuwiki\Utf8\Clean::isASCII', 199a0aeafaaSAndreas Gohr 'utf8_strip' => 'dokuwiki\Utf8\Clean::strip', 200a0aeafaaSAndreas Gohr 'utf8_check' => 'dokuwiki\Utf8\Clean::isUtf8', 201a0aeafaaSAndreas Gohr 'utf8_basename' => 'dokuwiki\Utf8\PhpString::basename', 202a0aeafaaSAndreas Gohr 'utf8_strlen' => 'dokuwiki\Utf8\PhpString::strlen', 203a0aeafaaSAndreas Gohr 'utf8_substr' => 'dokuwiki\Utf8\PhpString::substr', 204a0aeafaaSAndreas Gohr 'utf8_substr_replace' => 'dokuwiki\Utf8\PhpString::substr_replace', 205a0aeafaaSAndreas Gohr 'utf8_ltrim' => 'dokuwiki\Utf8\PhpString::ltrim', 206a0aeafaaSAndreas Gohr 'utf8_rtrim' => 'dokuwiki\Utf8\PhpString::rtrim', 207a0aeafaaSAndreas Gohr 'utf8_trim' => 'dokuwiki\Utf8\PhpString::trim', 208a0aeafaaSAndreas Gohr 'utf8_strtolower' => 'dokuwiki\Utf8\PhpString::strtolower', 209a0aeafaaSAndreas Gohr 'utf8_strtoupper' => 'dokuwiki\Utf8\PhpString::strtoupper', 210a0aeafaaSAndreas Gohr 'utf8_ucfirst' => 'dokuwiki\Utf8\PhpString::ucfirst', 211a0aeafaaSAndreas Gohr 'utf8_ucwords' => 'dokuwiki\Utf8\PhpString::ucwords', 212a0aeafaaSAndreas Gohr 'utf8_deaccent' => 'dokuwiki\Utf8\Clean::deaccent', 213a0aeafaaSAndreas Gohr 'utf8_romanize' => 'dokuwiki\Utf8\Clean::romanize', 214a0aeafaaSAndreas Gohr 'utf8_stripspecials' => 'dokuwiki\Utf8\Clean::stripspecials', 215a0aeafaaSAndreas Gohr 'utf8_strpos' => 'dokuwiki\Utf8\PhpString::strpos', 216a0aeafaaSAndreas Gohr 'utf8_tohtml' => 'dokuwiki\Utf8\Conversion::toHtml', 217a0aeafaaSAndreas Gohr 'utf8_unhtml' => 'dokuwiki\Utf8\Conversion::fromHtml', 218a0aeafaaSAndreas Gohr 'utf8_to_unicode' => 'dokuwiki\Utf8\Conversion::fromUtf8', 219a0aeafaaSAndreas Gohr 'unicode_to_utf8' => 'dokuwiki\Utf8\Conversion::toUtf8', 220a0aeafaaSAndreas Gohr 'utf8_to_utf16be' => 'dokuwiki\Utf8\Conversion::toUtf16be', 221a0aeafaaSAndreas Gohr 'utf16be_to_utf8' => 'dokuwiki\Utf8\Conversion::fromUtf16be', 222a0aeafaaSAndreas Gohr 'utf8_bad_replace' => 'dokuwiki\Utf8\Clean::replaceBadBytes', 223a0aeafaaSAndreas Gohr 'utf8_correctIdx' => 'dokuwiki\Utf8\Clean::correctIdx', 224a0aeafaaSAndreas Gohr ]); 225f9a94e78SAndreas Gohr 226f9a94e78SAndreas Gohr $rectorConfig->rule(DokuWikiPtlnRector::class); 22726dfc232SAndreas Gohr $rectorConfig->rule(DokuWikiRenamePrintToEcho::class); 228077b7fe2SAndreas Gohr}; 229