Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"description": "Rector upgrades rules for Laravel Framework",
"require": {
"php": ">=8.1",
"rector/rector": "^0.15.12"
"rector/rector": "^0.17.1"
},
"require-dev": {
"phpunit/phpunit": "^10.0",
Expand Down
4 changes: 2 additions & 2 deletions config/sets/laravel-static-to-injection.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
use Rector\Renaming\Rector\Name\RenameClassRector;
use Rector\Transform\Rector\FuncCall\FuncCallToNewRector;
use Rector\Transform\Rector\StaticCall\StaticCallToMethodCallRector;
use Rector\Transform\ValueObject\ArgumentFuncCallToMethodCall;
use Rector\Transform\ValueObject\ArrayFuncCallToMethodCall;
use Rector\Transform\ValueObject\StaticCallToMethodCall;
use RectorLaravel\Rector\FuncCall\ArgumentFuncCallToMethodCallRector;
use RectorLaravel\Rector\FuncCall\HelperFuncCallToFacadeClassRector;
use RectorLaravel\Rector\StaticCall\RequestStaticValidateToInjectRector;
use RectorLaravel\ValueObject\ArgumentFuncCallToMethodCall;
use RectorLaravel\ValueObject\ArrayFuncCallToMethodCall;

/**
* @see https://www.freecodecamp.org/news/moving-away-from-magic-or-why-i-dont-want-to-use-laravel-anymore-2ce098c979bd/
Expand Down
1 change: 0 additions & 1 deletion src/NodeFactory/AppAssignFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,5 @@ private function decorateWithVarAnnotation(
);

$phpDocInfo->addTagValueNode($varTagValueNode);
$phpDocInfo->makeSingleLined();
}
}
22 changes: 13 additions & 9 deletions src/Rector/Assign/CallOnAppArrayAccessToStandaloneAssignRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
use PhpParser\Node\Expr\Assign;
use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Expr\Variable;
use PhpParser\Node\Stmt\Expression;
use PHPStan\Type\ObjectType;
use Rector\Core\Rector\AbstractRector;
use Rector\PostRector\Collector\NodesToAddCollector;
use RectorLaravel\NodeFactory\AppAssignFactory;
use RectorLaravel\ValueObject\ServiceNameTypeAndVariableName;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
Expand All @@ -30,7 +30,6 @@ final class CallOnAppArrayAccessToStandaloneAssignRector extends AbstractRector

public function __construct(
private readonly AppAssignFactory $appAssignFactory,
private readonly NodesToAddCollector $nodesToAddCollector,
) {
$this->serviceNameTypeAndVariableNames[] = new ServiceNameTypeAndVariableName(
'validator',
Expand All @@ -44,19 +43,23 @@ public function __construct(
*/
public function getNodeTypes(): array
{
return [Assign::class];
return [Expression::class];
}

/**
* @param Assign $node
* @param Expression $node
*/
public function refactor(Node $node): ?Node
public function refactor(Node $node): Node|array|int|null
{
if (! $node->expr instanceof MethodCall) {
if (! $node->expr instanceof Assign) {
return null;
}

$methodCall = $node->expr;
if (! $node->expr->expr instanceof MethodCall) {
return null;
}

$methodCall = $node->expr->expr;
if (! $methodCall->var instanceof ArrayDimFetch) {
return null;
}
Expand Down Expand Up @@ -85,10 +88,11 @@ public function refactor(Node $node): ?Node
$methodCall->var
);

$this->nodesToAddCollector->addNodeBeforeNode($assignExpression, $node);
$methodCall->var = new Variable($serviceNameTypeAndVariableName->getVariableName());

return $node;
// the nop is a workaround because the docs of the first node are somehow stripped away
// this will add a newline but the docs will be preserved
return [new Node\Stmt\Nop(), $assignExpression, $node];
}

return null;
Expand Down
6 changes: 3 additions & 3 deletions src/Rector/ClassMethod/MigrateToSimplifiedAttributeRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use PhpParser\Node\Stmt\ClassMethod;
use PhpParser\Node\Stmt\Expression;
use PhpParser\Node\Stmt\Return_;
use PhpParser\NodeTraverser;
use PHPStan\Type\ObjectType;
use Rector\Core\Rector\AbstractRector;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
Expand All @@ -41,7 +42,7 @@ public function getNodeTypes(): array
/**
* @param ClassMethod $node
*/
public function refactor(Node $node): ?Node
public function refactor(Node $node): Node|array|int|null
{
if ($this->shouldSkipNode($node)) {
return null;
Expand Down Expand Up @@ -82,8 +83,7 @@ public function refactor(Node $node): ?Node
// is placed on the model and remove the mutator,
// so we don't run the refactoring twice
if ($accessor instanceof ClassMethod && $mutator instanceof ClassMethod && $this->isMutator($nodeName)) {
$this->removeNode($mutator);
return null;
return NodeTraverser::REMOVE_NODE;
}

if ($accessor instanceof ClassMethod && $mutator instanceof ClassMethod) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public function refactor(Node $node): ?Node
return null;
}

$this->removeNode($deferProperty);
unset($node->stmts[array_search($deferProperty, $node->stmts, true)]);

$node->implements[] = new FullyQualified('Illuminate\Contracts\Support\DeferrableProvider');

Expand Down
5 changes: 3 additions & 2 deletions src/Rector/Class_/UnifyModelDatesWithCastsRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function getNodeTypes(): array
/**
* @param Class_ $node
*/
public function refactor(Node $node): ?Node
public function refactor(Node $node)
{
if (! $this->isObjectType($node, new ObjectType('Illuminate\Database\Eloquent\Model'))) {
return null;
Expand Down Expand Up @@ -123,7 +123,8 @@ public function refactor(Node $node): ?Node
);
}

$this->nodeRemover->removeNode($datesProperty);
unset($node->stmts[array_search($datesProperty, $node->stmts, true)]);

return null;
}

Expand Down
Loading