mirror of
https://github.com/rectorphp/rector.git
synced 2025-02-19 23:55:32 +01:00
[StaticRemoval] Various fixes (#4245)
This commit is contained in:
parent
9431c8107b
commit
2630e1b900
@ -134,6 +134,7 @@ abstract class AbstractFluentChainMethodCallRector extends AbstractRector
|
|||||||
$classOfClassMethod[] = null;
|
$classOfClassMethod[] = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return count(array_unique($classOfClassMethod)) <= 1;
|
return count(array_unique($classOfClassMethod)) <= 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -195,13 +195,18 @@ CODE_SAMPLE
|
|||||||
|
|
||||||
// is the same class or external call?
|
// is the same class or external call?
|
||||||
$className = $this->getName($staticCall->class);
|
$className = $this->getName($staticCall->class);
|
||||||
|
|
||||||
if ($className === 'self') {
|
if ($className === 'self') {
|
||||||
return new MethodCall(new Variable(self::THIS), $staticCall->name, $staticCall->args);
|
return new MethodCall(new Variable(self::THIS), $staticCall->name, $staticCall->args);
|
||||||
}
|
}
|
||||||
|
|
||||||
$propertyName = $this->propertyNaming->fqnToVariableName($classType);
|
$propertyName = $this->propertyNaming->fqnToVariableName($classType);
|
||||||
$propertyFetch = new PropertyFetch(new Variable(self::THIS), $propertyName);
|
|
||||||
|
$currentMethodName = $staticCall->getAttribute(AttributeKey::METHOD_NAME);
|
||||||
|
if ($currentMethodName === MethodName::CONSTRUCT) {
|
||||||
|
$propertyFetch = new Variable($propertyName);
|
||||||
|
} else {
|
||||||
|
$propertyFetch = new PropertyFetch(new Variable(self::THIS), $propertyName);
|
||||||
|
}
|
||||||
return new MethodCall($propertyFetch, $staticCall->name, $staticCall->args);
|
return new MethodCall($propertyFetch, $staticCall->name, $staticCall->args);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -296,10 +301,30 @@ CODE_SAMPLE
|
|||||||
}
|
}
|
||||||
|
|
||||||
$propertyExpectedName = $this->propertyNaming->fqnToVariableName(new ObjectType($classType));
|
$propertyExpectedName = $this->propertyNaming->fqnToVariableName(new ObjectType($classType));
|
||||||
|
|
||||||
|
if ($this->isTypeAlreadyInParamMethod($constructClassMethod, $classType)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
$constructClassMethod->params[] = new Param(
|
$constructClassMethod->params[] = new Param(
|
||||||
new Variable($propertyExpectedName),
|
new Variable($propertyExpectedName),
|
||||||
null,
|
null,
|
||||||
new FullyQualified($this->classTypes)
|
new FullyQualified($classType)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function isTypeAlreadyInParamMethod(ClassMethod $classMethod, string $classType): bool
|
||||||
|
{
|
||||||
|
foreach ($classMethod->getParams() as $param) {
|
||||||
|
if ($param->type === null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->isName($param->type, $classType)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,31 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Rector\RemovingStatic\Tests\Rector\Class_\SingleStaticServiceToDynamicRector\Fixture;
|
||||||
|
|
||||||
|
use Rector\RemovingStatic\Tests\Rector\Class_\SingleStaticServiceToDynamicRector\Source\FirstStaticClass;
|
||||||
|
|
||||||
|
class ConstructAlreadyThereDependency
|
||||||
|
{
|
||||||
|
public function __construct(FirstStaticClass $firstStaticClass)
|
||||||
|
{
|
||||||
|
FirstStaticClass::someStaticFunction();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
|
-----
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Rector\RemovingStatic\Tests\Rector\Class_\SingleStaticServiceToDynamicRector\Fixture;
|
||||||
|
|
||||||
|
use Rector\RemovingStatic\Tests\Rector\Class_\SingleStaticServiceToDynamicRector\Source\FirstStaticClass;
|
||||||
|
|
||||||
|
class ConstructAlreadyThereDependency
|
||||||
|
{
|
||||||
|
public function __construct(FirstStaticClass $firstStaticClass)
|
||||||
|
{
|
||||||
|
$firstStaticClass->someStaticFunction();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
@ -50,10 +50,14 @@ final class VisibilityManipulator
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param ClassMethod|Property|ClassConst $node
|
* @param ClassMethod|Property $node
|
||||||
*/
|
*/
|
||||||
public function makeNonStatic(Node $node): void
|
public function makeNonStatic(Node $node): void
|
||||||
{
|
{
|
||||||
|
if (! $node->isStatic()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
$node->flags -= Class_::MODIFIER_STATIC;
|
$node->flags -= Class_::MODIFIER_STATIC;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -95,7 +95,7 @@ trait VisibilityTrait
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param ClassMethod|Property|ClassConst $node
|
* @param ClassMethod|Property $node
|
||||||
*/
|
*/
|
||||||
public function makeNonStatic(Node $node): void
|
public function makeNonStatic(Node $node): void
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user