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
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\KnownMagicClassMethodTypeRector\Fixture;

use Rector\Tests\TypeDeclaration\Rector\ClassMethod\KnownMagicClassMethodTypeRector\Source\ParentClassWithCall;

final class SkipExistsInParent extends ParentClassWithCall
{
public function __call($method, $args)
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

declare(strict_types=1);

namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\KnownMagicClassMethodTypeRector\Source;

abstract class ParentClassWithCall
{
public function __call($method, $args)
{
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use PhpParser\Node\Stmt\Class_;
use Rector\Rector\AbstractRector;
use Rector\ValueObject\MethodName;
use Rector\VendorLocker\ParentClassMethodTypeOverrideGuard;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;

Expand All @@ -20,6 +21,10 @@
*/
final class KnownMagicClassMethodTypeRector extends AbstractRector
{
public function __construct(
private readonly ParentClassMethodTypeOverrideGuard $parentClassMethodTypeOverrideGuard
){
}
public function getRuleDefinition(): RuleDefinition
{
return new RuleDefinition(
Expand Down Expand Up @@ -68,18 +73,24 @@ public function refactor(Node $node): ?Node
continue;
}

if ($this->isName($classMethod, MethodName::CALL)) {
$firstParam = $classMethod->getParams()[0];
if (! $firstParam->type instanceof Node) {
$firstParam->type = new Identifier('string');
$hasChanged = true;
}
if (! $this->isName($classMethod, MethodName::CALL)) {
continue;
}

if ($this->parentClassMethodTypeOverrideGuard->hasParentClassMethod($classMethod)) {
return null;
}

$firstParam = $classMethod->getParams()[0];
if (! $firstParam->type instanceof Node) {
$firstParam->type = new Identifier('string');
$hasChanged = true;
}

$secondParam = $classMethod->getParams()[1];
if (! $secondParam->type instanceof Node) {
$secondParam->type = new Name('array');
$hasChanged = true;
}
$secondParam = $classMethod->getParams()[1];
if (! $secondParam->type instanceof Node) {
$secondParam->type = new Name('array');
$hasChanged = true;
}
}

Expand Down