2121
2222final readonly class ParentPropertyLookupGuard
2323{
24+ /**
25+ * Symfony Console Command reserved static properties, read by the parent class via reflection
26+ * even when not declared on the parent class itself
27+ * @see https://github.com/symfony/console/blob/7.1/Command/Command.php
28+ *
29+ * @var string[]
30+ */
31+ private const SYMFONY_COMMAND_RESERVED_PROPERTY_NAMES = ['defaultName ' , 'defaultDescription ' ];
32+
2433 public function __construct (
2534 private BetterNodeFinder $ betterNodeFinder ,
2635 private NodeNameResolver $ nodeNameResolver ,
@@ -49,6 +58,10 @@ public function isLegal(Property|string $property, ?ClassReflection $classReflec
4958 return false ;
5059 }
5160
61+ if ($ this ->isSymfonyCommandReservedProperty ($ classReflection , $ propertyName )) {
62+ return false ;
63+ }
64+
5265 $ parentClassName = $ this ->classReflectionAnalyzer ->resolveParentClassName ($ classReflection );
5366 if ($ parentClassName === null ) {
5467 return true ;
@@ -65,6 +78,15 @@ public function isLegal(Property|string $property, ?ClassReflection $classReflec
6578 return $ this ->isGuardedByParents ($ parentClassReflections , $ propertyName , $ className );
6679 }
6780
81+ private function isSymfonyCommandReservedProperty (ClassReflection $ classReflection , string $ propertyName ): bool
82+ {
83+ if (! in_array ($ propertyName , self ::SYMFONY_COMMAND_RESERVED_PROPERTY_NAMES , true )) {
84+ return false ;
85+ }
86+
87+ return $ classReflection ->is ('Symfony\Component\Console\Command\Command ' );
88+ }
89+
6890 private function isFoundInParentClassMethods (
6991 ClassReflection $ parentClassReflection ,
7092 string $ propertyName ,
0 commit comments