@@ -55,8 +55,8 @@ function processStubFile(string $stubFile, Context $context): ?FileInfo {
55
55
initPhpParser ();
56
56
$ fileInfo = parseStubFile ($ stubCode );
57
57
$ arginfoCode = generateArgInfoCode ($ fileInfo , $ stubHash );
58
- if (( $ context ->forceRegeneration || $ stubHash !== $ oldStubHash) && file_put_contents ( $ arginfoFile , $ arginfoCode ) ) {
59
- echo " Saved $ arginfoFile \n" ;
58
+ if ($ context ->forceRegeneration || $ stubHash !== $ oldStubHash ) {
59
+ $ context -> generatedArginfoFiles [ $ arginfoFile ] = $ arginfoCode ;
60
60
}
61
61
62
62
if ($ fileInfo ->generateLegacyArginfo ) {
@@ -65,7 +65,7 @@ function processStubFile(string $stubFile, Context $context): ?FileInfo {
65
65
}
66
66
$ arginfoCode = generateArgInfoCode ($ fileInfo , $ stubHash );
67
67
if (($ context ->forceRegeneration || $ stubHash !== $ oldStubHash ) && file_put_contents ($ legacyFile , $ arginfoCode )) {
68
- echo " Saved $ legacyFile \n" ;
68
+ $ context -> generatedArginfoFiles [ $ legacyFile ] = $ arginfoCode ;
69
69
}
70
70
}
71
71
@@ -98,6 +98,8 @@ class Context {
98
98
public $ forceParse = false ;
99
99
/** @var bool */
100
100
public $ forceRegeneration = false ;
101
+ /** @var array */
102
+ public $ generatedArginfoFiles = [];
101
103
}
102
104
103
105
class SimpleType {
@@ -477,13 +479,17 @@ class FuncInfo {
477
479
/** @var FunctionOrMethodName */
478
480
public $ name ;
479
481
/** @var int */
482
+ public $ classFlags ;
483
+ /** @var int */
480
484
public $ flags ;
481
485
/** @var string|null */
482
486
public $ aliasType ;
483
487
/** @var FunctionName|null */
484
488
public $ alias ;
485
489
/** @var bool */
486
490
public $ isDeprecated ;
491
+ /** @var bool */
492
+ public $ verify ;
487
493
/** @var ArgInfo[] */
488
494
public $ args ;
489
495
/** @var ReturnInfo */
@@ -495,29 +501,43 @@ class FuncInfo {
495
501
496
502
public function __construct (
497
503
FunctionOrMethodName $ name ,
504
+ int $ classFlags ,
498
505
int $ flags ,
499
506
?string $ aliasType ,
500
507
?FunctionOrMethodName $ alias ,
501
508
bool $ isDeprecated ,
509
+ bool $ verify ,
502
510
array $ args ,
503
511
ReturnInfo $ return ,
504
512
int $ numRequiredArgs ,
505
513
?string $ cond
506
514
) {
507
515
$ this ->name = $ name ;
516
+ $ this ->classFlags = $ classFlags ;
508
517
$ this ->flags = $ flags ;
509
518
$ this ->aliasType = $ aliasType ;
510
519
$ this ->alias = $ alias ;
511
520
$ this ->isDeprecated = $ isDeprecated ;
521
+ $ this ->verify = $ verify ;
512
522
$ this ->args = $ args ;
513
523
$ this ->return = $ return ;
514
524
$ this ->numRequiredArgs = $ numRequiredArgs ;
515
525
$ this ->cond = $ cond ;
516
526
}
517
527
528
+ public function isMethod (): bool
529
+ {
530
+ return $ this ->name ->isMethod ();
531
+ }
532
+
533
+ public function isFinalMethod (): bool
534
+ {
535
+ return $ this ->flags & Class_::MODIFIER_FINAL || $ this ->classFlags & Class_::MODIFIER_FINAL ;
536
+ }
537
+
518
538
public function isInstanceMethod (): bool
519
539
{
520
- return !($ this ->flags & Class_::MODIFIER_STATIC ) && $ this ->name -> isMethod () && $ this ->name ->isConstructor () === false ;
540
+ return !($ this ->flags & Class_::MODIFIER_STATIC ) && $ this ->isMethod () && $ this ->name ->isConstructor () === false ;
521
541
}
522
542
523
543
public function equalsApartFromName (FuncInfo $ other ): bool {
@@ -757,6 +777,7 @@ function parseDocComment(DocComment $comment): array {
757
777
function parseFunctionLike (
758
778
PrettyPrinterAbstract $ prettyPrinter ,
759
779
FunctionOrMethodName $ name ,
780
+ int $ classFlags ,
760
781
int $ flags ,
761
782
Node \FunctionLike $ func ,
762
783
?string $ cond
@@ -766,6 +787,7 @@ function parseFunctionLike(
766
787
$ aliasType = null ;
767
788
$ alias = null ;
768
789
$ isDeprecated = false ;
790
+ $ noVerify = false ;
769
791
$ haveDocReturnType = false ;
770
792
$ docParamTypes = [];
771
793
@@ -778,7 +800,7 @@ function parseFunctionLike(
778
800
$ paramMeta [$ varName ] = [];
779
801
}
780
802
$ paramMeta [$ varName ]['preferRef ' ] = true ;
781
- } else if ($ tag ->name === 'alias ' || $ tag ->name === 'implementation-alias ' || $ tag -> name === ' static-method-alias ' ) {
803
+ } else if ($ tag ->name === 'alias ' || $ tag ->name === 'implementation-alias ' ) {
782
804
$ aliasType = $ tag ->name ;
783
805
$ aliasParts = explode (":: " , $ tag ->getValue ());
784
806
if (count ($ aliasParts ) === 1 ) {
@@ -788,6 +810,8 @@ function parseFunctionLike(
788
810
}
789
811
} else if ($ tag ->name === 'deprecated ' ) {
790
812
$ isDeprecated = true ;
813
+ } else if ($ tag ->name === 'no-verify ' ) {
814
+ $ noVerify = true ;
791
815
} else if ($ tag ->name === 'return ' ) {
792
816
$ haveDocReturnType = true ;
793
817
} else if ($ tag ->name === 'param ' ) {
@@ -868,10 +892,12 @@ function parseFunctionLike(
868
892
869
893
return new FuncInfo (
870
894
$ name ,
895
+ $ classFlags ,
871
896
$ flags ,
872
897
$ aliasType ,
873
898
$ alias ,
874
899
$ isDeprecated ,
900
+ !$ noVerify ,
875
901
$ args ,
876
902
$ return ,
877
903
$ numRequiredArgs ,
@@ -942,6 +968,7 @@ function handleStatements(FileInfo $fileInfo, array $stmts, PrettyPrinterAbstrac
942
968
$ prettyPrinter ,
943
969
new FunctionName ($ stmt ->namespacedName ),
944
970
0 ,
971
+ 0 ,
945
972
$ stmt ,
946
973
$ cond
947
974
);
@@ -961,6 +988,11 @@ function handleStatements(FileInfo $fileInfo, array $stmts, PrettyPrinterAbstrac
961
988
throw new Exception ("Not implemented {$ classStmt ->getType ()}" );
962
989
}
963
990
991
+ $ classFlags = 0 ;
992
+ if ($ stmt instanceof Class_) {
993
+ $ classFlags = $ stmt ->flags ;
994
+ }
995
+
964
996
$ flags = $ classStmt ->flags ;
965
997
if ($ stmt instanceof Stmt \Interface_) {
966
998
$ flags |= Class_::MODIFIER_ABSTRACT ;
@@ -973,6 +1005,7 @@ function handleStatements(FileInfo $fileInfo, array $stmts, PrettyPrinterAbstrac
973
1005
$ methodInfos [] = parseFunctionLike (
974
1006
$ prettyPrinter ,
975
1007
new MethodName ($ className , $ classStmt ->name ->toString ()),
1008
+ $ classFlags ,
976
1009
$ flags ,
977
1010
$ classStmt ,
978
1011
$ cond
@@ -1314,24 +1347,6 @@ function initPhpParser() {
1314
1347
exit (1 );
1315
1348
}
1316
1349
1317
- if ($ printParameterStats ) {
1318
- $ parameterStats = [];
1319
-
1320
- foreach ($ fileInfos as $ fileInfo ) {
1321
- foreach ($ fileInfo ->getAllFuncInfos () as $ funcInfo ) {
1322
- foreach ($ funcInfo ->args as $ argInfo ) {
1323
- if (!isset ($ context ->parameterStats [$ argInfo ->name ])) {
1324
- $ parameterStats [$ argInfo ->name ] = 0 ;
1325
- }
1326
- $ parameterStats [$ argInfo ->name ]++;
1327
- }
1328
- }
1329
- }
1330
-
1331
- arsort ($ parameterStats );
1332
- echo json_encode ($ parameterStats , JSON_PRETTY_PRINT ), "\n" ;
1333
- }
1334
-
1335
1350
if ($ verify ) {
1336
1351
$ errors = [];
1337
1352
$ funcMap = [];
@@ -1342,7 +1357,7 @@ function initPhpParser() {
1342
1357
/** @var FuncInfo $funcInfo */
1343
1358
$ funcMap [$ funcInfo ->name ->__toString ()] = $ funcInfo ;
1344
1359
1345
- if ($ funcInfo ->aliasType === "alias " || $ funcInfo -> aliasType === " static-method-alias " ) {
1360
+ if ($ funcInfo ->aliasType === "alias " ) {
1346
1361
$ aliases [] = $ funcInfo ;
1347
1362
}
1348
1363
}
@@ -1354,11 +1369,15 @@ function initPhpParser() {
1354
1369
continue ;
1355
1370
}
1356
1371
1372
+ if ($ aliasFunc ->verify === false ) {
1373
+ continue ;
1374
+ }
1375
+
1357
1376
$ aliasedFunc = $ funcMap [$ aliasFunc ->alias ->__toString ()];
1358
1377
$ aliasedArgs = $ aliasedFunc ->args ;
1359
1378
$ aliasArgs = $ aliasFunc ->args ;
1360
1379
1361
- if ($ aliasFunc ->isInstanceMethod () !== $ aliasedFunc ->isInstanceMethod () && $ aliasFunc -> aliasType !== " static-method-alias " ) {
1380
+ if ($ aliasFunc ->isInstanceMethod () !== $ aliasedFunc ->isInstanceMethod ()) {
1362
1381
if ($ aliasFunc ->isInstanceMethod ()) {
1363
1382
$ aliasedArgs = array_slice ($ aliasedArgs , 1 );
1364
1383
}
@@ -1397,6 +1416,13 @@ function(?ArgInfo $aliasArg, ?ArgInfo $aliasedArg) use ($aliasFunc, $aliasedFunc
1397
1416
},
1398
1417
$ aliasArgs , $ aliasedArgs
1399
1418
);
1419
+
1420
+ if ((!$ aliasedFunc ->isMethod () || $ aliasedFunc ->isFinalMethod ()) &&
1421
+ (!$ aliasFunc ->isMethod () || $ aliasFunc ->isFinalMethod ()) &&
1422
+ $ aliasFunc ->return != $ aliasedFunc ->return
1423
+ ) {
1424
+ $ errors [] = "{$ aliasFunc ->name }() and {$ aliasedFunc ->name }() must have the same return type " ;
1425
+ }
1400
1426
}
1401
1427
1402
1428
echo implode ("\n" , $ errors );
@@ -1405,3 +1431,29 @@ function(?ArgInfo $aliasArg, ?ArgInfo $aliasedArg) use ($aliasFunc, $aliasedFunc
1405
1431
exit (1 );
1406
1432
}
1407
1433
}
1434
+
1435
+ foreach ($ context ->generatedArginfoFiles as $ arginfoFile => $ arginfoCode ) {
1436
+ if (file_put_contents ($ arginfoFile , $ arginfoCode )) {
1437
+ echo "Saved $ arginfoFile \n" ;
1438
+ } else {
1439
+ echo "Saving $ arginfoFile was unsuccessful \n" ;
1440
+ }
1441
+ }
1442
+
1443
+ if ($ printParameterStats ) {
1444
+ $ parameterStats = [];
1445
+
1446
+ foreach ($ fileInfos as $ fileInfo ) {
1447
+ foreach ($ fileInfo ->getAllFuncInfos () as $ funcInfo ) {
1448
+ foreach ($ funcInfo ->args as $ argInfo ) {
1449
+ if (!isset ($ context ->parameterStats [$ argInfo ->name ])) {
1450
+ $ parameterStats [$ argInfo ->name ] = 0 ;
1451
+ }
1452
+ $ parameterStats [$ argInfo ->name ]++;
1453
+ }
1454
+ }
1455
+ }
1456
+
1457
+ arsort ($ parameterStats );
1458
+ echo json_encode ($ parameterStats , JSON_PRETTY_PRINT ), "\n" ;
1459
+ }
0 commit comments