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

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,9 @@ private function shouldSkip(
}

// exists, but by @method annotation
if ($reflection instanceof AnnotationMethodReflection && ! $reflection->getDeclaringClass()->hasNativeMethod($reflection->getName())) {
if ($reflection instanceof AnnotationMethodReflection && ! $reflection->getDeclaringClass()->hasNativeMethod(
$reflection->getName()
)) {
return true;
}

Expand Down
46 changes: 8 additions & 38 deletions rules/Transform/Rector/Assign/PropertyAssignToMethodCallRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,21 @@

namespace Rector\Transform\Rector\Assign;

use Rector\Exception\ShouldNotHappenException;
use PhpParser\Node;
use PhpParser\Node\Expr\Assign;
use PhpParser\Node\Expr\PropertyFetch;
use PhpParser\Node\Expr\Variable;
use Rector\Configuration\Deprecation\Contract\DeprecatedInterface;
use Rector\Contract\Rector\ConfigurableRectorInterface;
use Rector\Rector\AbstractRector;
use Rector\Transform\ValueObject\PropertyAssignToMethodCall;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
use Webmozart\Assert\Assert;

/**
* @see \Rector\Tests\Transform\Rector\Assign\PropertyAssignToMethodCallRector\PropertyAssignToMethodCallRectorTest
* @deprecated as too narrow use-case and never used. Create custom rector instead if needed.
*/
final class PropertyAssignToMethodCallRector extends AbstractRector implements ConfigurableRectorInterface
final class PropertyAssignToMethodCallRector extends AbstractRector implements ConfigurableRectorInterface, DeprecatedInterface
{
/**
* @var PropertyAssignToMethodCall[]
*/
private array $propertyAssignsToMethodCalls = [];

public function getRuleDefinition(): RuleDefinition
{
return new RuleDefinition('Turn property assign of specific type and property name to method call', [
Expand Down Expand Up @@ -57,40 +51,16 @@ public function getNodeTypes(): array
*/
public function refactor(Node $node): ?Node
{
if (! $node->var instanceof PropertyFetch) {
return null;
}

$propertyFetchNode = $node->var;

/** @var Variable $propertyNode */
$propertyNode = $propertyFetchNode->var;

foreach ($this->propertyAssignsToMethodCalls as $propertyAssignToMethodCall) {
if (! $this->isName($propertyFetchNode, $propertyAssignToMethodCall->getOldPropertyName())) {
continue;
}

if (! $this->isObjectType($propertyFetchNode->var, $propertyAssignToMethodCall->getObjectType())) {
continue;
}

return $this->nodeFactory->createMethodCall(
$propertyNode,
$propertyAssignToMethodCall->getNewMethodName(),
[$node->expr]
);
}

return null;
throw new ShouldNotHappenException(sprintf(
'%s is deprecated as too narrow use-case and never used. Create custom rector instead if needed.',
self::class
));
}

/**
* @param mixed[] $configuration
*/
public function configure(array $configuration): void
{
Assert::allIsAOf($configuration, PropertyAssignToMethodCall::class);
$this->propertyAssignsToMethodCalls = $configuration;
}
}
3 changes: 3 additions & 0 deletions rules/Transform/ValueObject/PropertyAssignToMethodCall.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
use PHPStan\Type\ObjectType;
use Rector\Validation\RectorAssert;

/**
* @deprecated as related rule is deprecated
*/
final readonly class PropertyAssignToMethodCall
{
public function __construct(
Expand Down