mirror of
https://github.com/Dolibarr/dolibarr.git
synced 2025-12-23 18:01:36 +01:00
More valid rector rules to change conf->global->xxx
This commit is contained in:
@@ -48,6 +48,7 @@ return static function (RectorConfig $rectorConfig): void {
|
||||
__DIR__ . '/../../../scripts/',
|
||||
__DIR__ . '/../../../test/phpunit/',
|
||||
]);
|
||||
|
||||
$rectorConfig->skip([
|
||||
'**/includes/**',
|
||||
'**/custom/**',
|
||||
@@ -55,6 +56,7 @@ return static function (RectorConfig $rectorConfig): void {
|
||||
'**/rector/**', // Disable this line to test the "test.php" file.
|
||||
__DIR__ . '/../../../htdocs/custom/',
|
||||
__DIR__ . '/../../../htdocs/install/doctemplates/*'
|
||||
//'test.php',
|
||||
]);
|
||||
$rectorConfig->parallel(240);
|
||||
|
||||
@@ -70,9 +72,9 @@ return static function (RectorConfig $rectorConfig): void {
|
||||
|
||||
//$rectorConfig->rule(ReplaceEachAssignmentWithKeyCurrentRector::class);
|
||||
|
||||
|
||||
$rectorConfig->rule(Rector\CodeQuality\Rector\FuncCall\FloatvalToTypeCastRector::class);
|
||||
$rectorConfig->rule(Rector\CodeQuality\Rector\FuncCall\BoolvalToTypeCastRector::class);
|
||||
$rectorConfig->rule(Rector\CodeQuality\Rector\NotEqual\CommonNotEqualRector::class);
|
||||
//Not yet ready: $rectorconfig->rule(Rector\CodeQuality\Rector\If_\CompleteMissingIfElseBracketRector::class);
|
||||
$rectorConfig->rule(Rector\CodeQuality\Rector\For_\ForRepeatedCountToOwnVariableRector::class);
|
||||
|
||||
@@ -82,11 +84,16 @@ return static function (RectorConfig $rectorConfig): void {
|
||||
$rectorConfig->rule(Dolibarr\Rector\Renaming\UserRightsToFunction::class);
|
||||
//$rectorConfig->rule(Dolibarr\Rector\Renaming\UsePositiveExit::class);
|
||||
|
||||
|
||||
// This fix <> into != but it breaks other rules, so added at end.
|
||||
$rectorConfig->rule(Rector\CodeQuality\Rector\NotEqual\CommonNotEqualRector::class);
|
||||
|
||||
|
||||
// Add all predefined rules to migrate to up to php 71.
|
||||
// Warning this break tab spacing of arrays on several lines
|
||||
/*$rectorConfig->sets([
|
||||
LevelSetList::UP_TO_PHP_70
|
||||
]);*/
|
||||
LevelSetList::UP_TO_PHP_70
|
||||
]);*/
|
||||
// Add predefined rules for a given version only
|
||||
//$rectorConfig->import(SetList::PHP_70);
|
||||
//$rectorConfig->import(SetList::PHP_71);
|
||||
|
||||
@@ -64,8 +64,8 @@ class GlobalToFunction extends AbstractRector
|
||||
[new CodeSample(
|
||||
'$conf->global->CONSTANT',
|
||||
'getDolGlobalInt(\'CONSTANT\')'
|
||||
)]
|
||||
);
|
||||
)]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -133,7 +133,7 @@ class GlobalToFunction extends AbstractRector
|
||||
$node->dim = new FuncCall(
|
||||
new Name('getDolGlobalString'),
|
||||
[new Arg($constName)]
|
||||
);
|
||||
);
|
||||
}
|
||||
return $node;
|
||||
}
|
||||
@@ -208,7 +208,7 @@ class GlobalToFunction extends AbstractRector
|
||||
$leftConcat = new FuncCall(
|
||||
new Name('getDolGlobalString'),
|
||||
[new Arg($constName)]
|
||||
);
|
||||
);
|
||||
$rightConcat = $node->right;
|
||||
}
|
||||
if ($this->isGlobalVar($node->right)) {
|
||||
@@ -219,7 +219,7 @@ class GlobalToFunction extends AbstractRector
|
||||
$rightConcat = new FuncCall(
|
||||
new Name('getDolGlobalString'),
|
||||
[new Arg($constName)]
|
||||
);
|
||||
);
|
||||
$leftConcat = $node->left;
|
||||
}
|
||||
if (!isset($leftConcat, $rightConcat)) {
|
||||
@@ -238,6 +238,7 @@ class GlobalToFunction extends AbstractRector
|
||||
$node = $nodes->getFirstExpr();
|
||||
}
|
||||
|
||||
|
||||
// Now process all comparison like:
|
||||
// $conf->global->... Operator Value
|
||||
|
||||
@@ -264,11 +265,14 @@ class GlobalToFunction extends AbstractRector
|
||||
$typeofcomparison = 'NotIdentical';
|
||||
//var_dump($node->left);
|
||||
}
|
||||
|
||||
if (empty($typeofcomparison)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!$this->isGlobalVar($node->left)) {
|
||||
$isconfglobal = $this->isGlobalVar($node->left);
|
||||
if (!$isconfglobal) {
|
||||
// The left side is not conf->global->xxx, so we leave
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -282,7 +286,8 @@ class GlobalToFunction extends AbstractRector
|
||||
$funcName = 'getDolGlobalString';
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
$funcName = 'getDolGlobalString';
|
||||
break;
|
||||
}
|
||||
|
||||
$constName = $this->getConstName($node->left);
|
||||
@@ -295,9 +300,9 @@ class GlobalToFunction extends AbstractRector
|
||||
new FuncCall(
|
||||
new Name($funcName),
|
||||
[new Arg($constName)]
|
||||
),
|
||||
),
|
||||
$node->right
|
||||
);
|
||||
);
|
||||
}
|
||||
if ($typeofcomparison == 'NotEqual') {
|
||||
return new NotEqual(
|
||||
@@ -313,36 +318,36 @@ class GlobalToFunction extends AbstractRector
|
||||
new FuncCall(
|
||||
new Name($funcName),
|
||||
[new Arg($constName)]
|
||||
),
|
||||
),
|
||||
$node->right
|
||||
);
|
||||
);
|
||||
}
|
||||
if ($typeofcomparison == 'GreaterOrEqual') {
|
||||
return new GreaterOrEqual(
|
||||
new FuncCall(
|
||||
new Name($funcName),
|
||||
[new Arg($constName)]
|
||||
),
|
||||
),
|
||||
$node->right
|
||||
);
|
||||
);
|
||||
}
|
||||
if ($typeofcomparison == 'Smaller') {
|
||||
return new Smaller(
|
||||
new FuncCall(
|
||||
new Name($funcName),
|
||||
[new Arg($constName)]
|
||||
),
|
||||
),
|
||||
$node->right
|
||||
);
|
||||
);
|
||||
}
|
||||
if ($typeofcomparison == 'SmallerOrEqual') {
|
||||
return new SmallerOrEqual(
|
||||
new FuncCall(
|
||||
new Name($funcName),
|
||||
[new Arg($constName)]
|
||||
),
|
||||
),
|
||||
$node->right
|
||||
);
|
||||
);
|
||||
}
|
||||
if ($typeofcomparison == 'NotIdentical') {
|
||||
return new NotIdentical(
|
||||
@@ -382,7 +387,7 @@ class GlobalToFunction extends AbstractRector
|
||||
}
|
||||
return \true;
|
||||
}
|
||||
);
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user