@@ -1222,6 +1222,8 @@ class FuncInfo {
1222
1222
public $ numRequiredArgs ;
1223
1223
/** @var string|null */
1224
1224
public $ cond ;
1225
+ /** @var bool */
1226
+ public $ isUndocumentable ;
1225
1227
1226
1228
/**
1227
1229
* @param ArgInfo[] $args
@@ -1238,7 +1240,8 @@ public function __construct(
1238
1240
array $ args ,
1239
1241
ReturnInfo $ return ,
1240
1242
int $ numRequiredArgs ,
1241
- ?string $ cond
1243
+ ?string $ cond ,
1244
+ bool $ isUndocumentable
1242
1245
) {
1243
1246
$ this ->name = $ name ;
1244
1247
$ this ->classFlags = $ classFlags ;
@@ -1252,6 +1255,7 @@ public function __construct(
1252
1255
$ this ->return = $ return ;
1253
1256
$ this ->numRequiredArgs = $ numRequiredArgs ;
1254
1257
$ this ->cond = $ cond ;
1258
+ $ this ->isUndocumentable = $ isUndocumentable ;
1255
1259
}
1256
1260
1257
1261
public function isMethod (): bool
@@ -3218,7 +3222,8 @@ function parseFunctionLike(
3218
3222
int $ classFlags ,
3219
3223
int $ flags ,
3220
3224
Node \FunctionLike $ func ,
3221
- ?string $ cond
3225
+ ?string $ cond ,
3226
+ bool $ isUndocumentable
3222
3227
): FuncInfo {
3223
3228
try {
3224
3229
$ comment = $ func ->getDocComment ();
@@ -3283,6 +3288,10 @@ function parseFunctionLike(
3283
3288
}
3284
3289
$ paramMeta [$ varName ][$ tag ->name ] = true ;
3285
3290
break ;
3291
+
3292
+ case 'undocumentable ' :
3293
+ $ isUndocumentable = true ;
3294
+ break ;
3286
3295
}
3287
3296
}
3288
3297
}
@@ -3383,7 +3392,8 @@ function parseFunctionLike(
3383
3392
$ args ,
3384
3393
$ return ,
3385
3394
$ numRequiredArgs ,
3386
- $ cond
3395
+ $ cond ,
3396
+ $ isUndocumentable
3387
3397
);
3388
3398
} catch (Exception $ e ) {
3389
3399
throw new Exception ($ name . "(): " .$ e ->getMessage ());
@@ -3570,6 +3580,12 @@ function parseClass(
3570
3580
throw new Exception ("Unknown class kind " . get_class ($ class ));
3571
3581
}
3572
3582
3583
+ if ($ isUndocumentable ) {
3584
+ foreach ($ methods as $ method ) {
3585
+ $ method ->isUndocumentable = true ;
3586
+ }
3587
+ }
3588
+
3573
3589
return new ClassInfo (
3574
3590
$ name ,
3575
3591
$ flags ,
@@ -3674,7 +3690,8 @@ function handleStatements(FileInfo $fileInfo, array $stmts, PrettyPrinterAbstrac
3674
3690
0 ,
3675
3691
0 ,
3676
3692
$ stmt ,
3677
- $ cond
3693
+ $ cond ,
3694
+ $ fileInfo ->isUndocumentable
3678
3695
);
3679
3696
continue ;
3680
3697
}
@@ -3731,7 +3748,8 @@ function handleStatements(FileInfo $fileInfo, array $stmts, PrettyPrinterAbstrac
3731
3748
$ classFlags ,
3732
3749
$ classStmt ->flags | $ abstractFlag ,
3733
3750
$ classStmt ,
3734
- $ cond
3751
+ $ cond ,
3752
+ $ fileInfo ->isUndocumentable
3735
3753
);
3736
3754
} else if ($ classStmt instanceof Stmt \EnumCase) {
3737
3755
$ enumCaseInfos [] = new EnumCaseInfo (
@@ -4342,7 +4360,7 @@ function replaceClassSynopses(string $targetDirectory, array $classMap, iterable
4342
4360
foreach ($ missingClassSynopses as $ className => $ info ) {
4343
4361
/** @var ClassInfo $info */
4344
4362
if (!$ info ->isUndocumentable ) {
4345
- echo "Warning: Missing class synopsis page for $ className \n" ;
4363
+ echo "Warning: Missing class synopsis for $ className \n" ;
4346
4364
}
4347
4365
}
4348
4366
}
@@ -4388,7 +4406,8 @@ function generateMethodSynopses(array $funcMap, array $aliasMap): array {
4388
4406
* @param array<string, FuncInfo> $aliasMap
4389
4407
* @return array<string, string>
4390
4408
*/
4391
- function replaceMethodSynopses (string $ targetDirectory , array $ funcMap , array $ aliasMap ): array {
4409
+ function replaceMethodSynopses (string $ targetDirectory , array $ funcMap , array $ aliasMap , bool $ isVerify ): array {
4410
+ $ existingMethodSynopses = [];
4392
4411
$ methodSynopses = [];
4393
4412
4394
4413
$ it = new RecursiveIteratorIterator (
@@ -4407,6 +4426,27 @@ function replaceMethodSynopses(string $targetDirectory, array $funcMap, array $a
4407
4426
continue ;
4408
4427
}
4409
4428
4429
+ if ($ isVerify ) {
4430
+ $ matches = [];
4431
+ preg_match ("/<refname>\s*(\w+)\s*<\/refname>\s*<refpurpose>\s*&Alias;\s*<(?:function|methodname)>\s*(\w+)\s*<\/(?:function|methodname)>\s*<\/refpurpose>/i " , $ xml , $ matches );
4432
+ $ aliasName = $ matches [1 ] ?? null ;
4433
+ $ alias = $ funcMap [$ aliasName ] ?? null ;
4434
+ $ funcName = $ matches [2 ] ?? null ;
4435
+ $ func = $ funcMap [$ funcName ] ?? null ;
4436
+
4437
+ if ($ alias &&
4438
+ !$ alias ->isUndocumentable &&
4439
+ ($ func === null || $ func ->alias === null || $ func ->alias ->__toString () !== $ aliasName ) &&
4440
+ ($ alias ->alias === null || $ alias ->alias ->__toString () !== $ funcName )
4441
+ ) {
4442
+ echo "Warning: $ aliasName() is an alias for " . $ alias ->alias ->__toString () . "(), but it is incorrectly documented as an alias for $ funcName() \n" ;
4443
+ }
4444
+
4445
+ if ($ aliasName ) {
4446
+ $ existingMethodSynopses [$ aliasName ] = $ aliasName ;
4447
+ }
4448
+ }
4449
+
4410
4450
if (stripos ($ xml , "<methodsynopsis " ) === false && stripos ($ xml , "<constructorsynopsis " ) === false && stripos ($ xml , "<destructorsynopsis " ) === false ) {
4411
4451
continue ;
4412
4452
}
@@ -4448,7 +4488,9 @@ function replaceMethodSynopses(string $targetDirectory, array $funcMap, array $a
4448
4488
if (!isset ($ funcMap [$ funcName ])) {
4449
4489
continue ;
4450
4490
}
4491
+
4451
4492
$ funcInfo = $ funcMap [$ funcName ];
4493
+ $ existingMethodSynopses [$ funcInfo ->name ->__toString ()] = $ funcInfo ->name ->__toString ();
4452
4494
4453
4495
$ newMethodSynopsis = $ funcInfo ->getMethodSynopsisElement ($ funcMap , $ aliasMap , $ doc );
4454
4496
if ($ newMethodSynopsis === null ) {
@@ -4534,6 +4576,16 @@ function replaceMethodSynopses(string $targetDirectory, array $funcMap, array $a
4534
4576
}
4535
4577
}
4536
4578
4579
+ if ($ isVerify ) {
4580
+ $ missingMethodSynopses = array_diff_key ($ funcMap , $ existingMethodSynopses );
4581
+ foreach ($ missingMethodSynopses as $ functionName => $ info ) {
4582
+ /** @var FuncInfo $info */
4583
+ if (!$ info ->isUndocumentable ) {
4584
+ echo "Warning: Missing method synopsis for $ functionName \n" ;
4585
+ }
4586
+ }
4587
+ }
4588
+
4537
4589
return $ methodSynopses ;
4538
4590
}
4539
4591
@@ -4845,7 +4897,7 @@ function(?ArgInfo $aliasArg, ?ArgInfo $aliasedArg) use ($aliasFunc, $aliasedFunc
4845
4897
}
4846
4898
4847
4899
if ($ replaceMethodSynopses ) {
4848
- $ methodSynopses = replaceMethodSynopses ($ targetSynopses , $ funcMap , $ aliasMap );
4900
+ $ methodSynopses = replaceMethodSynopses ($ targetSynopses , $ funcMap , $ aliasMap, $ verify );
4849
4901
4850
4902
foreach ($ methodSynopses as $ filename => $ content ) {
4851
4903
if (file_put_contents ($ filename , $ content )) {
0 commit comments