From 45abbf8a3d4311705bc562a29b53bd181e168544 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 12 Dec 2023 03:29:51 +0100 Subject: [PATCH] Enhance rector rules --- .../rector/src/Renaming/GlobalToFunction.php | 29 +++++++++++++++++-- .../accountancy/bookkeeping/listbyaccount.php | 2 +- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/dev/tools/rector/src/Renaming/GlobalToFunction.php b/dev/tools/rector/src/Renaming/GlobalToFunction.php index d20c2867cdb..286c5c91a46 100644 --- a/dev/tools/rector/src/Renaming/GlobalToFunction.php +++ b/dev/tools/rector/src/Renaming/GlobalToFunction.php @@ -70,14 +70,15 @@ class GlobalToFunction extends AbstractRector */ public function getNodeTypes(): array { - return [Equal::class, Greater::class, GreaterOrEqual::class, Smaller::class, SmallerOrEqual::class, BooleanAnd::class, Concat::class, ArrayDimFetch::class]; + return [FuncCall::class, Equal::class, Greater::class, GreaterOrEqual::class, Smaller::class, SmallerOrEqual::class, BooleanAnd::class, Concat::class, ArrayDimFetch::class]; } /** * refactor * * @param Node $node A node - * @return Equal|Concat|ArrayDimFetch|void + * @return FuncCall|Equal|Concat|ArrayDimFetch|void + * return $node unchanged or void to do nothing */ public function refactor(Node $node) { @@ -97,6 +98,28 @@ class GlobalToFunction extends AbstractRector } return $node; } + + if ($node instanceof FuncCall) { + $tmpfunctionname = $this->getName($node); + if (in_array($tmpfunctionname, array('dol_escape_htmltag'))) { + $nbofparam = count($node->getArgs()); + if ($nbofparam == 1) { + $args = $node->getArgs(); + foreach($args as $arg) { // only 1 element in this array + //var_dump($arg->value);exit; + if ($this->isGlobalVar($arg->value)) { + $constName = $this->getConstName($arg->value); + if (empty($constName)) { + return; + } + $a = new FuncCall(new Name('getDolGlobalString'), [new Arg($constName)]); + return new FuncCall(new Name($tmpfunctionname), [new Arg($a)]); + } + } + } + } + return $node; + } if ($node instanceof Concat) { if ($this->isGlobalVar($node->left)) { $constName = $this->getConstName($node->left); @@ -257,7 +280,7 @@ class GlobalToFunction extends AbstractRector * Check if node is a global access with format conf->global->XXX * * @param Node $node A node - * @return bool Return true if noe is conf->global->XXX + * @return bool Return true if node is conf->global->XXX */ private function isGlobalVar($node) { diff --git a/htdocs/accountancy/bookkeeping/listbyaccount.php b/htdocs/accountancy/bookkeeping/listbyaccount.php index 95951b87575..a6999195470 100644 --- a/htdocs/accountancy/bookkeeping/listbyaccount.php +++ b/htdocs/accountancy/bookkeeping/listbyaccount.php @@ -141,7 +141,7 @@ if (empty($search_date_start) && empty($search_date_end) && !GETPOSTISSET('searc $search_date_start = strtotime($fiscalYear->date_start); $search_date_end = strtotime($fiscalYear->date_end); } else { - $month_start = getDolGlobalInt('SOCIETE_FISCAL_MONTH_START', 1) + $month_start = getDolGlobalInt('SOCIETE_FISCAL_MONTH_START', 1); $year_start = dol_print_date(dol_now(), '%Y'); if (dol_print_date(dol_now(), '%m') < $month_start) { $year_start--; // If current month is lower that starting fiscal month, we start last year