Skip to content

Commit

Permalink
[Core] Apply Scope Refresh on Enum_ (#2549)
Browse files Browse the repository at this point in the history
* [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>
  • Loading branch information
samsonasik and actions-user committed Jun 21, 2022
1 parent e8ca23f commit 0fb4f5b
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function test(): void
// 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function test(SmartFileInfo $smartFileInfo): void
$fileContent = $this->nodePrinter->print($nodesWithoutComments);
$fileContent = trim($fileContent);

$expectedContent = trim($fileInfoToLocalInputAndExpected->getExpected());
$expectedContent = trim((string) $fileInfoToLocalInputAndExpected->getExpected());

$this->assertSame($fileContent, $expectedContent, $smartFileInfo->getRelativeFilePathFromCwd());

Expand Down
4 changes: 2 additions & 2 deletions packages/Parallel/Command/WorkerCommandLineFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function create(
break;
}

$workerCommandArray[] = escapeshellarg($arg);
$workerCommandArray[] = escapeshellarg((string) $arg);
}

$workerCommandArray[] = $workerCommandName;
Expand Down Expand Up @@ -110,7 +110,7 @@ public function create(
*
* tested in macOS and Ubuntu (github action)
*/
$workerCommandArray[] = escapeshellarg($input->getOption(Option::CONFIG));
$workerCommandArray[] = escapeshellarg((string) $input->getOption(Option::CONFIG));
}

return implode(' ', $workerCommandArray);
Expand Down
Original file line number Diff line number Diff line change
@@ -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';
}

?>
8 changes: 2 additions & 6 deletions rules/Naming/Naming/PropertyNaming.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public function getExpectedNameFromMethodName(string $methodName): ?ExpectedName
return null;
}

$originalName = lcfirst($matches['root_name']);
$originalName = lcfirst((string) $matches['root_name']);

return new ExpectedName($originalName, $this->rectorNamingInflector->singularize($originalName));
}
Expand Down Expand Up @@ -123,11 +123,7 @@ public function fqnToVariableName(ThisType | ObjectType | string $objectType): s
}

$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');
Expand Down
2 changes: 2 additions & 0 deletions rules/Php81/NodeFactory/EnumFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public function createFromClass(Class_ $class): Enum_
{
$shortClassName = $this->nodeNameResolver->getShortName($class);
$enum = new Enum_($shortClassName);
$enum->namespacedName = $class->namespacedName;

$constants = $class->getConstants();

Expand All @@ -53,6 +54,7 @@ public function createFromSpatieClass(Class_ $class): Enum_
{
$shortClassName = $this->nodeNameResolver->getShortName($class);
$enum = new Enum_($shortClassName);
$enum->namespacedName = $class->namespacedName;

// constant to cases
$phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($class);
Expand Down
4 changes: 2 additions & 2 deletions src/Application/VersionResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public static function resolvePackageVersion(): string
);
}

$version = trim($commitHashExecOutput[0]);
$version = trim((string) $commitHashExecOutput[0]);
return trim($version, '"');
}

Expand All @@ -69,6 +69,6 @@ public static function resolverReleaseDateTime(): DateTime
);
}

return new DateTime(trim($output[0]));
return new DateTime(trim((string) $output[0]));
}
}
2 changes: 0 additions & 2 deletions src/NodeAnalyzer/ScopeAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
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;

Expand All @@ -23,7 +22,6 @@ final class ScopeAnalyzer
Namespace_::class,
FileWithoutNamespace::class,
Identifier::class,
Enum_::class,
Param::class,
Arg::class,
];
Expand Down

0 comments on commit 0fb4f5b

Please sign in to comment.