forked from Wavyzz/dolibarr
Work on rector to fix warnings
This commit is contained in:
@@ -21,10 +21,12 @@ use Rector\Php71\ValueObject\TwoNodeMatch;
|
|||||||
use Symplify\RuleDocGenerator\Exception\PoorDocumentationException;
|
use Symplify\RuleDocGenerator\Exception\PoorDocumentationException;
|
||||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||||
|
use PhpParser\Node\Expr\BinaryOp\NotEqual;
|
||||||
use PhpParser\Node\Expr\BinaryOp\Greater;
|
use PhpParser\Node\Expr\BinaryOp\Greater;
|
||||||
use PhpParser\Node\Expr\BinaryOp\GreaterOrEqual;
|
use PhpParser\Node\Expr\BinaryOp\GreaterOrEqual;
|
||||||
use PhpParser\Node\Expr\BinaryOp\Smaller;
|
use PhpParser\Node\Expr\BinaryOp\Smaller;
|
||||||
use PhpParser\Node\Expr\BinaryOp\SmallerOrEqual;
|
use PhpParser\Node\Expr\BinaryOp\SmallerOrEqual;
|
||||||
|
use PhpParser\Node\Expr\BinaryOp\NotIdentical;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class with Rector custom rule to fix code
|
* Class with Rector custom rule to fix code
|
||||||
@@ -55,7 +57,7 @@ class GlobalToFunction extends AbstractRector
|
|||||||
public function getRuleDefinition(): RuleDefinition
|
public function getRuleDefinition(): RuleDefinition
|
||||||
{
|
{
|
||||||
return new RuleDefinition(
|
return new RuleDefinition(
|
||||||
'Change $conf->global to getDolGlobal',
|
'Change $conf->global to getDolGlobal in context (1) conf->global Operator Value or (2) function(conf->global...)',
|
||||||
[new CodeSample(
|
[new CodeSample(
|
||||||
'$conf->global->CONSTANT',
|
'$conf->global->CONSTANT',
|
||||||
'getDolGlobalInt(\'CONSTANT\')'
|
'getDolGlobalInt(\'CONSTANT\')'
|
||||||
@@ -70,7 +72,7 @@ class GlobalToFunction extends AbstractRector
|
|||||||
*/
|
*/
|
||||||
public function getNodeTypes(): array
|
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, NotEqual::class, Greater::class, GreaterOrEqual::class, Smaller::class, SmallerOrEqual::class, NotIdentical::class, BooleanAnd::class, Concat::class, ArrayDimFetch::class];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -101,7 +103,7 @@ class GlobalToFunction extends AbstractRector
|
|||||||
|
|
||||||
if ($node instanceof FuncCall) {
|
if ($node instanceof FuncCall) {
|
||||||
$tmpfunctionname = $this->getName($node);
|
$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();
|
$args = $node->getArgs();
|
||||||
$nbofparam = count($args);
|
$nbofparam = count($args);
|
||||||
|
|
||||||
@@ -126,6 +128,7 @@ class GlobalToFunction extends AbstractRector
|
|||||||
}
|
}
|
||||||
return $node;
|
return $node;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($node instanceof Concat) {
|
if ($node instanceof Concat) {
|
||||||
if ($this->isGlobalVar($node->left)) {
|
if ($this->isGlobalVar($node->left)) {
|
||||||
$constName = $this->getConstName($node->left);
|
$constName = $this->getConstName($node->left);
|
||||||
@@ -154,6 +157,7 @@ class GlobalToFunction extends AbstractRector
|
|||||||
}
|
}
|
||||||
return new Concat($leftConcat, $rightConcat);
|
return new Concat($leftConcat, $rightConcat);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($node instanceof BooleanAnd) {
|
if ($node instanceof BooleanAnd) {
|
||||||
$nodes = $this->resolveTwoNodeMatch($node);
|
$nodes = $this->resolveTwoNodeMatch($node);
|
||||||
if (!isset($nodes)) {
|
if (!isset($nodes)) {
|
||||||
@@ -164,10 +168,16 @@ class GlobalToFunction extends AbstractRector
|
|||||||
$node = $nodes->getFirstExpr();
|
$node = $nodes->getFirstExpr();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Now process all comparison like:
|
||||||
|
// $conf->global->... Operator Value
|
||||||
|
|
||||||
$typeofcomparison = '';
|
$typeofcomparison = '';
|
||||||
if ($node instanceof Equal) {
|
if ($node instanceof Equal) {
|
||||||
$typeofcomparison = 'Equal';
|
$typeofcomparison = 'Equal';
|
||||||
}
|
}
|
||||||
|
if ($node instanceof NotEqual) {
|
||||||
|
$typeofcomparison = 'NotEqual';
|
||||||
|
}
|
||||||
if ($node instanceof Greater) {
|
if ($node instanceof Greater) {
|
||||||
$typeofcomparison = 'Greater';
|
$typeofcomparison = 'Greater';
|
||||||
}
|
}
|
||||||
@@ -180,6 +190,10 @@ class GlobalToFunction extends AbstractRector
|
|||||||
if ($node instanceof SmallerOrEqual) {
|
if ($node instanceof SmallerOrEqual) {
|
||||||
$typeofcomparison = 'SmallerOrEqual';
|
$typeofcomparison = 'SmallerOrEqual';
|
||||||
}
|
}
|
||||||
|
if ($node instanceof NotIdentical) {
|
||||||
|
$typeofcomparison = 'NotIdentical';
|
||||||
|
//var_dump($node->left);
|
||||||
|
}
|
||||||
if (empty($typeofcomparison)) {
|
if (empty($typeofcomparison)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -189,7 +203,8 @@ class GlobalToFunction extends AbstractRector
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Test the type after the comparison conf->global->xxx to know the name of function
|
// 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':
|
case 'Scalar_LNumber':
|
||||||
$funcName = 'getDolGlobalInt';
|
$funcName = 'getDolGlobalInt';
|
||||||
break;
|
break;
|
||||||
@@ -214,6 +229,15 @@ class GlobalToFunction extends AbstractRector
|
|||||||
$node->right
|
$node->right
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
if ($typeofcomparison == 'NotEqual') {
|
||||||
|
return new NotEqual(
|
||||||
|
new FuncCall(
|
||||||
|
new Name($funcName),
|
||||||
|
[new Arg($constName)]
|
||||||
|
),
|
||||||
|
$node->right
|
||||||
|
);
|
||||||
|
}
|
||||||
if ($typeofcomparison == 'Greater') {
|
if ($typeofcomparison == 'Greater') {
|
||||||
return new Greater(
|
return new Greater(
|
||||||
new FuncCall(
|
new FuncCall(
|
||||||
@@ -250,6 +274,15 @@ class GlobalToFunction extends AbstractRector
|
|||||||
$node->right
|
$node->right
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
if ($typeofcomparison == 'NotIdentical') {
|
||||||
|
return new NotIdentical(
|
||||||
|
new FuncCall(
|
||||||
|
new Name($funcName),
|
||||||
|
[new Arg($constName)]
|
||||||
|
),
|
||||||
|
$node->right
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -262,7 +295,7 @@ class GlobalToFunction extends AbstractRector
|
|||||||
{
|
{
|
||||||
return $this->binaryOpManipulator->matchFirstAndSecondConditionNode(
|
return $this->binaryOpManipulator->matchFirstAndSecondConditionNode(
|
||||||
$booleanAnd,
|
$booleanAnd,
|
||||||
// $conf->global == $value
|
// Function to check if we are in the case $conf->global->... == $value
|
||||||
function (Node $node): bool {
|
function (Node $node): bool {
|
||||||
if (!$node instanceof Equal) {
|
if (!$node instanceof Equal) {
|
||||||
return \false;
|
return \false;
|
||||||
|
|||||||
@@ -428,7 +428,7 @@ if (isModEnabled('facture')) {
|
|||||||
if (isModEnabled("product") || isModEnabled("service")) {
|
if (isModEnabled("product") || isModEnabled("service")) {
|
||||||
print '<tr class="oddeven"><td>'.$langs->trans("ADHERENT_PRODUCT_ID_FOR_SUBSCRIPTIONS").'</td>';
|
print '<tr class="oddeven"><td>'.$langs->trans("ADHERENT_PRODUCT_ID_FOR_SUBSCRIPTIONS").'</td>';
|
||||||
print '<td>';
|
print '<td>';
|
||||||
$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"');
|
print img_picto('', 'product', 'class="pictofixedwidth"');
|
||||||
$form->select_produits($selected, 'ADHERENT_PRODUCT_ID_FOR_SUBSCRIPTIONS', '', 0);
|
$form->select_produits($selected, 'ADHERENT_PRODUCT_ID_FOR_SUBSCRIPTIONS', '', 0);
|
||||||
print '</td>';
|
print '</td>';
|
||||||
|
|||||||
@@ -1151,7 +1151,6 @@ class Adherent extends CommonObject
|
|||||||
// Mise a jour
|
// Mise a jour
|
||||||
$sql = "UPDATE ".MAIN_DB_PREFIX."adherent";
|
$sql = "UPDATE ".MAIN_DB_PREFIX."adherent";
|
||||||
$sql .= " SET pass_crypted = '".$this->db->escape($password_crypted)."'";
|
$sql .= " SET pass_crypted = '".$this->db->escape($password_crypted)."'";
|
||||||
//if (!empty($conf->global->DATABASE_PWD_ENCRYPTED))
|
|
||||||
if ($isencrypted) {
|
if ($isencrypted) {
|
||||||
$sql .= ", pass = null";
|
$sql .= ", pass = null";
|
||||||
} else {
|
} else {
|
||||||
@@ -1921,7 +1920,7 @@ class Adherent extends CommonObject
|
|||||||
$outputlangs->setDefaultLang($newlang);
|
$outputlangs->setDefaultLang($newlang);
|
||||||
}
|
}
|
||||||
// Generate PDF (whatever is option MAIN_DISABLE_PDF_AUTOUPDATE) so we can include it into email
|
// 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);
|
$invoice->generateDocument($invoice->model_pdf, $outputlangs);
|
||||||
}
|
}
|
||||||
@@ -2727,7 +2726,7 @@ class Adherent extends CommonObject
|
|||||||
$keymodified = false;
|
$keymodified = false;
|
||||||
|
|
||||||
// Object classes
|
// Object classes
|
||||||
$info["objectclass"] = explode(',', $conf->global->LDAP_MEMBER_OBJECT_CLASS);
|
$info["objectclass"] = explode(',', getDolGlobalString('LDAP_MEMBER_OBJECT_CLASS'));
|
||||||
|
|
||||||
$this->fullname = $this->getFullName($langs);
|
$this->fullname = $this->getFullName($langs);
|
||||||
|
|
||||||
@@ -2752,7 +2751,7 @@ class Adherent extends CommonObject
|
|||||||
$info[getDolGlobalString($constname)] = $this->$varname;
|
$info[getDolGlobalString($constname)] = $this->$varname;
|
||||||
|
|
||||||
// Check if it is the LDAP key and if its value has been changed
|
// 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) {
|
if (!empty($this->oldcopy) && $this->$varname != $this->oldcopy->$varname) {
|
||||||
$keymodified = true; // For check if LDAP key has been modified
|
$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')) {
|
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)
|
$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
|
// Set LDAP password if possible
|
||||||
// If ldap key is modified and LDAPv3 we use ldap_rename function for avoid lose encrypt password
|
// If ldap key is modified and LDAPv3 we use ldap_rename function for avoid lose encrypt password
|
||||||
if (getDolGlobalString('DATABASE_PWD_ENCRYPTED')) {
|
if (getDolGlobalString('DATABASE_PWD_ENCRYPTED')) { // This should be on on default installation
|
||||||
// Just for the default MD5 !
|
// Just for the case we use old md5 encryption (deprecated, no more used, kept for compatibility)
|
||||||
if (!getDolGlobalString('MAIN_SECURITY_HASH_ALGO')) {
|
if (!getDolGlobalString('MAIN_SECURITY_HASH_ALGO') || getDolGlobalString('MAIN_SECURITY_HASH_ALGO') == 'md5') {
|
||||||
if ($this->pass_indatabase_crypted && getDolGlobalString('LDAP_MEMBER_FIELD_PASSWORD_CRYPTED')) {
|
if ($this->pass_indatabase_crypted && getDolGlobalString('LDAP_MEMBER_FIELD_PASSWORD_CRYPTED')) {
|
||||||
// Create OpenLDAP MD5 password from Dolibarr MD5 password
|
// 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');
|
$info[getDolGlobalString('LDAP_MEMBER_FIELD_PASSWORD_CRYPTED')] = dolGetLdapPasswordHash($this->pass_indatabase_crypted, 'md5frommd5');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -844,7 +844,7 @@ class AdherentType extends CommonObject
|
|||||||
$dn = getDolGlobalString('LDAP_KEY_MEMBERS_TYPES') . "=".$info[getDolGlobalString('LDAP_KEY_MEMBERS_TYPES')]."," . getDolGlobalString('LDAP_MEMBER_TYPE_DN');
|
$dn = getDolGlobalString('LDAP_KEY_MEMBERS_TYPES') . "=".$info[getDolGlobalString('LDAP_KEY_MEMBERS_TYPES')]."," . getDolGlobalString('LDAP_MEMBER_TYPE_DN');
|
||||||
}
|
}
|
||||||
if ($mode == 1) {
|
if ($mode == 1) {
|
||||||
$dn = $conf->global->LDAP_MEMBER_TYPE_DN;
|
$dn = getDolGlobalString('LDAP_MEMBER_TYPE_DN');
|
||||||
}
|
}
|
||||||
if ($mode == 2) {
|
if ($mode == 2) {
|
||||||
$dn = getDolGlobalString('LDAP_KEY_MEMBERS_TYPES') . "=".$info[getDolGlobalString('LDAP_KEY_MEMBERS_TYPES')];
|
$dn = getDolGlobalString('LDAP_KEY_MEMBERS_TYPES') . "=".$info[getDolGlobalString('LDAP_KEY_MEMBERS_TYPES')];
|
||||||
@@ -868,7 +868,7 @@ class AdherentType extends CommonObject
|
|||||||
$info = array();
|
$info = array();
|
||||||
|
|
||||||
// Object classes
|
// 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
|
if (empty($this->note_public) && !empty($this->note)) { // For backward compatibility
|
||||||
$this->note_public = $this->note;
|
$this->note_public = $this->note;
|
||||||
|
|||||||
@@ -1056,7 +1056,7 @@ if (($action == 'addsubscription' || $action == 'create_thirdparty') && $user->h
|
|||||||
print $langs->trans("CreateDolibarrThirdParty");
|
print $langs->trans("CreateDolibarrThirdParty");
|
||||||
print '</a>)';
|
print '</a>)';
|
||||||
}
|
}
|
||||||
if (!getDolGlobalString('ADHERENT_VAT_FOR_SUBSCRIPTIONS') || $conf->global->ADHERENT_VAT_FOR_SUBSCRIPTIONS != 'defaultforfoundationcountry') {
|
if (!getDolGlobalString('ADHERENT_VAT_FOR_SUBSCRIPTIONS') || getDolGlobalString('ADHERENT_VAT_FOR_SUBSCRIPTIONS') != 'defaultforfoundationcountry') {
|
||||||
print '. <span class="opacitymedium">'.$langs->trans("NoVatOnSubscription", 0).'</span>';
|
print '. <span class="opacitymedium">'.$langs->trans("NoVatOnSubscription", 0).'</span>';
|
||||||
}
|
}
|
||||||
if (getDolGlobalString('ADHERENT_PRODUCT_ID_FOR_SUBSCRIPTIONS') && (isModEnabled('product') || isModEnabled('service'))) {
|
if (getDolGlobalString('ADHERENT_PRODUCT_ID_FOR_SUBSCRIPTIONS') && (isModEnabled('product') || isModEnabled('service'))) {
|
||||||
@@ -1086,7 +1086,7 @@ if (($action == 'addsubscription' || $action == 'create_thirdparty') && $user->h
|
|||||||
print $langs->trans("CreateDolibarrThirdParty");
|
print $langs->trans("CreateDolibarrThirdParty");
|
||||||
print '</a>)';
|
print '</a>)';
|
||||||
}
|
}
|
||||||
if (!getDolGlobalString('ADHERENT_VAT_FOR_SUBSCRIPTIONS') || $conf->global->ADHERENT_VAT_FOR_SUBSCRIPTIONS != 'defaultforfoundationcountry') {
|
if (!getDolGlobalString('ADHERENT_VAT_FOR_SUBSCRIPTIONS') || getDolGlobalString('ADHERENT_VAT_FOR_SUBSCRIPTIONS') != 'defaultforfoundationcountry') {
|
||||||
print '. <span class="opacitymedium">'.$langs->trans("NoVatOnSubscription", 0).'</span>';
|
print '. <span class="opacitymedium">'.$langs->trans("NoVatOnSubscription", 0).'</span>';
|
||||||
}
|
}
|
||||||
if (getDolGlobalString('ADHERENT_PRODUCT_ID_FOR_SUBSCRIPTIONS') && (isModEnabled('product')|| isModEnabled('service'))) {
|
if (getDolGlobalString('ADHERENT_PRODUCT_ID_FOR_SUBSCRIPTIONS') && (isModEnabled('product')|| isModEnabled('service'))) {
|
||||||
|
|||||||
Reference in New Issue
Block a user