mirror of
https://github.com/Dolibarr/dolibarr.git
synced 2025-02-20 13:46:52 +01:00
Work on rector to fix warnings
This commit is contained in:
parent
72006c6b76
commit
8f7d258a83
|
|
@ -21,10 +21,12 @@ use Rector\Php71\ValueObject\TwoNodeMatch;
|
|||
use Symplify\RuleDocGenerator\Exception\PoorDocumentationException;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
use PhpParser\Node\Expr\BinaryOp\NotEqual;
|
||||
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
|
||||
|
|
@ -55,7 +57,7 @@ class GlobalToFunction extends AbstractRector
|
|||
public function getRuleDefinition(): 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(
|
||||
'$conf->global->CONSTANT',
|
||||
'getDolGlobalInt(\'CONSTANT\')'
|
||||
|
|
@ -70,7 +72,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, 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) {
|
||||
$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 +128,7 @@ class GlobalToFunction extends AbstractRector
|
|||
}
|
||||
return $node;
|
||||
}
|
||||
|
||||
if ($node instanceof Concat) {
|
||||
if ($this->isGlobalVar($node->left)) {
|
||||
$constName = $this->getConstName($node->left);
|
||||
|
|
@ -154,6 +157,7 @@ class GlobalToFunction extends AbstractRector
|
|||
}
|
||||
return new Concat($leftConcat, $rightConcat);
|
||||
}
|
||||
|
||||
if ($node instanceof BooleanAnd) {
|
||||
$nodes = $this->resolveTwoNodeMatch($node);
|
||||
if (!isset($nodes)) {
|
||||
|
|
@ -164,10 +168,16 @@ class GlobalToFunction extends AbstractRector
|
|||
$node = $nodes->getFirstExpr();
|
||||
}
|
||||
|
||||
// Now process all comparison like:
|
||||
// $conf->global->... Operator Value
|
||||
|
||||
$typeofcomparison = '';
|
||||
if ($node instanceof Equal) {
|
||||
$typeofcomparison = 'Equal';
|
||||
}
|
||||
if ($node instanceof NotEqual) {
|
||||
$typeofcomparison = 'NotEqual';
|
||||
}
|
||||
if ($node instanceof Greater) {
|
||||
$typeofcomparison = 'Greater';
|
||||
}
|
||||
|
|
@ -180,6 +190,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 +203,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;
|
||||
|
|
@ -214,6 +229,15 @@ class GlobalToFunction extends AbstractRector
|
|||
$node->right
|
||||
);
|
||||
}
|
||||
if ($typeofcomparison == 'NotEqual') {
|
||||
return new NotEqual(
|
||||
new FuncCall(
|
||||
new Name($funcName),
|
||||
[new Arg($constName)]
|
||||
),
|
||||
$node->right
|
||||
);
|
||||
}
|
||||
if ($typeofcomparison == 'Greater') {
|
||||
return new Greater(
|
||||
new FuncCall(
|
||||
|
|
@ -250,6 +274,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 +295,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;
|
||||
|
|
|
|||
|
|
@ -428,7 +428,7 @@ if (isModEnabled('facture')) {
|
|||
if (isModEnabled("product") || isModEnabled("service")) {
|
||||
print '<tr class="oddeven"><td>'.$langs->trans("ADHERENT_PRODUCT_ID_FOR_SUBSCRIPTIONS").'</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"');
|
||||
$form->select_produits($selected, 'ADHERENT_PRODUCT_ID_FOR_SUBSCRIPTIONS', '', 0);
|
||||
print '</td>';
|
||||
|
|
|
|||
|
|
@ -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');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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');
|
||||
}
|
||||
if ($mode == 1) {
|
||||
$dn = $conf->global->LDAP_MEMBER_TYPE_DN;
|
||||
$dn = getDolGlobalString('LDAP_MEMBER_TYPE_DN');
|
||||
}
|
||||
if ($mode == 2) {
|
||||
$dn = getDolGlobalString('LDAP_KEY_MEMBERS_TYPES') . "=".$info[getDolGlobalString('LDAP_KEY_MEMBERS_TYPES')];
|
||||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -1056,7 +1056,7 @@ if (($action == 'addsubscription' || $action == 'create_thirdparty') && $user->h
|
|||
print $langs->trans("CreateDolibarrThirdParty");
|
||||
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>';
|
||||
}
|
||||
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 '</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>';
|
||||
}
|
||||
if (getDolGlobalString('ADHERENT_PRODUCT_ID_FOR_SUBSCRIPTIONS') && (isModEnabled('product')|| isModEnabled('service'))) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user