@@ -4547,6 +4547,19 @@ public static function parseDocComments(array $comments): array {
4547
4547
4548
4548
return $ tags ;
4549
4549
}
4550
+
4551
+ /**
4552
+ * @param DocCommentTag[] $tags
4553
+ * @return array<string, ?string> Mapping tag names to the value (or null),
4554
+ * if a tag is present multiple times the last value is used
4555
+ */
4556
+ public static function makeTagMap (array $ tags ): array {
4557
+ $ map = [];
4558
+ foreach ($ tags as $ tag ) {
4559
+ $ map [$ tag ->name ] = $ tag ->value ;
4560
+ }
4561
+ return $ map ;
4562
+ }
4550
4563
}
4551
4564
4552
4565
// Instances of ExposedDocComment are immutable and do not need to be cloned
@@ -4629,6 +4642,13 @@ function parseFunctionLike(
4629
4642
4630
4643
if ($ comments ) {
4631
4644
$ tags = DocCommentTag::parseDocComments ($ comments );
4645
+ $ tagMap = DocCommentTag::makeTagMap ($ tags );
4646
+
4647
+ $ isDeprecated = array_key_exists ('deprecated ' , $ tagMap );
4648
+ $ verify = !array_key_exists ('no-verify ' , $ tagMap );
4649
+ $ tentativeReturnType = array_key_exists ('tentative-return-type ' , $ tagMap );
4650
+ $ supportsCompileTimeEval = array_key_exists ('compile-time-eval ' , $ tagMap );
4651
+ $ isUndocumentable = $ isUndocumentable || array_key_exists ('undocumentable ' , $ tagMap );
4632
4652
4633
4653
foreach ($ tags as $ tag ) {
4634
4654
switch ($ tag ->name ) {
@@ -4643,18 +4663,6 @@ function parseFunctionLike(
4643
4663
}
4644
4664
break ;
4645
4665
4646
- case 'deprecated ' :
4647
- $ isDeprecated = true ;
4648
- break ;
4649
-
4650
- case 'no-verify ' :
4651
- $ verify = false ;
4652
- break ;
4653
-
4654
- case 'tentative-return-type ' :
4655
- $ tentativeReturnType = true ;
4656
- break ;
4657
-
4658
4666
case 'return ' :
4659
4667
$ docReturnType = $ tag ->getType ();
4660
4668
break ;
@@ -4667,10 +4675,6 @@ function parseFunctionLike(
4667
4675
$ refcount = $ tag ->getValue ();
4668
4676
break ;
4669
4677
4670
- case 'compile-time-eval ' :
4671
- $ supportsCompileTimeEval = true ;
4672
- break ;
4673
-
4674
4678
case 'prefer-ref ' :
4675
4679
$ varName = $ tag ->getVariableName ();
4676
4680
if (!isset ($ paramMeta [$ varName ])) {
@@ -4679,10 +4683,6 @@ function parseFunctionLike(
4679
4683
$ paramMeta [$ varName ][$ tag ->name ] = true ;
4680
4684
break ;
4681
4685
4682
- case 'undocumentable ' :
4683
- $ isUndocumentable = true ;
4684
- break ;
4685
-
4686
4686
case 'frameless-function ' :
4687
4687
$ framelessFunctionInfos [] = new FramelessFunctionInfo ($ tag ->getValue ());
4688
4688
break ;
@@ -4812,26 +4812,19 @@ function parseConstLike(
4812
4812
array $ attributes
4813
4813
): ConstInfo {
4814
4814
$ phpDocType = null ;
4815
- $ deprecated = false ;
4816
- $ cValue = null ;
4817
- $ link = null ;
4818
- $ isFileCacheAllowed = true ;
4819
- if ($ comments ) {
4820
- $ tags = DocCommentTag::parseDocComments ($ comments );
4821
- foreach ($ tags as $ tag ) {
4822
- if ($ tag ->name === 'var ' ) {
4823
- $ phpDocType = $ tag ->getType ();
4824
- } elseif ($ tag ->name === 'deprecated ' ) {
4825
- $ deprecated = true ;
4826
- } elseif ($ tag ->name === 'cvalue ' ) {
4827
- $ cValue = $ tag ->value ;
4828
- } elseif ($ tag ->name === 'undocumentable ' ) {
4829
- $ isUndocumentable = true ;
4830
- } elseif ($ tag ->name === 'link ' ) {
4831
- $ link = $ tag ->value ;
4832
- } elseif ($ tag ->name === 'no-file-cache ' ) {
4833
- $ isFileCacheAllowed = false ;
4834
- }
4815
+
4816
+ $ tags = DocCommentTag::parseDocComments ($ comments );
4817
+ $ tagMap = DocCommentTag::makeTagMap ($ tags );
4818
+
4819
+ $ deprecated = array_key_exists ('deprecated ' , $ tagMap );
4820
+ $ isUndocumentable = $ isUndocumentable || array_key_exists ('undocumentable ' , $ tagMap );
4821
+ $ isFileCacheAllowed = !array_key_exists ('no-file-cache ' , $ tagMap );
4822
+ $ cValue = $ tagMap ['cvalue ' ] ?? null ;
4823
+ $ link = $ tagMap ['link ' ] ?? null ;
4824
+
4825
+ foreach ($ tags as $ tag ) {
4826
+ if ($ tag ->name === 'var ' ) {
4827
+ $ phpDocType = $ tag ->getType ();
4835
4828
}
4836
4829
}
4837
4830
@@ -4886,22 +4879,17 @@ function parseProperty(
4886
4879
array $ attributes
4887
4880
): PropertyInfo {
4888
4881
$ phpDocType = null ;
4889
- $ isDocReadonly = false ;
4890
- $ isVirtual = false ;
4891
- $ link = null ;
4892
4882
4893
- if ($ comments ) {
4894
- $ tags = DocCommentTag::parseDocComments ($ comments );
4895
- foreach ($ tags as $ tag ) {
4896
- if ($ tag ->name === 'var ' ) {
4897
- $ phpDocType = $ tag ->getType ();
4898
- } elseif ($ tag ->name === 'readonly ' ) {
4899
- $ isDocReadonly = true ;
4900
- } elseif ($ tag ->name === 'link ' ) {
4901
- $ link = $ tag ->value ;
4902
- } elseif ($ tag ->name === 'virtual ' ) {
4903
- $ isVirtual = true ;
4904
- }
4883
+ $ tags = DocCommentTag::parseDocComments ($ comments );
4884
+ $ tagMap = DocCommentTag::makeTagMap ($ tags );
4885
+
4886
+ $ isDocReadonly = array_key_exists ('readonly ' , $ tagMap );
4887
+ $ link = $ tagMap ['link ' ] ?? null ;
4888
+ $ isVirtual = array_key_exists ('virtual ' , $ tagMap );
4889
+
4890
+ foreach ($ tags as $ tag ) {
4891
+ if ($ tag ->name === 'var ' ) {
4892
+ $ phpDocType = $ tag ->getType ();
4905
4893
}
4906
4894
}
4907
4895
@@ -4956,25 +4944,18 @@ function parseClass(
4956
4944
): ClassInfo {
4957
4945
$ comments = $ class ->getComments ();
4958
4946
$ alias = null ;
4959
- $ isDeprecated = false ;
4960
- $ isStrictProperties = false ;
4961
- $ isNotSerializable = false ;
4962
4947
$ allowsDynamicProperties = false ;
4963
4948
4964
- if ($ comments ) {
4965
- $ tags = DocCommentTag::parseDocComments ($ comments );
4966
- foreach ($ tags as $ tag ) {
4967
- if ($ tag ->name === 'alias ' ) {
4968
- $ alias = $ tag ->getValue ();
4969
- } else if ($ tag ->name === 'deprecated ' ) {
4970
- $ isDeprecated = true ;
4971
- } else if ($ tag ->name === 'strict-properties ' ) {
4972
- $ isStrictProperties = true ;
4973
- } else if ($ tag ->name === 'not-serializable ' ) {
4974
- $ isNotSerializable = true ;
4975
- } else if ($ tag ->name === 'undocumentable ' ) {
4976
- $ isUndocumentable = true ;
4977
- }
4949
+ $ tags = DocCommentTag::parseDocComments ($ comments );
4950
+ $ tagMap = DocCommentTag::makeTagMap ($ tags );
4951
+
4952
+ $ isDeprecated = array_key_exists ('deprecated ' , $ tagMap );
4953
+ $ isStrictProperties = array_key_exists ('strict-properties ' , $ tagMap );
4954
+ $ isNotSerializable = array_key_exists ('not-serializable ' , $ tagMap );
4955
+ $ isUndocumentable = $ isUndocumentable || array_key_exists ('undocumentable ' , $ tagMap );
4956
+ foreach ($ tags as $ tag ) {
4957
+ if ($ tag ->name === 'alias ' ) {
4958
+ $ alias = $ tag ->getValue ();
4978
4959
}
4979
4960
}
4980
4961
0 commit comments