2
0
forked from Wavyzz/dolibarr

NEW Add a rule to fix empty($conf->global->...) into !getDolGlobal...

This commit is contained in:
Laurent Destailleur
2023-10-24 16:09:23 +02:00
parent 70e475d0ce
commit 6913cafadd
4 changed files with 292 additions and 16 deletions

View File

@@ -21,6 +21,10 @@ 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\Greater;
use PhpParser\Node\Expr\BinaryOp\GreaterOrEqual;
use PhpParser\Node\Expr\BinaryOp\Smaller;
use PhpParser\Node\Expr\BinaryOp\SmallerOrEqual;
/**
* Class with Rector custom rule to fix code
@@ -64,7 +68,7 @@ class GlobalToFunction extends AbstractRector
*/
public function getNodeTypes(): array
{
return [Equal::class, BooleanAnd::class, Concat::class, ArrayDimFetch::class];
return [Equal::class, Greater::class, GreaterOrEqual::class, Smaller::class, SmallerOrEqual::class, BooleanAnd::class, Concat::class, ArrayDimFetch::class];
}
/**
@@ -128,9 +132,26 @@ class GlobalToFunction extends AbstractRector
/** @var Equal $node */
$node = $nodes->getFirstExpr();
}
if (!$node instanceof Equal) {
$typeofcomparison = '';
if ($node instanceof Equal) {
$typeofcomparison = 'Equal';
}
if ($node instanceof Greater) {
$typeofcomparison = 'Greater';
}
if ($node instanceof GreaterOrEqual) {
$typeofcomparison = 'GreaterOrEqual';
}
if ($node instanceof Smaller) {
$typeofcomparison = 'Smaller';
}
if ($node instanceof SmallerOrEqual) {
$typeofcomparison = 'SmallerOrEqual';
}
if (empty($typeofcomparison)) {
return;
};
}
if (!$this->isGlobalVar($node->left)) {
return;
@@ -152,13 +173,52 @@ class GlobalToFunction extends AbstractRector
if (empty($constName)) {
return;
}
return new Equal(
new FuncCall(
new Name($funcName),
[new Arg($constName)]
),
$node->right
);
if ($typeofcomparison == 'Equal') {
return new Equal(
new FuncCall(
new Name($funcName),
[new Arg($constName)]
),
$node->right
);
}
if ($typeofcomparison == 'Greater') {
return new Greater(
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
);
}
}
/**