Skip to content

Commit

Permalink
add allowFailures for obscure phpdoc errors
Browse files Browse the repository at this point in the history
  • Loading branch information
bshaffer committed May 3, 2024
1 parent e36f250 commit 7678de5
Showing 1 changed file with 25 additions and 9 deletions.
34 changes: 25 additions & 9 deletions dev/src/Command/DocFxCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ class DocFxCommand extends Command
private array $composerJson;
private array $repoMetadataJson;

// these links are inexplicably broken, and will require more investigation
private static array $allowedReferenceFailures = [
'\Google\Cloud\ResourceManager\V3\Client\ProjectsClient::testIamPermissions()'
=> 'ProjectsClient::testIamPermissionsAsync()',
'\Google\Cloud\Logging\V2\Client\ConfigServiceV2Client::getView()'
=> 'ConfigServiceV2Client::getViewAsync()'
];

protected function configure()
{
$this->setName('docfx')
Expand Down Expand Up @@ -215,26 +223,34 @@ public static function getPhpDocCommand(string $componentPath, string $outDir):
private function validate(ClassNode $class, OutputInterface $output): bool
{
$valid = true;
$hadWarning = false;
$isGenerated = $class->isProtobufMessageClass() || $class->isProtobufEnumClass() || $class->isServiceClass();
$nodes = array_merge([$class], $class->getMethods(), $class->getConstants());
foreach ($nodes as $node) {
foreach ($this->getInvalidXrefs($node->getContent()) as $invalidRef) {
if (isset(self::$allowedReferenceFailures[$node->getFullname()])
&& self::$allowedReferenceFailures[$node->getFullname()] == $invalidRef) {
// these links are inexplicably broken in phpdoc, and will require more investigation
continue;
}
$output->write(sprintf("\n<error>Invalid xref in %s: %s</>", $node->getFullname(), $invalidRef));
$valid = false;
$hadWarning = true;
}
foreach ($this->getBrokenXrefs($node->getContent()) as $brokenRef) {
$output->write(sprintf(
"\n<comment>Broken xref in %s: %s</>",
$node->getFullname(),
$brokenRef ?: '<options=bold>empty</>')
$output->writeln(
sprintf(
"<comment>Broken xref in %s: %s</>",
$node->getFullname(),
$brokenRef ?: '<options=bold>empty</>'
),
$isGenerated ? OutputInterface::VERBOSITY_VERBOSE : OutputInterface::VERBOSITY_NORMAL
);
$valid = $valid && (false || $isGenerated);
$hadWarning = true;
$warned = true;
if (!$isGenerated) {
$valid = false;
}
}
}
if ($hadWarning) {
if (!$valid) {
$output->writeln('');
}
return $valid;
Expand Down

0 comments on commit 7678de5

Please sign in to comment.