2424use PhpParser \PrettyPrinter \Standard ;
2525use RecursiveIterator ;
2626use Roave \BetterReflection \Reflection \Annotation \AnnotationHelper ;
27+ use Roave \BetterReflection \Reflection \Exception \InvalidConstantNode ;
2728use Roave \BetterReflection \SourceLocator \FileChecker ;
2829use Roave \BetterReflection \SourceLocator \SourceStubber \Exception \CouldNotFindPhpStormStubs ;
2930use Roave \BetterReflection \SourceLocator \SourceStubber \PhpStormStubs \CachingVisitor ;
31+ use Roave \BetterReflection \Util \ConstantNodeChecker ;
3032use SimpleXMLElement ;
3133use SplFixedArray ;
3234use Traversable ;
@@ -396,6 +398,15 @@ private function parseFile(string $filePath): void
396398
397399 private function createStub (Node \Stmt \ClassLike |Node \Stmt \Function_ |Node \Stmt \Const_ |Node \Expr \FuncCall $ node , Node \Stmt \Namespace_ |null $ namespaceNode ): string
398400 {
401+ if ($ node instanceof Node \Expr \FuncCall) {
402+ try {
403+ ConstantNodeChecker::assertValidDefineFunctionCall ($ node );
404+ $ this ->addDeprecatedDocComment ($ node );
405+ } catch (InvalidConstantNode ) {
406+ // just keep going
407+ }
408+ }
409+
399410 if (! ($ node instanceof Node \Expr \FuncCall)) {
400411 $ this ->addDeprecatedDocComment ($ node );
401412
@@ -612,16 +623,20 @@ private function getStmtType(Node\Stmt\Function_|Node\Stmt\ClassMethod|Node\Stmt
612623 : null ;
613624 }
614625
615- private function addDeprecatedDocComment (Node \Stmt \ClassLike |Node \Stmt \ClassConst |Node \Stmt \Property |Node \Stmt \ClassMethod |Node \Stmt \Function_ |Node \Stmt \Const_ $ node ): void
626+ private function addDeprecatedDocComment (Node \Stmt \ClassLike |Node \Stmt \ClassConst |Node \Stmt \Property |Node \Stmt \ClassMethod |Node \Stmt \Function_ |Node \Expr \ FuncCall | Node \ Stmt \Const_ $ node ): void
616627 {
617- if ($ node instanceof Node \Stmt \Const_ ) {
628+ if ($ node instanceof Node \Expr \FuncCall ) {
618629 if (! $ this ->isDeprecatedByPhpDocInPhpVersion ($ node )) {
619630 $ this ->removeAnnotationFromDocComment ($ node , 'deprecated ' );
620631 }
621632
622633 return ;
623634 }
624635
636+ if ($ node instanceof Node \Stmt \Const_) {
637+ return ;
638+ }
639+
625640 if (! $ this ->isDeprecatedInPhpVersion ($ node )) {
626641 $ this ->removeAnnotationFromDocComment ($ node , 'deprecated ' );
627642
@@ -647,7 +662,7 @@ private function addAnnotationToDocComment(
647662 }
648663
649664 private function removeAnnotationFromDocComment (
650- Node \Stmt \ClassLike |Node \Stmt \ClassConst |Node \Stmt \Property |Node \Stmt \ClassMethod |Node \Stmt \Function_ |Node \Stmt \Const_ $ node ,
665+ Node \Stmt \ClassLike |Node \Stmt \ClassConst |Node \Stmt \Property |Node \Stmt \ClassMethod |Node \Stmt \Function_ |Node \Expr \ FuncCall | Node \ Stmt \Const_ $ node ,
651666 string $ annotationName ,
652667 ): void {
653668 $ docComment = $ node ->getDocComment ();
@@ -664,14 +679,14 @@ private function isCoreExtension(string $extension): bool
664679 return in_array ($ extension , self ::CORE_EXTENSIONS , true );
665680 }
666681
667- private function isDeprecatedByPhpDocInPhpVersion (Node \Stmt \ Const_ $ node ): bool
682+ private function isDeprecatedByPhpDocInPhpVersion (Node \Expr \ FuncCall $ node ): bool
668683 {
669684 $ docComment = $ node ->getDocComment ();
670685 if ($ docComment === null ) {
671686 return false ;
672687 }
673688
674- if (preg_match ('#@deprecated\s+(\d+)\.(\d+)(?:\.(\d+)?) $#m ' , $ docComment ->getText (), $ matches ) === 1 ) {
689+ if (preg_match ('#@deprecated\s+(\d+)\.(\d+)(?:\.(\d+))? $#m ' , $ docComment ->getText (), $ matches ) === 1 ) {
675690 $ major = $ matches [1 ];
676691 $ minor = $ matches [2 ];
677692 $ patch = $ matches [3 ] ?? 0 ;
0 commit comments