Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace Rector\Tests\Privatization\Rector\Property\PrivatizeFinalClassPropertyRector\Fixture;

use Symfony\Component\Console\Command\Command;

final class SendWinnerEmailCommand extends Command
{
protected static $defaultDescription = 'Send winner email variant to remaining contacts';
}
22 changes: 22 additions & 0 deletions rules/Privatization/Guard/ParentPropertyLookupGuard.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@

final readonly class ParentPropertyLookupGuard
{
/**
* Symfony Console Command reserved static properties, read by the parent class via reflection
* even when not declared on the parent class itself
* @see https://github.com/symfony/console/blob/7.1/Command/Command.php
*
* @var string[]
*/
private const SYMFONY_COMMAND_RESERVED_PROPERTY_NAMES = ['defaultName', 'defaultDescription'];

public function __construct(
private BetterNodeFinder $betterNodeFinder,
private NodeNameResolver $nodeNameResolver,
Expand Down Expand Up @@ -49,6 +58,10 @@ public function isLegal(Property|string $property, ?ClassReflection $classReflec
return false;
}

if ($this->isSymfonyCommandReservedProperty($classReflection, $propertyName)) {
return false;
}

$parentClassName = $this->classReflectionAnalyzer->resolveParentClassName($classReflection);
if ($parentClassName === null) {
return true;
Expand All @@ -65,6 +78,15 @@ public function isLegal(Property|string $property, ?ClassReflection $classReflec
return $this->isGuardedByParents($parentClassReflections, $propertyName, $className);
}

private function isSymfonyCommandReservedProperty(ClassReflection $classReflection, string $propertyName): bool
{
if (! in_array($propertyName, self::SYMFONY_COMMAND_RESERVED_PROPERTY_NAMES, true)) {
return false;
}

return $classReflection->is('Symfony\Component\Console\Command\Command');
}

private function isFoundInParentClassMethods(
ClassReflection $parentClassReflection,
string $propertyName,
Expand Down
Loading