3636use PHPStan \Reflection \ClassReflection ;
3737use PHPStan \Reflection \Constant \RuntimeConstantReflection ;
3838use PHPStan \Reflection \ConstantReflection ;
39+ use PHPStan \Reflection \Deprecation \DeprecationResolver ;
3940use PHPStan \Reflection \FunctionReflection ;
4041use PHPStan \Reflection \FunctionReflectionFactory ;
4142use PHPStan \Reflection \InitializerExprContext ;
@@ -85,6 +86,7 @@ public function __construct(
8586 private Reflector $ reflector ,
8687 private FileTypeMapper $ fileTypeMapper ,
8788 private PhpDocInheritanceResolver $ phpDocInheritanceResolver ,
89+ private DeprecationResolver $ deprecationResolver ,
8890 private PhpVersion $ phpVersion ,
8991 private NativeFunctionReflectionProvider $ nativeFunctionReflectionProvider ,
9092 private StubPhpDocProvider $ stubPhpDocProvider ,
@@ -148,6 +150,7 @@ public function getClass(string $className): ClassReflection
148150 $ this ->phpDocInheritanceResolver ,
149151 $ this ->phpVersion ,
150152 $ this ->signatureMapProvider ,
153+ $ this ->deprecationResolver ,
151154 $ this ->attributeReflectionFactory ,
152155 $ this ->classReflectionExtensionRegistryProvider ->getRegistry ()->getPropertiesClassReflectionExtensions (),
153156 $ this ->classReflectionExtensionRegistryProvider ->getRegistry ()->getMethodsClassReflectionExtensions (),
@@ -243,6 +246,7 @@ public function getAnonymousClassReflection(Node\Stmt\Class_ $classNode, Scope $
243246 $ this ->phpDocInheritanceResolver ,
244247 $ this ->phpVersion ,
245248 $ this ->signatureMapProvider ,
249+ $ this ->deprecationResolver ,
246250 $ this ->attributeReflectionFactory ,
247251 $ this ->classReflectionExtensionRegistryProvider ->getRegistry ()->getPropertiesClassReflectionExtensions (),
248252 $ this ->classReflectionExtensionRegistryProvider ->getRegistry ()->getMethodsClassReflectionExtensions (),
@@ -305,8 +309,11 @@ private function getCustomFunction(string $functionName): PhpFunctionReflection
305309 $ phpDocParameterTypes = [];
306310 $ phpDocReturnTag = null ;
307311 $ phpDocThrowsTag = null ;
308- $ deprecatedTag = null ;
309- $ isDeprecated = false ;
312+
313+ $ deprecation = $ this ->deprecationResolver ->getFunctionDeprecation ($ reflectionFunction );
314+ $ deprecationDescription = $ deprecation ?->getDescription();
315+ $ isDeprecated = $ deprecation !== null ;
316+
310317 $ isInternal = false ;
311318 $ isPure = null ;
312319 $ asserts = Assertions::createEmpty ();
@@ -327,8 +334,10 @@ private function getCustomFunction(string $functionName): PhpFunctionReflection
327334 $ phpDocParameterTypes = array_map (static fn ($ tag ) => $ tag ->getType (), $ resolvedPhpDoc ->getParamTags ());
328335 $ phpDocReturnTag = $ resolvedPhpDoc ->getReturnTag ();
329336 $ phpDocThrowsTag = $ resolvedPhpDoc ->getThrowsTag ();
330- $ deprecatedTag = $ resolvedPhpDoc ->getDeprecatedTag ();
331- $ isDeprecated = $ resolvedPhpDoc ->isDeprecated ();
337+ if (!$ isDeprecated ) {
338+ $ deprecationDescription = $ resolvedPhpDoc ->getDeprecatedTag () !== null ? $ resolvedPhpDoc ->getDeprecatedTag ()->getMessage () : $ deprecationDescription ;
339+ $ isDeprecated = $ resolvedPhpDoc ->isDeprecated ();
340+ }
332341 $ isInternal = $ resolvedPhpDoc ->isInternal ();
333342 $ isPure = $ resolvedPhpDoc ->isPure ();
334343 $ asserts = Assertions::createFromResolvedPhpDocBlock ($ resolvedPhpDoc );
@@ -347,7 +356,7 @@ private function getCustomFunction(string $functionName): PhpFunctionReflection
347356 $ phpDocParameterTypes ,
348357 $ phpDocReturnTag !== null ? $ phpDocReturnTag ->getType () : null ,
349358 $ phpDocThrowsTag !== null ? $ phpDocThrowsTag ->getType () : null ,
350- $ deprecatedTag !== null ? $ deprecatedTag -> getMessage () : null ,
359+ $ deprecationDescription ,
351360 $ isDeprecated ,
352361 $ isInternal ,
353362 $ reflectionFunction ->getFileName () !== false ? $ reflectionFunction ->getFileName () : null ,
@@ -407,13 +416,15 @@ public function getConstant(Node\Name $nameNode, ?NamespaceAnswerer $namespaceAn
407416 $ constantValueType = $ this ->initializerExprTypeResolver ->getType ($ constantReflection ->getValueExpression (), InitializerExprContext::fromGlobalConstant ($ constantReflection ));
408417 $ docComment = $ constantReflection ->getDocComment ();
409418
410- $ isDeprecated = TrinaryLogic::createNo ();
411- $ deprecatedDescription = null ;
412- if ($ docComment !== null ) {
419+ $ deprecation = $ this ->deprecationResolver ->getConstantDeprecation ($ constantReflection );
420+ $ isDeprecated = $ deprecation !== null ;
421+ $ deprecatedDescription = $ deprecation ?->getDescription();
422+
423+ if ($ isDeprecated === false && $ docComment !== null ) {
413424 $ resolvedPhpDoc = $ this ->fileTypeMapper ->getResolvedPhpDoc ($ fileName , null , null , null , $ docComment );
414- $ isDeprecated = TrinaryLogic:: createFromBoolean ( $ resolvedPhpDoc ->isDeprecated () );
425+ $ isDeprecated = $ resolvedPhpDoc ->isDeprecated ();
415426
416- if ($ resolvedPhpDoc -> isDeprecated () && $ resolvedPhpDoc ->getDeprecatedTag () !== null ) {
427+ if ($ isDeprecated && $ resolvedPhpDoc ->getDeprecatedTag () !== null ) {
417428 $ deprecatedMessage = $ resolvedPhpDoc ->getDeprecatedTag ()->getMessage ();
418429
419430 $ matches = Strings::match ($ deprecatedMessage ?? '' , '#^(\d+)\.(\d+)(?:\.(\d+))?$# ' );
@@ -423,7 +434,7 @@ public function getConstant(Node\Name $nameNode, ?NamespaceAnswerer $namespaceAn
423434 $ patch = $ matches [3 ] ?? 0 ;
424435 $ versionId = sprintf ('%d%02d%02d ' , $ major , $ minor , $ patch );
425436
426- $ isDeprecated = TrinaryLogic:: createFromBoolean ( $ this ->phpVersion ->getVersionId () >= $ versionId) ;
437+ $ isDeprecated = $ this ->phpVersion ->getVersionId () >= $ versionId ;
427438 } else {
428439 // filter raw version number messages like in
429440 // https://github.com/JetBrains/phpstorm-stubs/blob/9608c953230b08f07b703ecfe459cc58d5421437/filter/filter.php#L478
@@ -436,7 +447,7 @@ public function getConstant(Node\Name $nameNode, ?NamespaceAnswerer $namespaceAn
436447 $ constantName ,
437448 $ constantValueType ,
438449 $ fileName ,
439- $ isDeprecated ,
450+ TrinaryLogic:: createFromBoolean ( $ isDeprecated) ,
440451 $ deprecatedDescription ,
441452 );
442453 }
0 commit comments