forked from Wavyzz/dolibarr
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__ . '/../../../scripts/',
|
||||||
__DIR__ . '/../../../test/phpunit/',
|
__DIR__ . '/../../../test/phpunit/',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$rectorConfig->skip([
|
$rectorConfig->skip([
|
||||||
'**/includes/**',
|
'**/includes/**',
|
||||||
'**/custom/**',
|
'**/custom/**',
|
||||||
@@ -55,6 +56,7 @@ return static function (RectorConfig $rectorConfig): void {
|
|||||||
'**/rector/**', // Disable this line to test the "test.php" file.
|
'**/rector/**', // Disable this line to test the "test.php" file.
|
||||||
__DIR__ . '/../../../htdocs/custom/',
|
__DIR__ . '/../../../htdocs/custom/',
|
||||||
__DIR__ . '/../../../htdocs/install/doctemplates/*'
|
__DIR__ . '/../../../htdocs/install/doctemplates/*'
|
||||||
|
//'test.php',
|
||||||
]);
|
]);
|
||||||
$rectorConfig->parallel(240);
|
$rectorConfig->parallel(240);
|
||||||
|
|
||||||
@@ -70,9 +72,9 @@ return static function (RectorConfig $rectorConfig): void {
|
|||||||
|
|
||||||
//$rectorConfig->rule(ReplaceEachAssignmentWithKeyCurrentRector::class);
|
//$rectorConfig->rule(ReplaceEachAssignmentWithKeyCurrentRector::class);
|
||||||
|
|
||||||
|
|
||||||
$rectorConfig->rule(Rector\CodeQuality\Rector\FuncCall\FloatvalToTypeCastRector::class);
|
$rectorConfig->rule(Rector\CodeQuality\Rector\FuncCall\FloatvalToTypeCastRector::class);
|
||||||
$rectorConfig->rule(Rector\CodeQuality\Rector\FuncCall\BoolvalToTypeCastRector::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);
|
//Not yet ready: $rectorconfig->rule(Rector\CodeQuality\Rector\If_\CompleteMissingIfElseBracketRector::class);
|
||||||
$rectorConfig->rule(Rector\CodeQuality\Rector\For_\ForRepeatedCountToOwnVariableRector::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\UserRightsToFunction::class);
|
||||||
//$rectorConfig->rule(Dolibarr\Rector\Renaming\UsePositiveExit::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.
|
// Add all predefined rules to migrate to up to php 71.
|
||||||
// Warning this break tab spacing of arrays on several lines
|
// Warning this break tab spacing of arrays on several lines
|
||||||
/*$rectorConfig->sets([
|
/*$rectorConfig->sets([
|
||||||
LevelSetList::UP_TO_PHP_70
|
LevelSetList::UP_TO_PHP_70
|
||||||
]);*/
|
]);*/
|
||||||
// Add predefined rules for a given version only
|
// Add predefined rules for a given version only
|
||||||
//$rectorConfig->import(SetList::PHP_70);
|
//$rectorConfig->import(SetList::PHP_70);
|
||||||
//$rectorConfig->import(SetList::PHP_71);
|
//$rectorConfig->import(SetList::PHP_71);
|
||||||
|
|||||||
@@ -64,8 +64,8 @@ class GlobalToFunction extends AbstractRector
|
|||||||
[new CodeSample(
|
[new CodeSample(
|
||||||
'$conf->global->CONSTANT',
|
'$conf->global->CONSTANT',
|
||||||
'getDolGlobalInt(\'CONSTANT\')'
|
'getDolGlobalInt(\'CONSTANT\')'
|
||||||
)]
|
)]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -133,7 +133,7 @@ class GlobalToFunction extends AbstractRector
|
|||||||
$node->dim = new FuncCall(
|
$node->dim = new FuncCall(
|
||||||
new Name('getDolGlobalString'),
|
new Name('getDolGlobalString'),
|
||||||
[new Arg($constName)]
|
[new Arg($constName)]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return $node;
|
return $node;
|
||||||
}
|
}
|
||||||
@@ -208,7 +208,7 @@ class GlobalToFunction extends AbstractRector
|
|||||||
$leftConcat = new FuncCall(
|
$leftConcat = new FuncCall(
|
||||||
new Name('getDolGlobalString'),
|
new Name('getDolGlobalString'),
|
||||||
[new Arg($constName)]
|
[new Arg($constName)]
|
||||||
);
|
);
|
||||||
$rightConcat = $node->right;
|
$rightConcat = $node->right;
|
||||||
}
|
}
|
||||||
if ($this->isGlobalVar($node->right)) {
|
if ($this->isGlobalVar($node->right)) {
|
||||||
@@ -219,7 +219,7 @@ class GlobalToFunction extends AbstractRector
|
|||||||
$rightConcat = new FuncCall(
|
$rightConcat = new FuncCall(
|
||||||
new Name('getDolGlobalString'),
|
new Name('getDolGlobalString'),
|
||||||
[new Arg($constName)]
|
[new Arg($constName)]
|
||||||
);
|
);
|
||||||
$leftConcat = $node->left;
|
$leftConcat = $node->left;
|
||||||
}
|
}
|
||||||
if (!isset($leftConcat, $rightConcat)) {
|
if (!isset($leftConcat, $rightConcat)) {
|
||||||
@@ -238,6 +238,7 @@ class GlobalToFunction extends AbstractRector
|
|||||||
$node = $nodes->getFirstExpr();
|
$node = $nodes->getFirstExpr();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Now process all comparison like:
|
// Now process all comparison like:
|
||||||
// $conf->global->... Operator Value
|
// $conf->global->... Operator Value
|
||||||
|
|
||||||
@@ -264,11 +265,14 @@ class GlobalToFunction extends AbstractRector
|
|||||||
$typeofcomparison = 'NotIdentical';
|
$typeofcomparison = 'NotIdentical';
|
||||||
//var_dump($node->left);
|
//var_dump($node->left);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (empty($typeofcomparison)) {
|
if (empty($typeofcomparison)) {
|
||||||
return;
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -282,7 +286,8 @@ class GlobalToFunction extends AbstractRector
|
|||||||
$funcName = 'getDolGlobalString';
|
$funcName = 'getDolGlobalString';
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return;
|
$funcName = 'getDolGlobalString';
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
$constName = $this->getConstName($node->left);
|
$constName = $this->getConstName($node->left);
|
||||||
@@ -295,9 +300,9 @@ class GlobalToFunction extends AbstractRector
|
|||||||
new FuncCall(
|
new FuncCall(
|
||||||
new Name($funcName),
|
new Name($funcName),
|
||||||
[new Arg($constName)]
|
[new Arg($constName)]
|
||||||
),
|
),
|
||||||
$node->right
|
$node->right
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if ($typeofcomparison == 'NotEqual') {
|
if ($typeofcomparison == 'NotEqual') {
|
||||||
return new NotEqual(
|
return new NotEqual(
|
||||||
@@ -313,36 +318,36 @@ class GlobalToFunction extends AbstractRector
|
|||||||
new FuncCall(
|
new FuncCall(
|
||||||
new Name($funcName),
|
new Name($funcName),
|
||||||
[new Arg($constName)]
|
[new Arg($constName)]
|
||||||
),
|
),
|
||||||
$node->right
|
$node->right
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if ($typeofcomparison == 'GreaterOrEqual') {
|
if ($typeofcomparison == 'GreaterOrEqual') {
|
||||||
return new GreaterOrEqual(
|
return new GreaterOrEqual(
|
||||||
new FuncCall(
|
new FuncCall(
|
||||||
new Name($funcName),
|
new Name($funcName),
|
||||||
[new Arg($constName)]
|
[new Arg($constName)]
|
||||||
),
|
),
|
||||||
$node->right
|
$node->right
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if ($typeofcomparison == 'Smaller') {
|
if ($typeofcomparison == 'Smaller') {
|
||||||
return new Smaller(
|
return new Smaller(
|
||||||
new FuncCall(
|
new FuncCall(
|
||||||
new Name($funcName),
|
new Name($funcName),
|
||||||
[new Arg($constName)]
|
[new Arg($constName)]
|
||||||
),
|
),
|
||||||
$node->right
|
$node->right
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if ($typeofcomparison == 'SmallerOrEqual') {
|
if ($typeofcomparison == 'SmallerOrEqual') {
|
||||||
return new SmallerOrEqual(
|
return new SmallerOrEqual(
|
||||||
new FuncCall(
|
new FuncCall(
|
||||||
new Name($funcName),
|
new Name($funcName),
|
||||||
[new Arg($constName)]
|
[new Arg($constName)]
|
||||||
),
|
),
|
||||||
$node->right
|
$node->right
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if ($typeofcomparison == 'NotIdentical') {
|
if ($typeofcomparison == 'NotIdentical') {
|
||||||
return new NotIdentical(
|
return new NotIdentical(
|
||||||
@@ -382,7 +387,7 @@ class GlobalToFunction extends AbstractRector
|
|||||||
}
|
}
|
||||||
return \true;
|
return \true;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user