Skip to content

Commit 25909ad

Browse files
[depre] Deprecate PropertyAssignToMethodCallRector as too narrow use-case and never used (#7561)
* [depre] Deprecate PropertyAssignToMethodCallRector as too narrow use-case and never used * [ci-review] Rector Rectify --------- Co-authored-by: GitHub Action <actions@github.com>
1 parent bc57aa6 commit 25909ad

File tree

8 files changed

+14
-139
lines changed

8 files changed

+14
-139
lines changed

rules-tests/Transform/Rector/Assign/PropertyAssignToMethodCallRector/Fixture/fixture.php.inc

Lines changed: 0 additions & 33 deletions
This file was deleted.

rules-tests/Transform/Rector/Assign/PropertyAssignToMethodCallRector/Fixture/skip_invalid_type.php.inc

Lines changed: 0 additions & 14 deletions
This file was deleted.

rules-tests/Transform/Rector/Assign/PropertyAssignToMethodCallRector/PropertyAssignToMethodCallRectorTest.php

Lines changed: 0 additions & 28 deletions
This file was deleted.

rules-tests/Transform/Rector/Assign/PropertyAssignToMethodCallRector/Source/ChoiceControl.php

Lines changed: 0 additions & 10 deletions
This file was deleted.

rules-tests/Transform/Rector/Assign/PropertyAssignToMethodCallRector/config/configured_rule.php

Lines changed: 0 additions & 15 deletions
This file was deleted.

rules/CodingStyle/Rector/FunctionLike/FunctionLikeToFirstClassCallableRector.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,9 @@ private function shouldSkip(
194194
}
195195

196196
// exists, but by @method annotation
197-
if ($reflection instanceof AnnotationMethodReflection && ! $reflection->getDeclaringClass()->hasNativeMethod($reflection->getName())) {
197+
if ($reflection instanceof AnnotationMethodReflection && ! $reflection->getDeclaringClass()->hasNativeMethod(
198+
$reflection->getName()
199+
)) {
198200
return true;
199201
}
200202

rules/Transform/Rector/Assign/PropertyAssignToMethodCallRector.php

Lines changed: 8 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,21 @@
44

55
namespace Rector\Transform\Rector\Assign;
66

7+
use Rector\Exception\ShouldNotHappenException;
78
use PhpParser\Node;
89
use PhpParser\Node\Expr\Assign;
9-
use PhpParser\Node\Expr\PropertyFetch;
10-
use PhpParser\Node\Expr\Variable;
10+
use Rector\Configuration\Deprecation\Contract\DeprecatedInterface;
1111
use Rector\Contract\Rector\ConfigurableRectorInterface;
1212
use Rector\Rector\AbstractRector;
1313
use Rector\Transform\ValueObject\PropertyAssignToMethodCall;
1414
use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample;
1515
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
16-
use Webmozart\Assert\Assert;
1716

1817
/**
19-
* @see \Rector\Tests\Transform\Rector\Assign\PropertyAssignToMethodCallRector\PropertyAssignToMethodCallRectorTest
18+
* @deprecated as too narrow use-case and never used. Create custom rector instead if needed.
2019
*/
21-
final class PropertyAssignToMethodCallRector extends AbstractRector implements ConfigurableRectorInterface
20+
final class PropertyAssignToMethodCallRector extends AbstractRector implements ConfigurableRectorInterface, DeprecatedInterface
2221
{
23-
/**
24-
* @var PropertyAssignToMethodCall[]
25-
*/
26-
private array $propertyAssignsToMethodCalls = [];
27-
2822
public function getRuleDefinition(): RuleDefinition
2923
{
3024
return new RuleDefinition('Turn property assign of specific type and property name to method call', [
@@ -57,40 +51,16 @@ public function getNodeTypes(): array
5751
*/
5852
public function refactor(Node $node): ?Node
5953
{
60-
if (! $node->var instanceof PropertyFetch) {
61-
return null;
62-
}
63-
64-
$propertyFetchNode = $node->var;
65-
66-
/** @var Variable $propertyNode */
67-
$propertyNode = $propertyFetchNode->var;
68-
69-
foreach ($this->propertyAssignsToMethodCalls as $propertyAssignToMethodCall) {
70-
if (! $this->isName($propertyFetchNode, $propertyAssignToMethodCall->getOldPropertyName())) {
71-
continue;
72-
}
73-
74-
if (! $this->isObjectType($propertyFetchNode->var, $propertyAssignToMethodCall->getObjectType())) {
75-
continue;
76-
}
77-
78-
return $this->nodeFactory->createMethodCall(
79-
$propertyNode,
80-
$propertyAssignToMethodCall->getNewMethodName(),
81-
[$node->expr]
82-
);
83-
}
84-
85-
return null;
54+
throw new ShouldNotHappenException(sprintf(
55+
'%s is deprecated as too narrow use-case and never used. Create custom rector instead if needed.',
56+
self::class
57+
));
8658
}
8759

8860
/**
8961
* @param mixed[] $configuration
9062
*/
9163
public function configure(array $configuration): void
9264
{
93-
Assert::allIsAOf($configuration, PropertyAssignToMethodCall::class);
94-
$this->propertyAssignsToMethodCalls = $configuration;
9565
}
9666
}

rules/Transform/ValueObject/PropertyAssignToMethodCall.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
use PHPStan\Type\ObjectType;
88
use Rector\Validation\RectorAssert;
99

10+
/**
11+
* @deprecated as related rule is deprecated
12+
*/
1013
final readonly class PropertyAssignToMethodCall
1114
{
1215
public function __construct(

0 commit comments

Comments
 (0)