@@ -4298,6 +4298,150 @@ public function getMinimumPhpVersionIdCompatibility(): ?int {
4298
4298
public function shouldGenerateLegacyArginfo (): bool {
4299
4299
return $ this ->minimumPhpVersionIdCompatibility !== null && $ this ->minimumPhpVersionIdCompatibility < PHP_80_VERSION_ID ;
4300
4300
}
4301
+
4302
+ public function handleStatements (array $ stmts , PrettyPrinterAbstract $ prettyPrinter ): void {
4303
+ $ conds = [];
4304
+ foreach ($ stmts as $ stmt ) {
4305
+ $ cond = handlePreprocessorConditions ($ conds , $ stmt );
4306
+
4307
+ if ($ stmt instanceof Stmt \Nop) {
4308
+ continue ;
4309
+ }
4310
+
4311
+ if ($ stmt instanceof Stmt \Namespace_) {
4312
+ $ this ->handleStatements ($ stmt ->stmts , $ prettyPrinter );
4313
+ continue ;
4314
+ }
4315
+
4316
+ if ($ stmt instanceof Stmt \Const_) {
4317
+ foreach ($ stmt ->consts as $ const ) {
4318
+ $ this ->constInfos [] = parseConstLike (
4319
+ $ prettyPrinter ,
4320
+ new ConstName ($ const ->namespacedName , $ const ->name ->toString ()),
4321
+ $ const ,
4322
+ 0 ,
4323
+ null ,
4324
+ $ stmt ->getComments (),
4325
+ $ cond ,
4326
+ $ this ->isUndocumentable ,
4327
+ $ this ->getMinimumPhpVersionIdCompatibility (),
4328
+ []
4329
+ );
4330
+ }
4331
+ continue ;
4332
+ }
4333
+
4334
+ if ($ stmt instanceof Stmt \Function_) {
4335
+ $ this ->funcInfos [] = parseFunctionLike (
4336
+ $ prettyPrinter ,
4337
+ new FunctionName ($ stmt ->namespacedName ),
4338
+ 0 ,
4339
+ 0 ,
4340
+ $ stmt ,
4341
+ $ cond ,
4342
+ $ this ->isUndocumentable ,
4343
+ $ this ->getMinimumPhpVersionIdCompatibility ()
4344
+ );
4345
+ continue ;
4346
+ }
4347
+
4348
+ if ($ stmt instanceof Stmt \ClassLike) {
4349
+ $ className = $ stmt ->namespacedName ;
4350
+ $ constInfos = [];
4351
+ $ propertyInfos = [];
4352
+ $ methodInfos = [];
4353
+ $ enumCaseInfos = [];
4354
+ foreach ($ stmt ->stmts as $ classStmt ) {
4355
+ $ cond = handlePreprocessorConditions ($ conds , $ classStmt );
4356
+ if ($ classStmt instanceof Stmt \Nop) {
4357
+ continue ;
4358
+ }
4359
+
4360
+ $ classFlags = $ stmt instanceof Class_ ? $ stmt ->flags : 0 ;
4361
+ $ abstractFlag = $ stmt instanceof Stmt \Interface_ ? Modifiers::ABSTRACT : 0 ;
4362
+
4363
+ if ($ classStmt instanceof Stmt \ClassConst) {
4364
+ foreach ($ classStmt ->consts as $ const ) {
4365
+ $ constInfos [] = parseConstLike (
4366
+ $ prettyPrinter ,
4367
+ new ClassConstName ($ className , $ const ->name ->toString ()),
4368
+ $ const ,
4369
+ $ classStmt ->flags ,
4370
+ $ classStmt ->type ,
4371
+ $ classStmt ->getComments (),
4372
+ $ cond ,
4373
+ $ this ->isUndocumentable ,
4374
+ $ this ->getMinimumPhpVersionIdCompatibility (),
4375
+ AttributeInfo::createFromGroups ($ classStmt ->attrGroups )
4376
+ );
4377
+ }
4378
+ } else if ($ classStmt instanceof Stmt \Property) {
4379
+ if (!($ classStmt ->flags & Class_::VISIBILITY_MODIFIER_MASK )) {
4380
+ throw new Exception ("Visibility modifier is required " );
4381
+ }
4382
+ foreach ($ classStmt ->props as $ property ) {
4383
+ $ propertyInfos [] = parseProperty (
4384
+ $ className ,
4385
+ $ classFlags ,
4386
+ $ classStmt ->flags ,
4387
+ $ property ,
4388
+ $ classStmt ->type ,
4389
+ $ classStmt ->getComments (),
4390
+ $ prettyPrinter ,
4391
+ $ this ->getMinimumPhpVersionIdCompatibility (),
4392
+ AttributeInfo::createFromGroups ($ classStmt ->attrGroups )
4393
+ );
4394
+ }
4395
+ } else if ($ classStmt instanceof Stmt \ClassMethod) {
4396
+ if (!($ classStmt ->flags & Class_::VISIBILITY_MODIFIER_MASK )) {
4397
+ throw new Exception ("Visibility modifier is required " );
4398
+ }
4399
+ $ methodInfos [] = parseFunctionLike (
4400
+ $ prettyPrinter ,
4401
+ new MethodName ($ className , $ classStmt ->name ->toString ()),
4402
+ $ classFlags ,
4403
+ $ classStmt ->flags | $ abstractFlag ,
4404
+ $ classStmt ,
4405
+ $ cond ,
4406
+ $ this ->isUndocumentable ,
4407
+ $ this ->getMinimumPhpVersionIdCompatibility ()
4408
+ );
4409
+ } else if ($ classStmt instanceof Stmt \EnumCase) {
4410
+ $ enumCaseInfos [] = new EnumCaseInfo (
4411
+ $ classStmt ->name ->toString (), $ classStmt ->expr );
4412
+ } else {
4413
+ throw new Exception ("Not implemented {$ classStmt ->getType ()}" );
4414
+ }
4415
+ }
4416
+
4417
+ $ this ->classInfos [] = parseClass (
4418
+ $ className ,
4419
+ $ stmt ,
4420
+ $ constInfos ,
4421
+ $ propertyInfos ,
4422
+ $ methodInfos ,
4423
+ $ enumCaseInfos ,
4424
+ $ cond ,
4425
+ $ this ->getMinimumPhpVersionIdCompatibility (),
4426
+ $ this ->isUndocumentable
4427
+ );
4428
+ continue ;
4429
+ }
4430
+
4431
+ if ($ stmt instanceof Stmt \Expression) {
4432
+ $ expr = $ stmt ->expr ;
4433
+ if ($ expr instanceof Expr \Include_) {
4434
+ $ this ->dependencies [] = (string )EvaluatedValue::createFromExpression ($ expr ->expr , null , null , [])->value ;
4435
+ continue ;
4436
+ }
4437
+ }
4438
+
4439
+ throw new Exception ("Unexpected node {$ stmt ->getType ()}" );
4440
+ }
4441
+ if (!empty ($ conds )) {
4442
+ throw new Exception ("Unterminated preprocessor conditions " );
4443
+ }
4444
+ }
4301
4445
}
4302
4446
4303
4447
class DocCommentTag {
@@ -4910,150 +5054,6 @@ function getFileDocComments(array $stmts): array {
4910
5054
);
4911
5055
}
4912
5056
4913
- function handleStatements (FileInfo $ fileInfo , array $ stmts , PrettyPrinterAbstract $ prettyPrinter ) {
4914
- $ conds = [];
4915
- foreach ($ stmts as $ stmt ) {
4916
- $ cond = handlePreprocessorConditions ($ conds , $ stmt );
4917
-
4918
- if ($ stmt instanceof Stmt \Nop) {
4919
- continue ;
4920
- }
4921
-
4922
- if ($ stmt instanceof Stmt \Namespace_) {
4923
- handleStatements ($ fileInfo , $ stmt ->stmts , $ prettyPrinter );
4924
- continue ;
4925
- }
4926
-
4927
- if ($ stmt instanceof Stmt \Const_) {
4928
- foreach ($ stmt ->consts as $ const ) {
4929
- $ fileInfo ->constInfos [] = parseConstLike (
4930
- $ prettyPrinter ,
4931
- new ConstName ($ const ->namespacedName , $ const ->name ->toString ()),
4932
- $ const ,
4933
- 0 ,
4934
- null ,
4935
- $ stmt ->getComments (),
4936
- $ cond ,
4937
- $ fileInfo ->isUndocumentable ,
4938
- $ fileInfo ->getMinimumPhpVersionIdCompatibility (),
4939
- []
4940
- );
4941
- }
4942
- continue ;
4943
- }
4944
-
4945
- if ($ stmt instanceof Stmt \Function_) {
4946
- $ fileInfo ->funcInfos [] = parseFunctionLike (
4947
- $ prettyPrinter ,
4948
- new FunctionName ($ stmt ->namespacedName ),
4949
- 0 ,
4950
- 0 ,
4951
- $ stmt ,
4952
- $ cond ,
4953
- $ fileInfo ->isUndocumentable ,
4954
- $ fileInfo ->getMinimumPhpVersionIdCompatibility ()
4955
- );
4956
- continue ;
4957
- }
4958
-
4959
- if ($ stmt instanceof Stmt \ClassLike) {
4960
- $ className = $ stmt ->namespacedName ;
4961
- $ constInfos = [];
4962
- $ propertyInfos = [];
4963
- $ methodInfos = [];
4964
- $ enumCaseInfos = [];
4965
- foreach ($ stmt ->stmts as $ classStmt ) {
4966
- $ cond = handlePreprocessorConditions ($ conds , $ classStmt );
4967
- if ($ classStmt instanceof Stmt \Nop) {
4968
- continue ;
4969
- }
4970
-
4971
- $ classFlags = $ stmt instanceof Class_ ? $ stmt ->flags : 0 ;
4972
- $ abstractFlag = $ stmt instanceof Stmt \Interface_ ? Modifiers::ABSTRACT : 0 ;
4973
-
4974
- if ($ classStmt instanceof Stmt \ClassConst) {
4975
- foreach ($ classStmt ->consts as $ const ) {
4976
- $ constInfos [] = parseConstLike (
4977
- $ prettyPrinter ,
4978
- new ClassConstName ($ className , $ const ->name ->toString ()),
4979
- $ const ,
4980
- $ classStmt ->flags ,
4981
- $ classStmt ->type ,
4982
- $ classStmt ->getComments (),
4983
- $ cond ,
4984
- $ fileInfo ->isUndocumentable ,
4985
- $ fileInfo ->getMinimumPhpVersionIdCompatibility (),
4986
- AttributeInfo::createFromGroups ($ classStmt ->attrGroups )
4987
- );
4988
- }
4989
- } else if ($ classStmt instanceof Stmt \Property) {
4990
- if (!($ classStmt ->flags & Class_::VISIBILITY_MODIFIER_MASK )) {
4991
- throw new Exception ("Visibility modifier is required " );
4992
- }
4993
- foreach ($ classStmt ->props as $ property ) {
4994
- $ propertyInfos [] = parseProperty (
4995
- $ className ,
4996
- $ classFlags ,
4997
- $ classStmt ->flags ,
4998
- $ property ,
4999
- $ classStmt ->type ,
5000
- $ classStmt ->getComments (),
5001
- $ prettyPrinter ,
5002
- $ fileInfo ->getMinimumPhpVersionIdCompatibility (),
5003
- AttributeInfo::createFromGroups ($ classStmt ->attrGroups )
5004
- );
5005
- }
5006
- } else if ($ classStmt instanceof Stmt \ClassMethod) {
5007
- if (!($ classStmt ->flags & Class_::VISIBILITY_MODIFIER_MASK )) {
5008
- throw new Exception ("Visibility modifier is required " );
5009
- }
5010
- $ methodInfos [] = parseFunctionLike (
5011
- $ prettyPrinter ,
5012
- new MethodName ($ className , $ classStmt ->name ->toString ()),
5013
- $ classFlags ,
5014
- $ classStmt ->flags | $ abstractFlag ,
5015
- $ classStmt ,
5016
- $ cond ,
5017
- $ fileInfo ->isUndocumentable ,
5018
- $ fileInfo ->getMinimumPhpVersionIdCompatibility ()
5019
- );
5020
- } else if ($ classStmt instanceof Stmt \EnumCase) {
5021
- $ enumCaseInfos [] = new EnumCaseInfo (
5022
- $ classStmt ->name ->toString (), $ classStmt ->expr );
5023
- } else {
5024
- throw new Exception ("Not implemented {$ classStmt ->getType ()}" );
5025
- }
5026
- }
5027
-
5028
- $ fileInfo ->classInfos [] = parseClass (
5029
- $ className ,
5030
- $ stmt ,
5031
- $ constInfos ,
5032
- $ propertyInfos ,
5033
- $ methodInfos ,
5034
- $ enumCaseInfos ,
5035
- $ cond ,
5036
- $ fileInfo ->getMinimumPhpVersionIdCompatibility (),
5037
- $ fileInfo ->isUndocumentable
5038
- );
5039
- continue ;
5040
- }
5041
-
5042
- if ($ stmt instanceof Stmt \Expression) {
5043
- $ expr = $ stmt ->expr ;
5044
- if ($ expr instanceof Expr \Include_) {
5045
- $ fileInfo ->dependencies [] = (string )EvaluatedValue::createFromExpression ($ expr ->expr , null , null , [])->value ;
5046
- continue ;
5047
- }
5048
- }
5049
-
5050
- throw new Exception ("Unexpected node {$ stmt ->getType ()}" );
5051
- }
5052
- if (!empty ($ conds )) {
5053
- throw new Exception ("Unterminated preprocessor conditions " );
5054
- }
5055
- }
5056
-
5057
5057
function parseStubFile (string $ code ): FileInfo {
5058
5058
$ parser = new PhpParser \Parser \Php7 (new PhpParser \Lexer \Emulative ());
5059
5059
$ nodeTraverser = new PhpParser \NodeTraverser ;
@@ -5070,7 +5070,7 @@ protected function pName_FullyQualified(Name\FullyQualified $node): string {
5070
5070
$ fileTags = parseDocComments (getFileDocComments ($ stmts ));
5071
5071
$ fileInfo = new FileInfo ($ fileTags );
5072
5072
5073
- handleStatements ( $ fileInfo, $ stmts , $ prettyPrinter );
5073
+ $ fileInfo-> handleStatements ( $ stmts , $ prettyPrinter );
5074
5074
return $ fileInfo ;
5075
5075
}
5076
5076
0 commit comments