forked from Wavyzz/dolibarr
Enhance rector
This commit is contained in:
@@ -5,6 +5,7 @@ declare(strict_types=1);
|
|||||||
use Rector\Config\RectorConfig;
|
use Rector\Config\RectorConfig;
|
||||||
use Rector\Core\ValueObject\PhpVersion;
|
use Rector\Core\ValueObject\PhpVersion;
|
||||||
use Rector\Set\ValueObject\LevelSetList;
|
use Rector\Set\ValueObject\LevelSetList;
|
||||||
|
use Rector\Set\ValueObject\SetList;
|
||||||
|
|
||||||
return static function (RectorConfig $rectorConfig): void {
|
return static function (RectorConfig $rectorConfig): void {
|
||||||
$rectorConfig->phpVersion(PhpVersion::PHP_71);
|
$rectorConfig->phpVersion(PhpVersion::PHP_71);
|
||||||
@@ -55,8 +56,19 @@ 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\EmptyGlobalToFunction::class);
|
$rectorConfig->rule(Dolibarr\Rector\Renaming\EmptyGlobalToFunction::class);
|
||||||
|
|
||||||
// Add all predefined rules to migrate to up to php 71
|
// Add all predefined rules to migrate to up to php 71.
|
||||||
// $rectorConfig->sets([
|
// Warning this break tab spacing of arrays on several lines
|
||||||
// LevelSetList::UP_TO_PHP_71
|
/*$rectorConfig->sets([
|
||||||
// ]);
|
LevelSetList::UP_TO_PHP_70
|
||||||
|
]);*/
|
||||||
|
// Add predefined rules for a given version only
|
||||||
|
//$rectorConfig->import(SetList::PHP_70);
|
||||||
|
//$rectorConfig->import(SetList::PHP_71);
|
||||||
|
//$rectorConfig->import(SetList::PHP_72);
|
||||||
|
//$rectorConfig->import(SetList::PHP_73);
|
||||||
|
//$rectorConfig->import(SetList::PHP_74);
|
||||||
|
//$rectorConfig->import(SetList::PHP_80);
|
||||||
|
//$rectorConfig->import(SetList::PHP_81);
|
||||||
|
//$rectorConfig->import(SetList::PHP_82);
|
||||||
|
//$rectorConfig->import(SetList::PHP_83);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ namespace Dolibarr\Rector\Renaming;
|
|||||||
|
|
||||||
use PhpParser\Node;
|
use PhpParser\Node;
|
||||||
use PhpParser\Node\Arg;
|
use PhpParser\Node\Arg;
|
||||||
|
use PhpParser\Node\Expr\ArrayItem;
|
||||||
use PhpParser\Node\Expr\ArrayDimFetch;
|
use PhpParser\Node\Expr\ArrayDimFetch;
|
||||||
use PhpParser\Node\Expr\BinaryOp\BooleanAnd;
|
use PhpParser\Node\Expr\BinaryOp\BooleanAnd;
|
||||||
use PhpParser\Node\Expr\BinaryOp\Concat;
|
use PhpParser\Node\Expr\BinaryOp\Concat;
|
||||||
@@ -73,7 +74,7 @@ class GlobalToFunction extends AbstractRector
|
|||||||
*/
|
*/
|
||||||
public function getNodeTypes(): array
|
public function getNodeTypes(): array
|
||||||
{
|
{
|
||||||
return [FuncCall::class, MethodCall::class, Equal::class, NotEqual::class, Greater::class, GreaterOrEqual::class, Smaller::class, SmallerOrEqual::class, NotIdentical::class, BooleanAnd::class, Concat::class, ArrayDimFetch::class];
|
return [FuncCall::class, MethodCall::class, Equal::class, NotEqual::class, Greater::class, GreaterOrEqual::class, Smaller::class, SmallerOrEqual::class, NotIdentical::class, BooleanAnd::class, Concat::class, ArrayItem::class, ArrayDimFetch::class];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -85,6 +86,23 @@ class GlobalToFunction extends AbstractRector
|
|||||||
*/
|
*/
|
||||||
public function refactor(Node $node)
|
public function refactor(Node $node)
|
||||||
{
|
{
|
||||||
|
if ($node instanceof Node\Expr\ArrayItem) {
|
||||||
|
if (!isset($node->key)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if ($this->isGlobalVar($node->value)) {
|
||||||
|
$constName = $this->getConstName($node->value);
|
||||||
|
if (empty($constName)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$node->value = new FuncCall(
|
||||||
|
new Name('getDolGlobalString'),
|
||||||
|
[new Arg($constName)]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return $node;
|
||||||
|
}
|
||||||
|
|
||||||
if ($node instanceof Node\Expr\ArrayDimFetch) {
|
if ($node instanceof Node\Expr\ArrayDimFetch) {
|
||||||
if (!isset($node->dim)) {
|
if (!isset($node->dim)) {
|
||||||
return;
|
return;
|
||||||
|
|||||||
Reference in New Issue
Block a user