Skip to content
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

feat(dev): improve broken reference output #7730

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
move classnameToProtobufPath into XrefValidationTrait
  • Loading branch information
bshaffer committed Oct 7, 2024
commit d4a83a86851c282b952e9615285a17272ccf794a
31 changes: 0 additions & 31 deletions dev/src/Command/DocFxCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -270,35 +270,4 @@ private function validate(ClassNode $class, OutputInterface $output): bool
}
return $valid;
}

private function classnameToProtobufPath(string $ref, string $text): string
{
// remove leading and trailing slashes and parentheses
$ref = trim(trim($ref, '\\'), '()');
// convert methods to snake case
if (strpos($ref, '::set') !== false || strpos($ref, '::get') !== false) {
$parts = explode('::', $ref);
$ref = $parts[0] . '.' . strtolower(preg_replace('/(?<!^)[A-Z]/', '_$0', substr($parts[1], 3)));
}

// convert namespace separators and function calls to dots
$ref = str_replace(['\\', '::'], '.', $ref);

// lowercase the namespace
$parts = explode('.', $ref);
foreach ($parts as $i => $part) {
if (preg_match(Component::VERSION_REGEX, $part) || $part === 'Master') {
for ($j = 0; $j <= $i; $j++) {
$parts[$j] = strtolower($parts[$j]);
}
$ref = implode('.', $parts);
break;
}
}

// convert namespace to lowercase
$ref = false === strpos($ref, '.') ? strtolower($ref) : $ref;

return sprintf('[%s][%s]', $text, $ref);
}
}
31 changes: 31 additions & 0 deletions dev/src/DocFx/XrefValidationTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,35 @@ function ($matches) use (&$brokenRefs) {

return $brokenRefs;
}

private function classnameToProtobufPath(string $ref, string $text): string
{
// remove leading and trailing slashes and parentheses
$ref = trim(trim($ref, '\\'), '()');
// convert methods to snake case
if (strpos($ref, '::set') !== false || strpos($ref, '::get') !== false) {
$parts = explode('::', $ref);
$ref = $parts[0] . '.' . strtolower(preg_replace('/(?<!^)[A-Z]/', '_$0', substr($parts[1], 3)));
}

// convert namespace separators and function calls to dots
$ref = str_replace(['\\', '::'], '.', $ref);

// lowercase the namespace
$parts = explode('.', $ref);
foreach ($parts as $i => $part) {
if (preg_match(Component::VERSION_REGEX, $part) || $part === 'Master') {
for ($j = 0; $j <= $i; $j++) {
$parts[$j] = strtolower($parts[$j]);
}
$ref = implode('.', $parts);
break;
}
}

// convert namespace to lowercase
$ref = false === strpos($ref, '.') ? strtolower($ref) : $ref;

return sprintf('[%s][%s]', $text, $ref);
}
}