Skip to content

Commit 478ecfa

Browse files
authored
Reflection: test edgecase of getting all constants on parent (#137)
1 parent d9aa188 commit 478ecfa

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

tests/Rule/data/providers/reflection.php

+28
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,34 @@ public function test() // error: Unused Reflection\TransitiveHolder::test
6868
}
6969
}
7070

71+
72+
abstract class GetAllConstantsParent {
73+
public static function getConstants()
74+
{
75+
// this is not yet supported as we are unaware of children in collectors (and thus in ReflectionUsageProvider)
76+
// it might be solvable by making ClassConstantRef::$constantName nullable
77+
// - calling getConstants() should mark all constants as used (on all children as the generic class might be just phpdoc based, not string-literal based)
78+
return (new \ReflectionClass(static::class))->getConstants();
79+
}
80+
81+
/**
82+
* @param \ReflectionClass<self> $reflection
83+
*/
84+
public static function getConstants2(\ReflectionClass $reflection)
85+
{
86+
// same problem as above
87+
return $reflection->getConstants();
88+
}
89+
}
90+
91+
class GetAllConstantsChild extends GetAllConstantsParent {
92+
const CONSTANT = 1; // error: Unused Reflection\GetAllConstantsChild::CONSTANT
93+
}
94+
95+
GetAllConstantsChild::getConstants();
96+
GetAllConstantsChild::getConstants2();
97+
98+
7199
$reflection1 = new \ReflectionClass(Holder1::class);
72100
$reflection1->getConstants();
73101
$reflection1->getMethod('used');

0 commit comments

Comments
 (0)