Skip to content

Commit 8d4ea60

Browse files
committed
Update ClassReflection::getConstant() return type
1 parent b60d12c commit 8d4ea60

5 files changed

Lines changed: 5 additions & 26 deletions

File tree

src/Reflection/ClassReflection.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ class ClassReflection
7979
/** @var PropertyReflection[] */
8080
private array $properties = [];
8181

82-
/** @var ConstantReflection[] */
82+
/** @var ClassConstantReflection[] */
8383
private array $constants = [];
8484

8585
/** @var int[]|null */
@@ -1005,7 +1005,7 @@ public function hasConstant(string $name): bool
10051005
return $this->reflectionProvider->hasClass($reflectionConstant->getDeclaringClass()->getName());
10061006
}
10071007

1008-
public function getConstant(string $name): ConstantReflection
1008+
public function getConstant(string $name): ClassConstantReflection
10091009
{
10101010
if (!isset($this->constants[$name])) {
10111011
$reflectionConstant = $this->getNativeReflection()->getReflectionConstant($name);

src/Reflection/InitializerExprTypeResolver.php

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1906,28 +1906,21 @@ function (Type $type, callable $traverse): Type {
19061906

19071907
$constantReflection = $constantClassReflection->getConstant($constantName);
19081908
if (
1909-
$constantReflection instanceof ClassConstantReflection
1910-
&& !$constantClassReflection->isFinal()
1909+
!$constantClassReflection->isFinal()
19111910
&& !$constantReflection->hasPhpDocType()
19121911
&& !$constantReflection->hasNativeType()
19131912
) {
19141913
unset($this->currentlyResolvingClassConstant[$resolvingName]);
19151914
return new MixedType();
19161915
}
19171916

1918-
if (
1919-
!$constantReflection instanceof ClassConstantReflection
1920-
|| !$constantClassReflection->isFinal()
1921-
) {
1917+
if (!$constantClassReflection->isFinal()) {
19221918
$constantType = $constantReflection->getValueType();
19231919
} else {
19241920
$constantType = $this->getType($constantReflection->getValueExpr(), InitializerExprContext::fromClassReflection($constantReflection->getDeclaringClass()));
19251921
}
19261922

1927-
$nativeType = null;
1928-
if ($constantReflection instanceof ClassConstantReflection) {
1929-
$nativeType = $constantReflection->getNativeType();
1930-
}
1923+
$nativeType = $constantReflection->getNativeType();
19311924
$constantType = $this->constantResolver->resolveClassConstantType(
19321925
$constantClassReflection->getName(),
19331926
$constantName,

src/Rules/Constants/OverridingConstantRule.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,6 @@ private function processSingleConstant(ClassReflection $classReflection, string
5858
}
5959

6060
$constantReflection = $classReflection->getConstant($constantName);
61-
if (!$constantReflection instanceof ClassConstantReflection) {
62-
return [];
63-
}
64-
6561
$errors = [];
6662
if ($prototype->isFinal()) {
6763
$errors[] = RuleErrorBuilder::message(sprintf(

src/Rules/Constants/ValueAssignedToClassConstantRule.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
use PhpParser\Node;
66
use PHPStan\Analyser\Scope;
7-
use PHPStan\Reflection\ClassConstantReflection;
87
use PHPStan\Reflection\ClassReflection;
98
use PHPStan\Rules\Rule;
109
use PHPStan\Rules\RuleError;
@@ -58,10 +57,6 @@ public function processNode(Node $node, Scope $scope): array
5857
private function processSingleConstant(ClassReflection $classReflection, string $constantName, Type $valueExprType, ?Type $nativeType): array
5958
{
6059
$constantReflection = $classReflection->getConstant($constantName);
61-
if (!$constantReflection instanceof ClassConstantReflection) {
62-
return [];
63-
}
64-
6560
$phpDocType = $constantReflection->getPhpDocType();
6661
if ($phpDocType === null) {
6762
if ($nativeType === null) {

src/Rules/PhpDoc/IncompatibleClassConstantPhpDocTypeRule.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
use PhpParser\Node;
66
use PHPStan\Analyser\Scope;
77
use PHPStan\Internal\SprintfHelper;
8-
use PHPStan\Reflection\ClassConstantReflection;
98
use PHPStan\Reflection\ClassReflection;
109
use PHPStan\Rules\Generics\GenericObjectTypeCheck;
1110
use PHPStan\Rules\Rule;
@@ -62,10 +61,6 @@ public function processNode(Node $node, Scope $scope): array
6261
private function processSingleConstant(ClassReflection $classReflection, ?Type $nativeType, string $constantName): array
6362
{
6463
$constantReflection = $classReflection->getConstant($constantName);
65-
if (!$constantReflection instanceof ClassConstantReflection) {
66-
return [];
67-
}
68-
6964
$phpDocType = $constantReflection->getPhpDocType();
7065
if ($phpDocType === null) {
7166
return [];

0 commit comments

Comments
 (0)