Skip to content

3. Rule reference (what each rule is for)

github-actions[bot] edited this page Jun 8, 2026 · 2 revisions

3. Rule reference (what each rule is for)

There are 22 custom rules in src/Rules/ plus several configured built-in Rector rules. The default set (config/sets/xoops.php) registers the behaviour-preserving ones; the risky set (config/sets/xoops-risky.php) the behaviour-changing ones. For the exact, authoritative list, read the two set files — this section explains them by domain.

3.1 Database API (XOOPS 2.7)

XOOPS 2.7 splits the old queryF() into query() (reads, returns a result) and exec() (writes, returns bool). quoteString()quote(). The legacy mysql_* / mysqli_* functions are gone.

Rule Before → After Notes
MysqlFunctionToXoopsDbRector mysql_query("SELECT …")$GLOBALS['xoopsDB']->query(…); mysql_query("UPDATE …")…->exec(…); mysqli_error($link)…->error() Routes *_query to query/exec by the SQL keyword; drops the $link arg for connection-first mysqli_*.
QueryFToQueryOrExecRector $db->queryF("SELECT …")$db->query(…); $db->queryF("DELETE …")$db->exec(…) Same keyword routing for explicit queryF(). A flat queryFexec would break SELECTs.
MysqlSelectDbToXoopsDbRector mysql_select_db($n)mysqli_select_db($GLOBALS['xoopsDB']->conn, $n) Fixes a removed PHP-7 function.
HandlerConstructorDbTypeRector function __construct($db)function __construct(\XoopsDatabase $db) Only on classes extending XoopsPersistableObjectHandler/XoopsObjectHandler (matches the parent signature).
built-in RenameMethodRector (typed) XoopsMySQLDatabase/XoopsDatabase::quoteString()quote(); XoopsObject::makeTareaData4Show()displayTarea() Configured in the set.

The SQL keyword classification is shared via the Xoops\Rector\Support\SqlKeywordDetector trait.

3.2 Removed / deprecated PHP

Rule Before → After
RenameLegacyHttpVarsRector $HTTP_POST_VARS$_POST (and _GET/_SERVER/_COOKIE/…)
SessionIsRegisteredToIssetRector session_is_registered($k)isset($_SESSION[$k])
GetMagicQuotesGpcToFalseRector get_magic_quotes_gpc()false (replaces the call only; dead if (false) branches may then be removed by your PHP/dead-code sets)
UniqidMtRandStrictRector uniqid(mt_rand(), 1)uniqid((string) mt_rand(), true)
RemoveFuncCallRector (configurable) drops statement-level mt_srand() / imagedestroy()
DropReferenceFromAssignmentRector $x =& foo() / =& new / =& Class::m()$x = … (call/new RHS only)
StaticStringCallableToArrayRector 'static::m'[static::class, 'm'] (PHP 8.5)
AddAllowedClassesToUnserializeRector unserialize($x)unserialize($x, ['allowed_classes' => false])
BooleanLiteralStrictComparisonRector == true/false/null=== … (both directions)
built-in MultiDirnameRector dirname(dirname(dirname(__DIR__)))dirname(__DIR__, 3)
built-in AbsolutizeRequireAndIncludePathRector require './foo.php'require __DIR__ . '/foo.php'

3.3 XOOPS framework API

Rule Before → After
GlobalXoopsOptionRector $xoopsOption['template_main'] = …$GLOBALS['xoopsOption']['template_main'] = …
KernelIncludePathRector moved kernel include paths: class/xoopsobject.phpkernel/object.php, class/xoopsmodule.phpkernel/module.php (include paths only)
NewModuleAdminToXmfRector new ModuleAdmin()\Xmf\Module\Admin::getInstance()
built-in RenameFunctionRector xoops_gethandlerxoops_getHandler, xoops_getmodulehandlerxoops_getModuleHandler, set_errorHandlerset_error_handler, restore_errorHandlerrestore_error_handler, set_exceptionHandlerset_exception_handler
built-in FuncCallToStaticCallRector xoops_refcheck()XoopsSecurity::checkReferer(), xoops_getLinkedUnameFromId()XoopsUserUtility::getUnameFromId()
built-in RenameStaticMethodRector Database::getInstance()XoopsDatabaseFactory::getDatabaseConnection()
built-in FunctionArgumentDefaultValueReplacerRector xoops_load('cache')xoops_load('xoopscache')

3.4 MyTextSanitizer & Smarty (method renames)

RenameMethodCallByNameRector (name-only, for untyped receivers) carries these maps in the default set:

  • quoteStringquote (the XOOPS DB value-quoter rename).
  • MyTextSanitizer deprecated methods → current API: makeTarea*/makeTbox*/sanitizeFor*/oops*displayTarea/previewTarea/htmlSpecialChars/addSlashes/stripSlashesGPC/nl2Br.
  • Smarty 2 → 4 PHP API: assign_by_refassignByRef, clear_compiled_tplclearCompiledTemplate, is_cachedisCached, get_template_varsgetTemplateVars, … — these are the Smarty 4 forms. (The further Smarty-4→5 step, e.g. assignByRefassign, is a separate, future opt-in set — see §3.6.)

RenameMethodWithAddedFirstArgRector handles the Smarty dispatcher migration (rename + prepend a literal arg): register_function(…)registerPlugin('function', …), register_prefilter(…)registerFilter('pre', …), and the block/modifier/compiler/postfilter/outputfilter variants.

ModuleAdmin render*display* — opt-in (NOT in the default set)

\Xmf\Module\Admin (and legacy ModuleAdmin) has both renderX() (returns a string) and displayX() (echoes, returns void). A name-only renderIndexdisplayIndex / renderButtondisplayButton rename is only safe when the result is echoed or discarded — it breaks any site that captures the return value ($html = $admin->renderButton(...)). Because that is not behaviour-preserving, it is deliberately left out of the default set. Enable it per-module after checking your call sites:

use Xoops\Rector\Rules\RenameMethodCallByNameRector;

return RectorConfig::configure()
    // … your paths / sets …
    ->withConfiguredRule(RenameMethodCallByNameRector::class, [
        'renderIndex'  => 'displayIndex',
        'renderButton' => 'displayButton',
    ]);

3.5 Risky set (opt-in, behaviour-changing)

These ship in XoopsSetList::XOOPS_RISKY because they change runtime values/output. The MyTS rules are receiver-aware (only $myts / $GLOBALS['myts'], via the MytsReceiverDetector trait).

Rule Before → After Why it's risky
ServerSuperglobalToXmfRequestRector (configurable) $_SERVER['HTTP_REFERER']\Xmf\Request::getString('HTTP_REFERER', '', 'SERVER') raw → filtered
RemoveDeadMytsStripSlashesRector $myts->stripSlashesGPC($x)$x no-op on 7.4+, but depends on the MyTS build
MytsAddSlashesToDbEscapeRector $myts->addSlashes($x)$GLOBALS['xoopsDB']->escape($x) only valid in a SQL context
MytsHtmlSpecialCharsToNativeRector $myts->htmlSpecialChars($x)htmlspecialchars($x, ENT_QUOTES | ENT_SUBSTITUTE, _CHARSET) may change entity handling

3.6 Planned: XOOPS_SMARTY5 (future opt-in set)

The Smarty 4 → 5 PHP-API changes (assignByRefassign, appendByRefappend, the property→setter moves like template_dir = …setTemplateDir(…), removed constants) are not shipped yet — XOOPS 2.7.x runs Smarty 4, so applying them prematurely would break working code. They are planned as a gated XoopsSetList::XOOPS_SMARTY5 set, enabled only when the core engine actually moves to Smarty 5. This constant does not exist yet — there is no XOOPS_SMARTY5 in XoopsSetList, so don't go looking for it; the note is here to set expectations, not to document a shipped feature.