Skip to content

Commit

Permalink
cs
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasVotruba committed May 31, 2024
1 parent 3473f2e commit 38e3315
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/Command/PrettyJsonCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$printedFilePaths[] = $jsonFileInfo->getRelativePathname();

// nothing will be changed
if ($isDryRun === true) {
if ($isDryRun) {
continue;
}

Expand Down
12 changes: 6 additions & 6 deletions src/Command/PrivatizeConstantsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -216,22 +216,22 @@ private function replaceClassAndChildWithProtected(array $phpFileInfos, array $s
continue;
}

foreach ($staticClassConstsMatches as $staticClassConstsMatch) {
foreach ($staticClassConstsMatches as $staticClassConstMatch) {
// update current and all hcildren
if (! is_a($fullyQualifiedClassName, $staticClassConstsMatch->getClassName(), true)) {
if (! is_a($fullyQualifiedClassName, $staticClassConstMatch->getClassName(), true)) {
continue;
}

$classFileContents = \str_replace(
'private const ' . $staticClassConstsMatch->getConstantName(),
'protected const ' . $staticClassConstsMatch->getConstantName(),
'private const ' . $staticClassConstMatch->getConstantName(),
'protected const ' . $staticClassConstMatch->getConstantName(),
$phpFileInfo->getContents()
);

$this->symfonyStyle->warning(sprintf(
'The "%s" constant in "%s" made protected to allow static access. Consider refactoring to better design',
$staticClassConstsMatch->getConstantName(),
$staticClassConstsMatch->getClassName(),
$staticClassConstMatch->getConstantName(),
$staticClassConstMatch->getClassName(),
));

FileSystem::write($phpFileInfo->getRealPath(), $classFileContents);
Expand Down
6 changes: 1 addition & 5 deletions src/FileSystem/JsonAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ final class JsonAnalyzer
public function isPrettyPrinted(string $json): bool
{
$lines = explode(PHP_EOL, $json);
if (count($lines) >= 3) {
return true;
}

return false;
return count($lines) >= 3;
}
}
13 changes: 7 additions & 6 deletions src/ValueObject/ClassConstMatch.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
namespace Rector\SwissKnife\ValueObject;

use ReflectionClass;
use Stringable;

final readonly class ClassConstMatch implements \Stringable
final readonly class ClassConstMatch implements Stringable
{
/**
* @param class-string $className
Expand Down Expand Up @@ -41,17 +42,17 @@ public function getConstantName(): string
*/
public function getClassFileName(): string
{
$classReflection = new ReflectionClass($this->className);
return (string) $classReflection->getFileName();
$reflectionClass = new ReflectionClass($this->className);
return (string) $reflectionClass->getFileName();
}

public function getParentClassConstMatch(): ?self
{
$classReflection = new ReflectionClass($this->className);
if ($classReflection->getParentClass() === false) {
$reflectionClass = new ReflectionClass($this->className);
if ($reflectionClass->getParentClass() === false) {
return null;
}

return new self($classReflection->getParentClass()->getName(), $this->constantName);
return new self($reflectionClass->getParentClass()->getName(), $this->constantName);
}
}
2 changes: 1 addition & 1 deletion src/ValueObject/PublicAndProtectedClassConstants.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Rector\SwissKnife\ValueObject;

final class PublicAndProtectedClassConstants
final readonly class PublicAndProtectedClassConstants
{
/**
* @param ClassConstMatch[] $publicClassConstMatch
Expand Down

0 comments on commit 38e3315

Please sign in to comment.