Skip to content

Warn about missing class synopses when running gen_stub.php --replace-classsynopses #9472

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 34 additions & 7 deletions build/gen_stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -2453,6 +2453,8 @@ class ClassInfo {
public $cond;
/** @var int|null */
public $phpVersionIdMinimumCompatibility;
/** @var bool */
public $isUndocumentable;

/**
* @param AttributeInfo[] $attributes
Expand Down Expand Up @@ -2480,7 +2482,8 @@ public function __construct(
array $funcInfos,
array $enumCaseInfos,
?string $cond,
?int $minimumPhpVersionIdCompatibility
?int $minimumPhpVersionIdCompatibility,
bool $isUndocumentable
) {
$this->name = $name;
$this->flags = $flags;
Expand All @@ -2499,6 +2502,7 @@ public function __construct(
$this->enumCaseInfos = $enumCaseInfos;
$this->cond = $cond;
$this->phpVersionIdMinimumCompatibility = $minimumPhpVersionIdCompatibility;
$this->isUndocumentable = $isUndocumentable;
}

/**
Expand Down Expand Up @@ -3088,6 +3092,8 @@ class FileInfo {
public $generateLegacyArginfoForPhpVersionId;
/** @var bool */
public $generateClassEntries = false;
/** @var bool */
public $isUndocumentable = false;

/**
* @return iterable<FuncInfo>
Expand Down Expand Up @@ -3499,7 +3505,8 @@ function parseClass(
array $methods,
array $enumCases,
?string $cond,
?int $minimumPhpVersionIdCompatibility
?int $minimumPhpVersionIdCompatibility,
bool $isUndocumentable
): ClassInfo {
$flags = $class instanceof Class_ ? $class->flags : 0;
$comment = $class->getDocComment();
Expand All @@ -3521,6 +3528,8 @@ function parseClass(
$isStrictProperties = true;
} else if ($tag->name === 'not-serializable') {
$isNotSerializable = true;
} else if ($tag->name === 'undocumentable') {
$isUndocumentable = true;
}
}
}
Expand Down Expand Up @@ -3579,7 +3588,8 @@ function parseClass(
$methods,
$enumCases,
$cond,
$minimumPhpVersionIdCompatibility
$minimumPhpVersionIdCompatibility,
$isUndocumentable
);
}

Expand Down Expand Up @@ -3732,7 +3742,7 @@ function handleStatements(FileInfo $fileInfo, array $stmts, PrettyPrinterAbstrac
}

$fileInfo->classInfos[] = parseClass(
$className, $stmt, $constInfos, $propertyInfos, $methodInfos, $enumCaseInfos, $cond, $fileInfo->generateLegacyArginfoForPhpVersionId
$className, $stmt, $constInfos, $propertyInfos, $methodInfos, $enumCaseInfos, $cond, $fileInfo->generateLegacyArginfoForPhpVersionId, $fileInfo->isUndocumentable
);
continue;
}
Expand Down Expand Up @@ -3783,6 +3793,8 @@ protected function pName_FullyQualified(Name\FullyQualified $node) {
} else if ($tag->name === 'generate-class-entries') {
$fileInfo->generateClassEntries = true;
$fileInfo->declarationPrefix = $tag->value ? $tag->value . " " : "";
} else if ($tag->name === 'undocumentable') {
$fileInfo->isUndocumentable = true;
}
}
}
Expand Down Expand Up @@ -4219,12 +4231,14 @@ function generateClassSynopses(array $classMap, iterable $allConstInfos): array
}

/**
* @param ClassInfo[] $classMap
* @param array<string, ClassInfo> $classMap
* $param iterable<ConstInfo> $allConstInfos
* @return array<string, string>
*/
function replaceClassSynopses(string $targetDirectory, array $classMap, iterable $allConstInfos): array
function replaceClassSynopses(string $targetDirectory, array $classMap, iterable $allConstInfos, bool $isVerify): array
{
$existingClassSynopses = [];

$classSynopses = [];

$it = new RecursiveIteratorIterator(
Expand Down Expand Up @@ -4281,6 +4295,9 @@ function replaceClassSynopses(string $targetDirectory, array $classMap, iterable
if (!isset($classMap[$className])) {
continue;
}

$existingClassSynopses[$className] = $className;

$classInfo = $classMap[$className];

$newClassSynopsis = $classInfo->getClassSynopsisElement($doc, $classMap, $allConstInfos);
Expand Down Expand Up @@ -4320,6 +4337,16 @@ function replaceClassSynopses(string $targetDirectory, array $classMap, iterable
}
}

if ($isVerify) {
$missingClassSynopses = array_diff_key($classMap, $existingClassSynopses);
foreach ($missingClassSynopses as $className => $info) {
/** @var ClassInfo $info */
if (!$info->isUndocumentable) {
echo "Warning: Missing class synopsis page for $className\n";
}
}
}

return $classSynopses;
}

Expand Down Expand Up @@ -4791,7 +4818,7 @@ function(?ArgInfo $aliasArg, ?ArgInfo $aliasedArg) use ($aliasFunc, $aliasedFunc
}

if ($replaceClassSynopses) {
$classSynopses = replaceClassSynopses($targetSynopses, $classMap, $context->allConstInfos);
$classSynopses = replaceClassSynopses($targetSynopses, $classMap, $context->allConstInfos, $verify);

foreach ($classSynopses as $filename => $content) {
if (file_put_contents($filename, $content)) {
Expand Down
5 changes: 4 additions & 1 deletion ext/pdo_pgsql/pgsql_driver.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

/** @generate-function-entries */

// These are extension methods for PDO. This is not a real class.
/**
* These are extension methods for PDO. This is not a real class.
* @undocumentable
*/
class PDO_PGSql_Ext {
/** @tentative-return-type */
public function pgsqlCopyFromArray(string $tableName, array $rows, string $separator = "\t", string $nullAs = "\\\\N", ?string $fields = null): bool {}
Expand Down
2 changes: 1 addition & 1 deletion ext/pdo_pgsql/pgsql_driver_arginfo.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion ext/pdo_sqlite/sqlite_driver.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

/** @generate-function-entries */

// These are extension methods for PDO. This is not a real class.
/**
* These are extension methods for PDO. This is not a real class.
* @undocumentable
*/
class PDO_SQLite_Ext {
/** @tentative-return-type */
public function sqliteCreateFunction(string $name, callable $callback, int $numArgs = -1, int $flags = 0): bool {}
Expand Down
2 changes: 1 addition & 1 deletion ext/pdo_sqlite/sqlite_driver_arginfo.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions ext/standard/basic_functions.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -740,6 +740,7 @@
const LOG_PERROR = UNKNOWN;
#endif

/** @undocumentable */
#[AllowDynamicProperties]
final class __PHP_Incomplete_Class
{
Expand Down
2 changes: 1 addition & 1 deletion ext/standard/basic_functions_arginfo.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion ext/zend_test/fiber.stub.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
<?php

/** @generate-class-entries static */
/**
* @generate-class-entries static
* @undocumentable
*/

final class _ZendTestFiber
{
Expand Down
2 changes: 1 addition & 1 deletion ext/zend_test/fiber_arginfo.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions ext/zend_test/test.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
/**
* @generate-class-entries static
* @generate-legacy-arginfo 80000
* @undocumentable
*/
namespace {
/**
Expand Down
2 changes: 1 addition & 1 deletion ext/zend_test/test_arginfo.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.