This commit is contained in:
Dan Harrin
2023-02-25 21:45:09 +00:00
parent d9ab466b25
commit d13383c14e
6 changed files with 63 additions and 10 deletions
@@ -1,6 +0,0 @@
<?php
use Rector\Config\RectorConfig;
return static function (RectorConfig $rectorConfig): void {
};
@@ -2,6 +2,7 @@
namespace Filament\Upgrade\App;
use phpDocumentor\Reflection\Types\Null_;
use PhpParser\Node;
use PhpParser\Node\Expr\ConstFetch;
use PhpParser\Node\Expr\Variable;
@@ -10,7 +11,10 @@ use PhpParser\Node\Name;
use PhpParser\Node\Param;
use PhpParser\Node\Stmt\Class_;
use PhpParser\Node\Stmt\ClassMethod;
use PhpParser\Node\UnionType;
use Rector\Core\Rector\AbstractRector;
use Rector\Naming\Guard\BreakingVariableRenameGuard;
use Rector\Naming\Naming\ExpectedNameResolver;
use Rector\Naming\VariableRenamer;
use Rector\NodeTypeResolver\Node\AttributeKey;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
@@ -0,0 +1,51 @@
<?php
namespace Filament\Upgrade\Forms;
use PhpParser\Node;
use PhpParser\Node\Expr\ArrowFunction;
use PhpParser\Node\Expr\Closure;
use PhpParser\Node\Name;
use Rector\Core\Rector\AbstractRector;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
class FixGetSetClosureTypesRector extends AbstractRector
{
public function getNodeTypes(): array
{
return [ArrowFunction::class, Closure::class];
}
public function refactor(Node | ArrowFunction | Closure $node): ?Node
{
foreach ($node->params as $param) {
if (! $param->type) {
continue;
}
if (($param->var->name === 'get') && $this->isName($param->type, 'Closure')) {
$param->type = new Name('\\Filament\\Forms\\Get');
}
if (($param->var->name === 'set') && $this->isName($param->type, 'Closure')) {
$param->type = new Name('\\Filament\\Forms\\Set');
}
}
return $node;
}
public function getRuleDefinition(): RuleDefinition
{
return new RuleDefinition(
'Fix the types for `$get` and `$set` closure arguments',
[
new CodeSample(
'function (Closure $get, Closure $set)',
'function (\\Filament\\Forms\\Get $get, \\Filament\\Forms\\Set $set)',
),
]
);
}
}
@@ -48,4 +48,4 @@ class SecondaryToGrayColorRector extends AbstractRector
]
);
}
}
}
+1 -1
View File
@@ -130,4 +130,4 @@ foreach ($iconNameChanges as $oldName => $newName) {
$changes["heroicon-s-{$oldName}"] = "heroicon-m-{$newName}";
}
return $changes;
return $changes;
+6 -2
View File
@@ -3,18 +3,22 @@
use Filament\Upgrade\App\MoveImportedClassesRector;
use Filament\Upgrade\App\SimpleMethodChangesRector;
use Filament\Upgrade\App\SimplePropertyChangesRector;
use Filament\Upgrade\Forms\FixGetSetClosureTypesRector;
use Filament\Upgrade\SecondaryToGrayColorRector;
use Rector\Config\RectorConfig;
use Rector\Renaming\Rector\String_\RenameStringRector;
return static function (RectorConfig $rectorConfig): void {
$rectorConfig->rules([
FixGetSetClosureTypesRector::class,
MoveImportedClassesRector::class,
SecondaryToGrayColorRector::class,
SimpleMethodChangesRector::class,
SimplePropertyChangesRector::class,
]);
$heroiconChanges = require 'heroicon-changes.php';
$rectorConfig->ruleWithConfiguration(RenameStringRector::class, $heroiconChanges);
$rectorConfig->ruleWithConfiguration(
RenameStringRector::class,
require 'heroicon-changes.php',
);
};