From fc1411f9a46de5942adef6bdaf9586c46cc0b8d6 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 13 Dec 2023 14:59:22 +0100 Subject: [PATCH] Work on rector to fix warnings --- .../rector/src/Renaming/GlobalToFunction.php | 28 ++++++++++++++++--- htdocs/adherents/admin/member.php | 2 +- htdocs/adherents/class/adherent.class.php | 17 ++++++----- .../adherents/class/adherent_type.class.php | 2 +- 4 files changed, 34 insertions(+), 15 deletions(-) diff --git a/dev/tools/rector/src/Renaming/GlobalToFunction.php b/dev/tools/rector/src/Renaming/GlobalToFunction.php index 03b797c81b1..b498160c895 100644 --- a/dev/tools/rector/src/Renaming/GlobalToFunction.php +++ b/dev/tools/rector/src/Renaming/GlobalToFunction.php @@ -25,6 +25,7 @@ use PhpParser\Node\Expr\BinaryOp\Greater; use PhpParser\Node\Expr\BinaryOp\GreaterOrEqual; use PhpParser\Node\Expr\BinaryOp\Smaller; use PhpParser\Node\Expr\BinaryOp\SmallerOrEqual; +use PhpParser\Node\Expr\BinaryOp\NotIdentical; /** * Class with Rector custom rule to fix code @@ -70,7 +71,7 @@ class GlobalToFunction extends AbstractRector */ public function getNodeTypes(): array { - return [FuncCall::class, 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, NotIdentical::class, BooleanAnd::class, Concat::class, ArrayDimFetch::class]; } /** @@ -101,7 +102,7 @@ class GlobalToFunction extends AbstractRector if ($node instanceof FuncCall) { $tmpfunctionname = $this->getName($node); - if (in_array($tmpfunctionname, array('dol_escape_htmltag', 'make_substitutions', 'min', 'max'))) { + if (in_array($tmpfunctionname, array('dol_escape_htmltag', 'make_substitutions', 'min', 'max', 'explode'))) { $args = $node->getArgs(); $nbofparam = count($args); @@ -126,6 +127,7 @@ class GlobalToFunction extends AbstractRector } return $node; } + if ($node instanceof Concat) { if ($this->isGlobalVar($node->left)) { $constName = $this->getConstName($node->left); @@ -154,6 +156,7 @@ class GlobalToFunction extends AbstractRector } return new Concat($leftConcat, $rightConcat); } + if ($node instanceof BooleanAnd) { $nodes = $this->resolveTwoNodeMatch($node); if (!isset($nodes)) { @@ -164,6 +167,9 @@ class GlobalToFunction extends AbstractRector $node = $nodes->getFirstExpr(); } + // Now process all comparison like: + // $conf->global->... Operator Value + $typeofcomparison = ''; if ($node instanceof Equal) { $typeofcomparison = 'Equal'; @@ -180,6 +186,10 @@ class GlobalToFunction extends AbstractRector if ($node instanceof SmallerOrEqual) { $typeofcomparison = 'SmallerOrEqual'; } + if ($node instanceof NotIdentical) { + $typeofcomparison = 'NotIdentical'; + //var_dump($node->left); + } if (empty($typeofcomparison)) { return; } @@ -189,7 +199,8 @@ class GlobalToFunction extends AbstractRector } // Test the type after the comparison conf->global->xxx to know the name of function - switch ($node->right->getType()) { + $typeright = $node->right->getType(); + switch ($typeright) { case 'Scalar_LNumber': $funcName = 'getDolGlobalInt'; break; @@ -250,6 +261,15 @@ class GlobalToFunction extends AbstractRector $node->right ); } + if ($typeofcomparison == 'NotIdentical') { + return new NotIdentical( + new FuncCall( + new Name($funcName), + [new Arg($constName)] + ), + $node->right + ); + } } /** @@ -262,7 +282,7 @@ class GlobalToFunction extends AbstractRector { return $this->binaryOpManipulator->matchFirstAndSecondConditionNode( $booleanAnd, - // $conf->global == $value + // Function to check if we are in the case $conf->global->... == $value function (Node $node): bool { if (!$node instanceof Equal) { return \false; diff --git a/htdocs/adherents/admin/member.php b/htdocs/adherents/admin/member.php index 06416f19039..b78cd367c9d 100644 --- a/htdocs/adherents/admin/member.php +++ b/htdocs/adherents/admin/member.php @@ -428,7 +428,7 @@ if (isModEnabled('facture')) { if (isModEnabled("product") || isModEnabled("service")) { print ''.$langs->trans("ADHERENT_PRODUCT_ID_FOR_SUBSCRIPTIONS").''; print ''; - $selected = (!getDolGlobalString('ADHERENT_PRODUCT_ID_FOR_SUBSCRIPTIONS') ? '' : $conf->global->ADHERENT_PRODUCT_ID_FOR_SUBSCRIPTIONS); + $selected = getDolGlobalString('ADHERENT_PRODUCT_ID_FOR_SUBSCRIPTIONS'); print img_picto('', 'product', 'class="pictofixedwidth"'); $form->select_produits($selected, 'ADHERENT_PRODUCT_ID_FOR_SUBSCRIPTIONS', '', 0); print ''; diff --git a/htdocs/adherents/class/adherent.class.php b/htdocs/adherents/class/adherent.class.php index 294e0c4689d..51af75d9591 100644 --- a/htdocs/adherents/class/adherent.class.php +++ b/htdocs/adherents/class/adherent.class.php @@ -1151,7 +1151,6 @@ class Adherent extends CommonObject // Mise a jour $sql = "UPDATE ".MAIN_DB_PREFIX."adherent"; $sql .= " SET pass_crypted = '".$this->db->escape($password_crypted)."'"; - //if (!empty($conf->global->DATABASE_PWD_ENCRYPTED)) if ($isencrypted) { $sql .= ", pass = null"; } else { @@ -1921,7 +1920,7 @@ class Adherent extends CommonObject $outputlangs->setDefaultLang($newlang); } // Generate PDF (whatever is option MAIN_DISABLE_PDF_AUTOUPDATE) so we can include it into email - //if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) + //if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE')) $invoice->generateDocument($invoice->model_pdf, $outputlangs); } @@ -2727,7 +2726,7 @@ class Adherent extends CommonObject $keymodified = false; // Object classes - $info["objectclass"] = explode(',', $conf->global->LDAP_MEMBER_OBJECT_CLASS); + $info["objectclass"] = explode(',', getDolGlobalString('LDAP_MEMBER_OBJECT_CLASS')); $this->fullname = $this->getFullName($langs); @@ -2752,7 +2751,7 @@ class Adherent extends CommonObject $info[getDolGlobalString($constname)] = $this->$varname; // Check if it is the LDAP key and if its value has been changed - if (getDolGlobalString('LDAP_KEY_MEMBERS') && $conf->global->LDAP_KEY_MEMBERS == getDolGlobalString($constname)) { + if (getDolGlobalString('LDAP_KEY_MEMBERS') && getDolGlobalString('LDAP_KEY_MEMBERS') == getDolGlobalString($constname)) { if (!empty($this->oldcopy) && $this->$varname != $this->oldcopy->$varname) { $keymodified = true; // For check if LDAP key has been modified } @@ -2821,15 +2820,15 @@ class Adherent extends CommonObject if (getDolGlobalString('LDAP_MEMBER_FIELD_PASSWORD_CRYPTED')) { $info[getDolGlobalString('LDAP_MEMBER_FIELD_PASSWORD_CRYPTED')] = dol_hash($this->pass, 'openldap'); // Create OpenLDAP password (see LDAP_PASSWORD_HASH_TYPE) } - } elseif ($conf->global->LDAP_SERVER_PROTOCOLVERSION !== '3') { + } elseif (getDolGlobalString('LDAP_SERVER_PROTOCOLVERSION') !== '3') { // Set LDAP password if possible // If ldap key is modified and LDAPv3 we use ldap_rename function for avoid lose encrypt password - if (getDolGlobalString('DATABASE_PWD_ENCRYPTED')) { - // Just for the default MD5 ! - if (!getDolGlobalString('MAIN_SECURITY_HASH_ALGO')) { + if (getDolGlobalString('DATABASE_PWD_ENCRYPTED')) { // This should be on on default installation + // Just for the case we use old md5 encryption (deprecated, no more used, kept for compatibility) + if (!getDolGlobalString('MAIN_SECURITY_HASH_ALGO') || getDolGlobalString('MAIN_SECURITY_HASH_ALGO') == 'md5') { if ($this->pass_indatabase_crypted && getDolGlobalString('LDAP_MEMBER_FIELD_PASSWORD_CRYPTED')) { // Create OpenLDAP MD5 password from Dolibarr MD5 password - // Note: This suppose that "pass_indatabase_crypted" is a md5 (guaranted by the previous test if "(empty($conf->global->MAIN_SECURITY_HASH_ALGO))" + // Note: This suppose that "pass_indatabase_crypted" is a md5 (this should not happen anymore)" $info[getDolGlobalString('LDAP_MEMBER_FIELD_PASSWORD_CRYPTED')] = dolGetLdapPasswordHash($this->pass_indatabase_crypted, 'md5frommd5'); } } diff --git a/htdocs/adherents/class/adherent_type.class.php b/htdocs/adherents/class/adherent_type.class.php index c75ec565b35..2ecd0a80978 100644 --- a/htdocs/adherents/class/adherent_type.class.php +++ b/htdocs/adherents/class/adherent_type.class.php @@ -868,7 +868,7 @@ class AdherentType extends CommonObject $info = array(); // Object classes - $info["objectclass"] = explode(',', $conf->global->LDAP_MEMBER_TYPE_OBJECT_CLASS); + $info["objectclass"] = explode(',', getDolGlobalString('LDAP_MEMBER_TYPE_OBJECT_CLASS')); if (empty($this->note_public) && !empty($this->note)) { // For backward compatibility $this->note_public = $this->note;