Skip to content

Commit

Permalink
tidy
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasVotruba committed Sep 6, 2024
1 parent df7a8da commit 37bca44
Showing 1 changed file with 22 additions and 16 deletions.
38 changes: 22 additions & 16 deletions src/Command/PrivatizeConstantsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,21 +108,7 @@ private function processFileInfo(SplFileInfo $phpFileInfo, array $classConstantF
}

foreach ($findNonPrivateClassConstNodeVisitor->getClassConstants() as $classConstant) {
$isPublic = false;
foreach ($classConstantFetches as $classConstantFetch) {
if (! $classConstantFetch->isClassConstantMatch($classConstant)) {
continue;
}

if ($classConstantFetch instanceof CurrentClassConstantFetch) {
continue;
}

// used externally, make public
$isPublic = true;
}

if ($isPublic) {
if ($this->isClassConstantUsedPublicly($classConstantFetches, $classConstant)) {
$changedFileContents = Strings::replace(
$phpFileInfo->getContents(),
'#(public\s+)?const\s+' . $classConstant->getConstantName() . '#',
Expand All @@ -138,12 +124,32 @@ private function processFileInfo(SplFileInfo $phpFileInfo, array $classConstantF
// make private
$changedFileContents = Strings::replace(
$phpFileInfo->getContents(),
'#(public\s+)?const\s+' . $classConstant->getConstantName() . '#',
'#((public|protected)\s+)?const\s+' . $classConstant->getConstantName() . '#',
'private const ' . $classConstant->getConstantName()
);
FileSystem::write($phpFileInfo->getRealPath(), $changedFileContents);

$this->symfonyStyle->note(sprintf('Constant %s changed to private', $classConstant->getConstantName()));
}
}

private function isClassConstantUsedPublicly(

Check failure on line 136 in src/Command/PrivatizeConstantsCommand.php

View workflow job for this annotation

GitHub Actions / PHPStan

Method Rector\SwissKnife\Command\PrivatizeConstantsCommand::isClassConstantUsedPublicly() has parameter $classConstantFetches with no value type specified in iterable type array.
array $classConstantFetches,
\Rector\SwissKnife\ValueObject\ClassConstant $classConstant
): bool {
foreach ($classConstantFetches as $classConstantFetch) {
if (! $classConstantFetch->isClassConstantMatch($classConstant)) {
continue;
}

if ($classConstantFetch instanceof CurrentClassConstantFetch) {
continue;
}

// used externally, make public
return true;
}

return false;
}
}

0 comments on commit 37bca44

Please sign in to comment.