-
Notifications
You must be signed in to change notification settings - Fork 1
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.
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 queryF→exec 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.
| 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'
|
| Rule | Before → After |
|---|---|
GlobalXoopsOptionRector |
$xoopsOption['template_main'] = … → $GLOBALS['xoopsOption']['template_main'] = …
|
KernelIncludePathRector |
moved kernel include paths: class/xoopsobject.php→kernel/object.php, class/xoopsmodule.php→kernel/module.php (include paths only) |
NewModuleAdminToXmfRector |
new ModuleAdmin() → \Xmf\Module\Admin::getInstance()
|
built-in RenameFunctionRector
|
xoops_gethandler→xoops_getHandler, xoops_getmodulehandler→xoops_getModuleHandler, set_errorHandler→set_error_handler, restore_errorHandler→restore_error_handler, set_exceptionHandler→set_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')
|
RenameMethodCallByNameRector (name-only, for untyped receivers) carries these maps in the default set:
-
quoteString→quote(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_ref→assignByRef,clear_compiled_tpl→clearCompiledTemplate,is_cached→isCached,get_template_vars→getTemplateVars, … — these are the Smarty 4 forms. (The further Smarty-4→5 step, e.g.assignByRef→assign, 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.
\Xmf\Module\Admin (and legacy ModuleAdmin) has both renderX() (returns a string) and displayX()
(echoes, returns void). A name-only renderIndex→displayIndex / renderButton→displayButton
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',
]);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 |
The Smarty 4 → 5 PHP-API changes (assignByRef→assign, appendByRef→append, 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.