Skip to content

Commit

Permalink
[Transform] Allow transform fileExtensions() to withFileExtensions() (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
samsonasik committed Feb 20, 2024
1 parent 70b1985 commit 23179d0
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 11 deletions.
@@ -0,0 +1,21 @@
<?php

declare(strict_types=1);

use Rector\Config\RectorConfig;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->fileExtensions(['php', 'phtml']);
};

?>
-----
<?php

declare(strict_types=1);

use Rector\Config\RectorConfig;

return \Rector\Config\RectorConfig::configure()->withFileExtensions(['php', 'phtml']);

?>
Expand Up @@ -128,33 +128,78 @@ public function refactor(Node $node): ?Node
if ($name === 'rule') {
Assert::isAOf($rules, Array_::class);
$rules->items[] = new ArrayItem($value);
} elseif (($name === 'rules')) {

continue;
}

if (($name === 'rules')) {
if ($value instanceof Array_) {
Assert::isAOf($rules, Array_::class);
$rules->items = array_merge($rules->items, $value->items);
} else {
$rules = $value;
}
} elseif ($name === 'paths') {

continue;
}

if ($name === 'paths') {
$paths = $value;
} elseif ($name === 'skip') {
continue;
}

if ($name === 'skip') {
$skips = $value;
} elseif ($name === 'autoloadPaths') {

continue;
}

if ($name === 'autoloadPaths') {
Assert::isAOf($value, Array_::class);
$autoloadPaths = $value;
} elseif ($name === 'bootstrapFiles') {

continue;
}

if ($name === 'bootstrapFiles') {
Assert::isAOf($value, Array_::class);
$bootstrapFiles = $value;
} elseif ($name === 'ruleWithConfiguration') {
$newExpr = $this->nodeFactory->createMethodCall($newExpr, 'withConfiguredRule', [$value, $args[1]->value]);

continue;
}

if ($name === 'ruleWithConfiguration') {
$newExpr = $this->nodeFactory->createMethodCall(
$newExpr,
'withConfiguredRule',
[$value, $args[1]->value]
);
$hasChanged = true;
} elseif ($name === 'sets') {

continue;
}

if ($name === 'sets') {
Assert::isAOf($value, Array_::class);
$sets->items = array_merge($sets->items, $value->items);
} else {
// implementing method by method
return null;

continue;
}

if ($name === 'fileExtensions') {
Assert::isAOf($value, Array_::class);
$newExpr = $this->nodeFactory->createMethodCall(
$newExpr,
'withFileExtensions',
[$value]
);
$hasChanged = true;

continue;
}

// implementing method by method
return null;
}

if (! $paths instanceof Array_ || $paths->items !== []) {
Expand Down

0 comments on commit 23179d0

Please sign in to comment.