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