2626use PHPStan \PhpDoc \Tag \TemplateTag ;
2727use PHPStan \PhpDoc \Tag \TypeAliasImportTag ;
2828use PHPStan \PhpDoc \Tag \TypeAliasTag ;
29+ use PHPStan \Reflection \Deprecation \DeprecationProvider ;
2930use PHPStan \Reflection \Php \PhpClassReflectionExtension ;
3031use PHPStan \Reflection \Php \PhpPropertyReflection ;
3132use PHPStan \Reflection \Php \UniversalObjectCratesClassReflectionExtension ;
@@ -161,6 +162,7 @@ public function __construct(
161162 private PhpDocInheritanceResolver $ phpDocInheritanceResolver ,
162163 private PhpVersion $ phpVersion ,
163164 private SignatureMapProvider $ signatureMapProvider ,
165+ private DeprecationProvider $ deprecationProvider ,
164166 private AttributeReflectionFactory $ attributeReflectionFactory ,
165167 private array $ propertiesClassReflectionExtensions ,
166168 private array $ methodsClassReflectionExtensions ,
@@ -793,7 +795,8 @@ public function getEnumCases(): array
793795 $ valueType = $ this ->initializerExprTypeResolver ->getType ($ case ->getValueExpression (), $ initializerExprContext );
794796 }
795797 $ caseName = $ case ->getName ();
796- $ cases [$ caseName ] = new EnumCaseReflection ($ this , $ case , $ valueType , $ this ->attributeReflectionFactory ->fromNativeReflection ($ case ->getAttributes (), InitializerExprContext::fromClass ($ this ->getName (), $ this ->getFileName ())));
798+ $ attributes = $ this ->attributeReflectionFactory ->fromNativeReflection ($ case ->getAttributes (), InitializerExprContext::fromClass ($ this ->getName (), $ this ->getFileName ()));
799+ $ cases [$ caseName ] = new EnumCaseReflection ($ this , $ case , $ valueType , $ attributes , $ this ->deprecationProvider );
797800 }
798801
799802 return $ this ->enumCases = $ cases ;
@@ -819,7 +822,9 @@ public function getEnumCase(string $name): EnumCaseReflection
819822 $ valueType = $ this ->initializerExprTypeResolver ->getType ($ case ->getValueExpression (), InitializerExprContext::fromClassReflection ($ this ));
820823 }
821824
822- return new EnumCaseReflection ($ this , $ case , $ valueType , $ this ->attributeReflectionFactory ->fromNativeReflection ($ case ->getAttributes (), InitializerExprContext::fromClass ($ this ->getName (), $ this ->getFileName ())));
825+ $ attributes = $ this ->attributeReflectionFactory ->fromNativeReflection ($ case ->getAttributes (), InitializerExprContext::fromClass ($ this ->getName (), $ this ->getFileName ()));
826+
827+ return new EnumCaseReflection ($ this , $ case , $ valueType , $ attributes , $ this ->deprecationProvider );
823828 }
824829
825830 public function isClass (): bool
@@ -1079,6 +1084,10 @@ public function getConstant(string $name): ClassConstantReflection
10791084 throw new MissingConstantFromReflectionException ($ this ->getName (), $ name );
10801085 }
10811086
1087+ $ deprecation = $ this ->deprecationProvider ->getClassConstantDeprecation ($ reflectionConstant );
1088+ $ deprecatedDescription = $ deprecation === null ? null : $ deprecation ->getDescription ();
1089+ $ isDeprecated = $ deprecation !== null ;
1090+
10821091 $ declaringClass = $ this ->reflectionProvider ->getClass ($ reflectionConstant ->getDeclaringClass ()->getName ());
10831092 $ fileName = $ declaringClass ->getFileName ();
10841093 $ phpDocType = null ;
@@ -1099,8 +1108,10 @@ public function getConstant(string $name): ClassConstantReflection
10991108 );
11001109 }
11011110
1102- $ deprecatedDescription = $ resolvedPhpDoc ->getDeprecatedTag () !== null ? $ resolvedPhpDoc ->getDeprecatedTag ()->getMessage () : null ;
1103- $ isDeprecated = $ resolvedPhpDoc ->isDeprecated ();
1111+ if (!$ isDeprecated ) {
1112+ $ deprecatedDescription = $ resolvedPhpDoc ->getDeprecatedTag () !== null ? $ resolvedPhpDoc ->getDeprecatedTag ()->getMessage () : null ;
1113+ $ isDeprecated = $ resolvedPhpDoc ->isDeprecated ();
1114+ }
11041115 $ isInternal = $ resolvedPhpDoc ->isInternal ();
11051116 $ isFinal = $ resolvedPhpDoc ->isFinal ();
11061117 $ varTags = $ resolvedPhpDoc ->getVarTags ();
@@ -1210,11 +1221,8 @@ public function getTypeAliases(): array
12101221
12111222 public function getDeprecatedDescription (): ?string
12121223 {
1213- if ($ this ->deprecatedDescription === null && $ this ->isDeprecated ()) {
1214- $ resolvedPhpDoc = $ this ->getResolvedPhpDoc ();
1215- if ($ resolvedPhpDoc !== null && $ resolvedPhpDoc ->getDeprecatedTag () !== null ) {
1216- $ this ->deprecatedDescription = $ resolvedPhpDoc ->getDeprecatedTag ()->getMessage ();
1217- }
1224+ if ($ this ->isDeprecated === null ) {
1225+ $ this ->resolveDeprecation ();
12181226 }
12191227
12201228 return $ this ->deprecatedDescription ;
@@ -1223,13 +1231,36 @@ public function getDeprecatedDescription(): ?string
12231231 public function isDeprecated (): bool
12241232 {
12251233 if ($ this ->isDeprecated === null ) {
1226- $ resolvedPhpDoc = $ this ->getResolvedPhpDoc ();
1227- $ this ->isDeprecated = $ resolvedPhpDoc !== null && $ resolvedPhpDoc ->isDeprecated ();
1234+ $ this ->resolveDeprecation ();
12281235 }
12291236
12301237 return $ this ->isDeprecated ;
12311238 }
12321239
1240+ /**
1241+ * @phpstan-assert bool $this->isDeprecated
1242+ */
1243+ private function resolveDeprecation (): void
1244+ {
1245+ $ deprecation = $ this ->deprecationProvider ->getClassDeprecation ($ this ->reflection );
1246+ if ($ deprecation !== null ) {
1247+ $ this ->isDeprecated = true ;
1248+ $ this ->deprecatedDescription = $ deprecation ->getDescription ();
1249+ return ;
1250+ }
1251+
1252+ $ resolvedPhpDoc = $ this ->getResolvedPhpDoc ();
1253+
1254+ if ($ resolvedPhpDoc !== null && $ resolvedPhpDoc ->isDeprecated ()) {
1255+ $ this ->isDeprecated = true ;
1256+ $ this ->deprecatedDescription = $ resolvedPhpDoc ->getDeprecatedTag () !== null ? $ resolvedPhpDoc ->getDeprecatedTag ()->getMessage () : null ;
1257+ return ;
1258+ }
1259+
1260+ $ this ->isDeprecated = false ;
1261+ $ this ->deprecatedDescription = null ;
1262+ }
1263+
12331264 public function isBuiltin (): bool
12341265 {
12351266 return $ this ->reflection ->isInternal ();
@@ -1559,6 +1590,7 @@ public function withTypes(array $types): self
15591590 $ this ->phpDocInheritanceResolver ,
15601591 $ this ->phpVersion ,
15611592 $ this ->signatureMapProvider ,
1593+ $ this ->deprecationProvider ,
15621594 $ this ->attributeReflectionFactory ,
15631595 $ this ->propertiesClassReflectionExtensions ,
15641596 $ this ->methodsClassReflectionExtensions ,
@@ -1590,6 +1622,7 @@ public function withVariances(array $variances): self
15901622 $ this ->phpDocInheritanceResolver ,
15911623 $ this ->phpVersion ,
15921624 $ this ->signatureMapProvider ,
1625+ $ this ->deprecationProvider ,
15931626 $ this ->attributeReflectionFactory ,
15941627 $ this ->propertiesClassReflectionExtensions ,
15951628 $ this ->methodsClassReflectionExtensions ,
@@ -1631,6 +1664,7 @@ public function asFinal(): self
16311664 $ this ->phpDocInheritanceResolver ,
16321665 $ this ->phpVersion ,
16331666 $ this ->signatureMapProvider ,
1667+ $ this ->deprecationProvider ,
16341668 $ this ->attributeReflectionFactory ,
16351669 $ this ->propertiesClassReflectionExtensions ,
16361670 $ this ->methodsClassReflectionExtensions ,
0 commit comments