[Core] Apply Scope Refresh on Enum_ (#2549)

* [Core] Apply Scope Refresh on Enum_

* implemented 🎉

* more set namespacedName

* [ci-review] Rector Rectify

* [ci-review] Rector Rectify

* final touch: fixture for Enum_ no namespace

Co-authored-by: GitHub Action <action@github.com>
This commit is contained in:
Abdul Malik Ikhsan 2022-06-21 21:54:05 +07:00 committed by GitHub
parent e8ca23fd15
commit 0fb4f5bfbb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 30 additions and 14 deletions

View File

@ -61,7 +61,7 @@ final class TestModifyReprintTest extends AbstractTestCase
// this will extended tokens of first node
$doctrineAnnotationTagValueNode->changeValue('methods', new CurlyListNode(['"GET"', '"HEAD"']));
$expectedDocContent = trim($inputFileInfoAndExpected->getExpected());
$expectedDocContent = trim((string) $inputFileInfoAndExpected->getExpected());
$printedPhpDocInfo = $this->printPhpDocInfoToString($phpDocInfo);
$this->assertSame($expectedDocContent, $printedPhpDocInfo);

View File

@ -46,7 +46,7 @@ final class CommentRemoverTest extends AbstractTestCase
$fileContent = $this->nodePrinter->print($nodesWithoutComments);
$fileContent = trim($fileContent);
$expectedContent = trim($fileInfoToLocalInputAndExpected->getExpected());
$expectedContent = trim((string) $fileInfoToLocalInputAndExpected->getExpected());
$this->assertSame($fileContent, $expectedContent, $smartFileInfo->getRelativeFilePathFromCwd());

View File

@ -61,7 +61,7 @@ final class WorkerCommandLineFactory
break;
}
$workerCommandArray[] = escapeshellarg($arg);
$workerCommandArray[] = escapeshellarg((string) $arg);
}
$workerCommandArray[] = $workerCommandName;
@ -110,7 +110,7 @@ final class WorkerCommandLineFactory
*
* tested in macOS and Ubuntu (github action)
*/
$workerCommandArray[] = escapeshellarg($input->getOption(Option::CONFIG));
$workerCommandArray[] = escapeshellarg((string) $input->getOption(Option::CONFIG));
}
return implode(' ', $workerCommandArray);

View File

@ -0,0 +1,20 @@
<?php
class EnumNoNamespace
{
public const LEFT = 'left';
public const RIGHT = 'right';
}
?>
-----
<?php
enum EnumNoNamespace : string
{
case LEFT = 'left';
case RIGHT = 'right';
}
?>

View File

@ -64,7 +64,7 @@ final class PropertyNaming
return null;
}
$originalName = lcfirst($matches['root_name']);
$originalName = lcfirst((string) $matches['root_name']);
return new ExpectedName($originalName, $this->rectorNamingInflector->singularize($originalName));
}
@ -123,11 +123,7 @@ final class PropertyNaming
}
$className = $this->resolveClassName($objectType);
if (str_contains($className, '\\')) {
$shortClassName = (string) Strings::after($className, '\\', -1);
} else {
$shortClassName = $className;
}
$shortClassName = str_contains($className, '\\') ? (string) Strings::after($className, '\\', -1) : $className;
$variableName = $this->removeInterfaceSuffixPrefix($shortClassName, 'interface');
$variableName = $this->removeInterfaceSuffixPrefix($variableName, 'abstract');

View File

@ -31,6 +31,7 @@ final class EnumFactory
{
$shortClassName = $this->nodeNameResolver->getShortName($class);
$enum = new Enum_($shortClassName);
$enum->namespacedName = $class->namespacedName;
$constants = $class->getConstants();
@ -53,6 +54,7 @@ final class EnumFactory
{
$shortClassName = $this->nodeNameResolver->getShortName($class);
$enum = new Enum_($shortClassName);
$enum->namespacedName = $class->namespacedName;
// constant to cases
$phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($class);

View File

@ -56,7 +56,7 @@ final class VersionResolver
);
}
$version = trim($commitHashExecOutput[0]);
$version = trim((string) $commitHashExecOutput[0]);
return trim($version, '"');
}
@ -69,6 +69,6 @@ final class VersionResolver
);
}
return new DateTime(trim($output[0]));
return new DateTime(trim((string) $output[0]));
}
}

View File

@ -9,7 +9,6 @@ use PhpParser\Node\Arg;
use PhpParser\Node\Identifier;
use PhpParser\Node\Name;
use PhpParser\Node\Param;
use PhpParser\Node\Stmt\Enum_;
use PhpParser\Node\Stmt\Namespace_;
use Rector\Core\PhpParser\Node\CustomNode\FileWithoutNamespace;
@ -23,7 +22,6 @@ final class ScopeAnalyzer
Namespace_::class,
FileWithoutNamespace::class,
Identifier::class,
Enum_::class,
Param::class,
Arg::class,
];