mirror of
https://github.com/rectorphp/rector.git
synced 2024-07-22 01:10:23 +00:00
correct names manually back to desired state
This commit is contained in:
parent
015525c6c3
commit
c1e1053d1c
@ -45,9 +45,9 @@ final class ClassMethodParamVendorLockResolver extends AbstractNodeVendorLockRes
|
||||
|
||||
private function isParentClassVendorLocking(int $paramPosition, string $parentClassName, string $methodName): ?bool
|
||||
{
|
||||
$class = $this->parsedNodeCollector->findClass($parentClassName);
|
||||
if ($class !== null) {
|
||||
$parentClassMethod = $class->getMethod($methodName);
|
||||
$parentClass = $this->parsedNodeCollector->findClass($parentClassName);
|
||||
if ($parentClass !== null) {
|
||||
$parentClassMethod = $parentClass->getMethod($methodName);
|
||||
// parent class method in local scope → it's ok
|
||||
if ($parentClassMethod !== null) {
|
||||
// parent method has no type → we cannot change it here
|
||||
|
@ -41,9 +41,9 @@ final class ClassMethodReturnVendorLockResolver extends AbstractNodeVendorLockRe
|
||||
|
||||
private function isVendorLockedByParentClass(string $parentClassName, string $methodName): bool
|
||||
{
|
||||
$class = $this->parsedNodeCollector->findClass($parentClassName);
|
||||
if ($class !== null) {
|
||||
$parentClassMethod = $class->getMethod($methodName);
|
||||
$parentClass = $this->parsedNodeCollector->findClass($parentClassName);
|
||||
if ($parentClass !== null) {
|
||||
$parentClassMethod = $parentClass->getMethod($methodName);
|
||||
// validate type is conflicting
|
||||
// parent class method in local scope → it's ok
|
||||
if ($parentClassMethod !== null) {
|
||||
|
@ -73,13 +73,13 @@ PHP
|
||||
return null;
|
||||
}
|
||||
|
||||
$allConstants = $node->consts;
|
||||
$allConsts = $node->consts;
|
||||
|
||||
/** @var Const_ $const */
|
||||
$const = array_shift($allConstants);
|
||||
$node->consts = [$const];
|
||||
/** @var Const_ $firstConst */
|
||||
$firstConst = array_shift($allConsts);
|
||||
$node->consts = [$firstConst];
|
||||
|
||||
foreach ($allConstants as $anotherConstant) {
|
||||
foreach ($allConsts as $anotherConstant) {
|
||||
$nextClassConst = new ClassConst([$anotherConstant], $node->flags, $node->getAttributes());
|
||||
$this->addNodeAfterNode($nextClassConst, $node);
|
||||
}
|
||||
@ -92,9 +92,9 @@ PHP
|
||||
}
|
||||
|
||||
$allProperties = $node->props;
|
||||
/** @var PropertyProperty $propertyProperty */
|
||||
$propertyProperty = array_shift($allProperties);
|
||||
$node->props = [$propertyProperty];
|
||||
/** @var PropertyProperty $firstPropertyProperty */
|
||||
$firstPropertyProperty = array_shift($allProperties);
|
||||
$node->props = [$firstPropertyProperty];
|
||||
|
||||
foreach ($allProperties as $anotherProperty) {
|
||||
$nextProperty = new Property($node->flags, [$anotherProperty], $node->getAttributes());
|
||||
|
@ -102,8 +102,8 @@ PHP
|
||||
*/
|
||||
public function refactor(Node $node): ?Node
|
||||
{
|
||||
$classMethod = $node->getMethod('__construct');
|
||||
if ($classMethod === null) {
|
||||
$constructorClassMethod = $node->getMethod('__construct');
|
||||
if ($constructorClassMethod === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -113,7 +113,7 @@ PHP
|
||||
return null;
|
||||
}
|
||||
|
||||
$managerRegistryParam = $this->resolveManagerRegistryParam($classMethod);
|
||||
$managerRegistryParam = $this->resolveManagerRegistryParam($constructorClassMethod);
|
||||
|
||||
// no registry manager in the constructor
|
||||
if ($managerRegistryParam === null) {
|
||||
@ -122,7 +122,7 @@ PHP
|
||||
|
||||
if ($registryCalledMethods === [self::GET_MANAGER]) {
|
||||
// the manager registry is needed only get entity manager → we don't need it now
|
||||
$this->removeManagerRegistryDependency($node, $classMethod, $managerRegistryParam);
|
||||
$this->removeManagerRegistryDependency($node, $constructorClassMethod, $managerRegistryParam);
|
||||
}
|
||||
|
||||
$this->replaceEntityRegistryVariableWithEntityManagerProperty($node);
|
||||
@ -131,7 +131,7 @@ PHP
|
||||
// add entity manager via constructor
|
||||
$this->addConstructorDependencyWithProperty(
|
||||
$node,
|
||||
$classMethod,
|
||||
$constructorClassMethod,
|
||||
self::ENTITY_MANAGER,
|
||||
new FullyQualifiedObjectType('Doctrine\ORM\EntityManagerInterface')
|
||||
);
|
||||
|
@ -104,10 +104,10 @@ PHP
|
||||
}
|
||||
|
||||
// A. try find "setUuid()" call on the same object later
|
||||
$methodCall = $this->getSetUuidMethodCallOnSameVariable($node);
|
||||
if ($methodCall !== null) {
|
||||
$node->args = $methodCall->args;
|
||||
$this->removeNode($methodCall);
|
||||
$setUuidMethodCall = $this->getSetUuidMethodCallOnSameVariable($node);
|
||||
if ($setUuidMethodCall !== null) {
|
||||
$node->args = $setUuidMethodCall->args;
|
||||
$this->removeNode($setUuidMethodCall);
|
||||
return $node;
|
||||
}
|
||||
|
||||
|
@ -158,16 +158,16 @@ PHP
|
||||
|
||||
private function findParentClassConstantAndRefactorIfPossible(string $class, string $constant): ?ConstantVisibility
|
||||
{
|
||||
$classConst = $this->parentClassConstantNodeFinder->find($class, $constant);
|
||||
$parentClassConst = $this->parentClassConstantNodeFinder->find($class, $constant);
|
||||
|
||||
if ($classConst !== null) {
|
||||
if ($parentClassConst !== null) {
|
||||
// Make sure the parent's constant has been refactored
|
||||
$this->refactor($classConst);
|
||||
$this->refactor($parentClassConst);
|
||||
|
||||
return new ConstantVisibility(
|
||||
$classConst->isPublic(),
|
||||
$classConst->isProtected(),
|
||||
$classConst->isPrivate()
|
||||
$parentClassConst->isPublic(),
|
||||
$parentClassConst->isProtected(),
|
||||
$parentClassConst->isPrivate()
|
||||
);
|
||||
// If the constant isn't declared in the parent, it might be declared in the parent's parent
|
||||
}
|
||||
|
@ -104,12 +104,12 @@ final class MultipleClassFileToPsr4ClassesRectorTest extends AbstractFileSystemR
|
||||
*/
|
||||
public function testSkip(SmartFileInfo $originalFile): void
|
||||
{
|
||||
$contents = $originalFile->getContents();
|
||||
$originalContents = $originalFile->getContents();
|
||||
|
||||
$this->doTestFileInfo($originalFile);
|
||||
|
||||
$this->assertFileExists($originalFile->getRealPath());
|
||||
$this->assertStringEqualsFile($originalFile->getRealPath(), $contents);
|
||||
$this->assertStringEqualsFile($originalFile->getRealPath(), $originalContents);
|
||||
}
|
||||
|
||||
public function provideDataForSkip(): Iterator
|
||||
|
@ -208,7 +208,7 @@ PHP
|
||||
// add all properties to class
|
||||
$class = $this->addNewPropertiesToClass($class, $newProperties);
|
||||
|
||||
$expression = $this->createParentSetUpStaticCall();
|
||||
$parentSetUpStaticCallExpression = $this->createParentSetUpStaticCall();
|
||||
foreach ($newProperties as $type) {
|
||||
// container fetch assign
|
||||
$assign = $this->createContainerGetTypeToPropertyAssign($type);
|
||||
@ -217,9 +217,9 @@ PHP
|
||||
|
||||
// get setup or create a setup add add it there
|
||||
if ($setupClassMethod !== null) {
|
||||
$this->updateSetUpMethod($setupClassMethod, $expression, $assign);
|
||||
$this->updateSetUpMethod($setupClassMethod, $parentSetUpStaticCallExpression, $assign);
|
||||
} else {
|
||||
$setUpMethod = $this->createSetUpMethod($expression, $assign);
|
||||
$setUpMethod = $this->createSetUpMethod($parentSetUpStaticCallExpression, $assign);
|
||||
$this->classInsertManipulator->addAsFirstMethod($class, $setUpMethod);
|
||||
}
|
||||
}
|
||||
|
@ -80,8 +80,8 @@ final class UniqueObjectFactoryFactory
|
||||
$factoryClassBuilder->addStmts($properties);
|
||||
|
||||
// constructor
|
||||
$classMethod = $this->createConstructMethod($objectType);
|
||||
$factoryClassBuilder->addStmt($classMethod);
|
||||
$constructorClassMethod = $this->createConstructMethod($objectType);
|
||||
$factoryClassBuilder->addStmt($constructorClassMethod);
|
||||
|
||||
// create
|
||||
$createMethod = $this->createCreateMethod($class, $className, $properties);
|
||||
|
@ -200,13 +200,13 @@ PHP
|
||||
*/
|
||||
private function resolveConstructorParamClassTypes(Class_ $class): array
|
||||
{
|
||||
$classMethod = $class->getMethod(self::CONSTRUCTOR_METHOD_NAME);
|
||||
if ($classMethod === null) {
|
||||
$constructorClassMethod = $class->getMethod(self::CONSTRUCTOR_METHOD_NAME);
|
||||
if ($constructorClassMethod === null) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$objectTypes = [];
|
||||
foreach ($classMethod->getParams() as $param) {
|
||||
foreach ($constructorClassMethod->getParams() as $param) {
|
||||
$paramType = $this->getObjectType($param);
|
||||
$paramType = $this->popFirstObjectTypeFromUnionType($paramType);
|
||||
|
||||
|
@ -240,11 +240,11 @@ PHP
|
||||
*/
|
||||
private function createGetSubscribedEventsClassMethod(array $eventsToMethods): ClassMethod
|
||||
{
|
||||
$classMethod = $this->nodeFactory->createPublicMethod('getSubscribedEvents');
|
||||
$getSubscribersClassMethod = $this->nodeFactory->createPublicMethod('getSubscribedEvents');
|
||||
|
||||
$eventsToMethodsArray = new Array_();
|
||||
|
||||
$this->makeStatic($classMethod);
|
||||
$this->makeStatic($getSubscribersClassMethod);
|
||||
|
||||
foreach ($eventsToMethods as $eventName => $methodNamesWithPriorities) {
|
||||
$eventNameExpr = $this->createEventName($eventName);
|
||||
@ -261,10 +261,10 @@ PHP
|
||||
}
|
||||
}
|
||||
|
||||
$classMethod->stmts[] = new Return_($eventsToMethodsArray);
|
||||
$this->decorateClassMethodWithReturnType($classMethod);
|
||||
$getSubscribersClassMethod->stmts[] = new Return_($eventsToMethodsArray);
|
||||
$this->decorateClassMethodWithReturnType($getSubscribersClassMethod);
|
||||
|
||||
return $classMethod;
|
||||
return $getSubscribersClassMethod;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -185,18 +185,18 @@ PHP
|
||||
return null;
|
||||
}
|
||||
|
||||
$classMethod = $formTypeClass->getMethod('__construct');
|
||||
$constructorClassMethod = $formTypeClass->getMethod('__construct');
|
||||
|
||||
// nothing we can do, out of scope
|
||||
if ($classMethod === null) {
|
||||
if ($constructorClassMethod === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$this->addBuildFormMethod($formTypeClass, $classMethod);
|
||||
$this->addBuildFormMethod($formTypeClass, $constructorClassMethod);
|
||||
$this->addConfigureOptionsMethod($formTypeClass, $namesToArgs);
|
||||
|
||||
// remove ctor
|
||||
$this->removeNode($classMethod);
|
||||
$this->removeNode($constructorClassMethod);
|
||||
|
||||
return $methodCall;
|
||||
}
|
||||
|
@ -77,15 +77,15 @@ PHP
|
||||
return null;
|
||||
}
|
||||
|
||||
$arrayItem = $this->arrayManipulator->findItemInInArrayByKeyAndUnset($optionsArray, 'read_only');
|
||||
if ($arrayItem === null) {
|
||||
$readOnlyArrayItem = $this->arrayManipulator->findItemInInArrayByKeyAndUnset($optionsArray, 'read_only');
|
||||
if ($readOnlyArrayItem === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// rename string
|
||||
$arrayItem->key = new String_('readonly');
|
||||
$readOnlyArrayItem->key = new String_('readonly');
|
||||
|
||||
$this->arrayManipulator->addItemToArrayUnderKey($optionsArray, $arrayItem, 'attr');
|
||||
$this->arrayManipulator->addItemToArrayUnderKey($optionsArray, $readOnlyArrayItem, 'attr');
|
||||
|
||||
return $node;
|
||||
}
|
||||
|
@ -98,8 +98,8 @@ PHP
|
||||
*/
|
||||
public function refactor(Node $node): ?Node
|
||||
{
|
||||
$methodCall = $this->createMethodCall('client', 'getResponse');
|
||||
$this->getStatusCodeMethodCall = $this->createMethodCall($methodCall, 'getStatusCode');
|
||||
$clientGetResponseMethodCall = $this->createMethodCall('client', 'getResponse');
|
||||
$this->getStatusCodeMethodCall = $this->createMethodCall($clientGetResponseMethodCall, 'getStatusCode');
|
||||
|
||||
if (! $this->isInWebTestCase($node)) {
|
||||
return null;
|
||||
|
Loading…
Reference in New Issue
Block a user