[ Index ]

PHP Cross Reference of DokuWiki

title

Body

[close]

/_test/ -> rector.php (source)

   1  <?php
   2  
   3  declare(strict_types=1);
   4  
   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\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\TypeDeclaration\Rector\Property\TypedPropertyFromAssignsRector;
  44  
  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';
  49  
  50      // tune parallel task settings (see rectorphp/rector#8396)
  51      $rectorConfig->parallel(120, 16, 10);
  52  
  53      $rectorConfig->paths([
  54          __DIR__ . '/../inc/',
  55          __DIR__ . '/../lib/',
  56          __DIR__ . '/../bin/',
  57          __DIR__ . '/../*.php',
  58      ]);
  59  
  60      $rectorConfig->bootstrapFiles([
  61          __DIR__ . '/../inc/init.php',
  62      ]);
  63  
  64      $rectorConfig->importNames();
  65      $rectorConfig->importShortClasses(false);
  66      $rectorConfig->cacheClass(FileCacheStorage::class);
  67      $rectorConfig->cacheDirectory(__DIR__ . '/.rector-cache');
  68  
  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");
  73  
  74      // define sets of rules
  75      $rectorConfig->sets([
  76          constant($phpset),
  77          SetList::CODE_QUALITY,
  78          SetList::DEAD_CODE,
  79          SetList::CODING_STYLE,
  80      ]);
  81  
  82      // future rules for which we have polyfills
  83      $rectorConfig->rule(StrContainsRector::class);
  84      $rectorConfig->rule(StrEndsWithRector::class);
  85      $rectorConfig->rule(StrStartsWithRector::class);
  86  
  87      $rectorConfig->skip([
  88          // skip paths
  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',
 101  
 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',
 106  
 107          // skip rules
 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          CallableThisArrayToAnonymousFunctionRector::class,
 118          StaticClosureRector::class,
 119          SimplifyUselessVariableRector::class, // seems to strip constructor property initializations
 120          PostIncDecToPreIncDecRector::class,
 121          DisallowedEmptyRuleFixerRector::class,
 122          RemoveParentCallWithoutParentRector::class,
 123          WrapEncapsedVariableInCurlyBracesRector::class,
 124          SimplifyIfReturnBoolRector::class,
 125          StrictArraySearchRector::class, // we cannot assume strict search is always wanted
 126          TypedPropertyFromAssignsRector::class, // maybe?
 127          JoinStringConcatRector::class, // this does not count variables, so it creates overlong lines
 128          RemoveExtraParametersRector::class, // this actually broke code
 129          RemoveUnusedNonEmptyArrayBeforeForeachRector::class, // seems unreliable when checking on array keys
 130          RemoveAlwaysTrueIfConditionRector::class, // fails with if(defined(...)) constructs
 131          RemoveUnreachableStatementRector::class, // fails GOTO in authpdo -> should be rewritten with exceptions
 132          ReturnNeverTypeRector::class,
 133          RemoveUselessParamTagRector::class, // keep doc blocks
 134          RemoveUselessVarTagRector::class, // keep doc blocks
 135          RemoveUselessReturnTagRector::class, // keep doc blocks
 136      ]);
 137  
 138      $rectorConfig->ruleWithConfiguration(RenameClassRector::class, [
 139          // see inc/deprecated.php
 140          'RemoteAccessDeniedException' => 'dokuwiki\Remote\AccessDeniedException',
 141          'RemoteException' => 'dokuwiki\Remote\RemoteException',
 142          'setting' => 'dokuwiki\plugin\config\core\Setting\Setting',
 143          'setting_authtype' => 'dokuwiki\plugin\config\core\Setting\SettingAuthtype',
 144          'setting_string' => 'dokuwiki\plugin\config\core\Setting\SettingString',
 145          'PageChangelog' => 'dokuwiki\ChangeLog\PageChangeLog',
 146          'MediaChangelog' => 'dokuwiki\ChangeLog\MediaChangeLog',
 147          'Input' => 'dokuwiki\Input\Input',
 148          'PostInput' => 'dokuwiki\Input\Post',
 149          'GetInput' => 'dokuwiki\Input\Get',
 150          'ServerInput' => 'dokuwiki\Input\Server',
 151          'PassHash' => 'dokuwiki\PassHash',
 152          'HTTPClientException' => 'dokuwiki\HTTP\HTTPClientException',
 153          'HTTPClient' => 'dokuwiki\HTTP\HTTPClient',
 154          'DokuHTTPClient' => 'dokuwiki\HTTP\DokuHTTPClient',
 155          'Doku_Plugin_Controller' => 'dokuwiki\Extension\PluginController',
 156          'Doku_Indexer' => 'dokuwiki\Search\Indexer',
 157          'IXR_Client' => 'dokuwiki\Remote\IXR\Client',
 158          'IXR_ClientMulticall' => 'IXR\Client\ClientMulticall',
 159          'IXR_Server' => 'IXR\Server\Server',
 160          'IXR_IntrospectionServer' => 'IXR\Server\IntrospectionServer',
 161          'IXR_Request' => 'IXR\Request\Request',
 162          'IXR_Message' => 'R\Message\Message',
 163          'IXR_Error' => 'XR\Message\Error',
 164          'IXR_Date' => 'IXR\DataType\Date',
 165          'IXR_Base64' => 'IXR\DataType\Base64',
 166          'IXR_Value' => 'IXR\DataType\Value',
 167  
 168          // see inc/legacy.php
 169          'Doku_Event_Handler' => 'dokuwiki\Extension\EventHandler',
 170          'Doku_Event' => 'dokuwiki\Extension\Event',
 171          'DokuWiki_Action_Plugin' => 'dokuwiki\Extension\ActionPlugin',
 172          'DokuWiki_Admin_Plugin' => 'dokuwiki\Extension\AdminPlugin',
 173          'DokuWiki_Auth_Plugin' => 'dokuwiki\Extension\AuthPlugin',
 174          'DokuWiki_CLI_Plugin' => 'dokuwiki\Extension\CLIPlugin',
 175          'DokuWiki_Plugin' => 'dokuwiki\Extension\Plugin',
 176          'DokuWiki_Remote_Plugin' => 'dokuwiki\Extension\RemotePlugin',
 177          'DokuWiki_Syntax_Plugin' => 'dokuwiki\Extension\SyntaxPlugin',
 178      ]);
 179  
 180      $rectorConfig->ruleWithConfiguration(RenameFunctionRector::class, [
 181          // see inc/deprecated.php
 182          'Doku_Lexer_Escape' => 'dokuwiki\Parsing\Lexer\Lexer::escape',
 183  
 184          // see inc/utf8.php
 185          'utf8_isASCII' => 'dokuwiki\Utf8\Clean::isASCII',
 186          'utf8_strip' => 'dokuwiki\Utf8\Clean::strip',
 187          'utf8_check' => 'dokuwiki\Utf8\Clean::isUtf8',
 188          'utf8_basename' => 'dokuwiki\Utf8\PhpString::basename',
 189          'utf8_strlen' => 'dokuwiki\Utf8\PhpString::strlen',
 190          'utf8_substr' => 'dokuwiki\Utf8\PhpString::substr',
 191          'utf8_substr_replace' => 'dokuwiki\Utf8\PhpString::substr_replace',
 192          'utf8_ltrim' => 'dokuwiki\Utf8\PhpString::ltrim',
 193          'utf8_rtrim' => 'dokuwiki\Utf8\PhpString::rtrim',
 194          'utf8_trim' => 'dokuwiki\Utf8\PhpString::trim',
 195          'utf8_strtolower' => 'dokuwiki\Utf8\PhpString::strtolower',
 196          'utf8_strtoupper' => 'dokuwiki\Utf8\PhpString::strtoupper',
 197          'utf8_ucfirst' => 'dokuwiki\Utf8\PhpString::ucfirst',
 198          'utf8_ucwords' => 'dokuwiki\Utf8\PhpString::ucwords',
 199          'utf8_deaccent' => 'dokuwiki\Utf8\Clean::deaccent',
 200          'utf8_romanize' => 'dokuwiki\Utf8\Clean::romanize',
 201          'utf8_stripspecials' => 'dokuwiki\Utf8\Clean::stripspecials',
 202          'utf8_strpos' => 'dokuwiki\Utf8\PhpString::strpos',
 203          'utf8_tohtml' => 'dokuwiki\Utf8\Conversion::toHtml',
 204          'utf8_unhtml' => 'dokuwiki\Utf8\Conversion::fromHtml',
 205          'utf8_to_unicode' => 'dokuwiki\Utf8\Conversion::fromUtf8',
 206          'unicode_to_utf8' => 'dokuwiki\Utf8\Conversion::toUtf8',
 207          'utf8_to_utf16be' => 'dokuwiki\Utf8\Conversion::toUtf16be',
 208          'utf16be_to_utf8' => 'dokuwiki\Utf8\Conversion::fromUtf16be',
 209          'utf8_bad_replace' => 'dokuwiki\Utf8\Clean::replaceBadBytes',
 210          'utf8_correctIdx' => 'dokuwiki\Utf8\Clean::correctIdx',
 211      ]);
 212  
 213      $rectorConfig->rule(DokuWikiPtlnRector::class);
 214      $rectorConfig->rule(DokuWikiRenamePrintToEcho::class);
 215  };