24
24
use PhpParser \PrettyPrinter \Standard ;
25
25
use RecursiveIterator ;
26
26
use Roave \BetterReflection \Reflection \Annotation \AnnotationHelper ;
27
+ use Roave \BetterReflection \Reflection \Exception \InvalidConstantNode ;
27
28
use Roave \BetterReflection \SourceLocator \FileChecker ;
28
29
use Roave \BetterReflection \SourceLocator \SourceStubber \Exception \CouldNotFindPhpStormStubs ;
29
30
use Roave \BetterReflection \SourceLocator \SourceStubber \PhpStormStubs \CachingVisitor ;
31
+ use Roave \BetterReflection \Util \ConstantNodeChecker ;
30
32
use SimpleXMLElement ;
31
33
use SplFixedArray ;
32
34
use Traversable ;
@@ -396,6 +398,15 @@ private function parseFile(string $filePath): void
396
398
397
399
private function createStub (Node \Stmt \ClassLike |Node \Stmt \Function_ |Node \Stmt \Const_ |Node \Expr \FuncCall $ node , Node \Stmt \Namespace_ |null $ namespaceNode ): string
398
400
{
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
+
399
410
if (! ($ node instanceof Node \Expr \FuncCall)) {
400
411
$ this ->addDeprecatedDocComment ($ node );
401
412
@@ -612,16 +623,20 @@ private function getStmtType(Node\Stmt\Function_|Node\Stmt\ClassMethod|Node\Stmt
612
623
: null ;
613
624
}
614
625
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
616
627
{
617
- if ($ node instanceof Node \Stmt \Const_ ) {
628
+ if ($ node instanceof Node \Expr \FuncCall ) {
618
629
if (! $ this ->isDeprecatedByPhpDocInPhpVersion ($ node )) {
619
630
$ this ->removeAnnotationFromDocComment ($ node , 'deprecated ' );
620
631
}
621
632
622
633
return ;
623
634
}
624
635
636
+ if ($ node instanceof Node \Stmt \Const_) {
637
+ return ;
638
+ }
639
+
625
640
if (! $ this ->isDeprecatedInPhpVersion ($ node )) {
626
641
$ this ->removeAnnotationFromDocComment ($ node , 'deprecated ' );
627
642
@@ -647,7 +662,7 @@ private function addAnnotationToDocComment(
647
662
}
648
663
649
664
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 ,
651
666
string $ annotationName ,
652
667
): void {
653
668
$ docComment = $ node ->getDocComment ();
@@ -664,14 +679,14 @@ private function isCoreExtension(string $extension): bool
664
679
return in_array ($ extension , self ::CORE_EXTENSIONS , true );
665
680
}
666
681
667
- private function isDeprecatedByPhpDocInPhpVersion (Node \Stmt \ Const_ $ node ): bool
682
+ private function isDeprecatedByPhpDocInPhpVersion (Node \Expr \ FuncCall $ node ): bool
668
683
{
669
684
$ docComment = $ node ->getDocComment ();
670
685
if ($ docComment === null ) {
671
686
return false ;
672
687
}
673
688
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 ) {
675
690
$ major = $ matches [1 ];
676
691
$ minor = $ matches [2 ];
677
692
$ patch = $ matches [3 ] ?? 0 ;
0 commit comments