Skip to content

Commit

Permalink
Use constant for indentation size in WP doc comments (#214)
Browse files Browse the repository at this point in the history
  • Loading branch information
IanDelMar authored Aug 27, 2024
1 parent c1e8f57 commit f0a3175
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/Visitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@

class Visitor extends NodeVisitor
{
/**
* The number of spaces used for indentation in WordPress Doc Comments.
*/
private const WP_INDENT_SIZE = 4;

private \phpDocumentor\Reflection\DocBlockFactoryInterface $docBlockFactory;

/** @var array<string,array<int|string,string>> */
Expand Down Expand Up @@ -288,7 +293,7 @@ static function (WordPressTag $tag): string {

$newDocComment = sprintf(
"%s\n%s\n */",
substr($docCommentText, 0, -4),
substr($docCommentText, 0, -self::WP_INDENT_SIZE),
implode("\n", $additionStrings)
);

Expand Down Expand Up @@ -477,7 +482,7 @@ private function addStringTags(string $name, Doc $docComment): ?Doc
$docCommentText = $docComment->getText();
$newDocComment = sprintf(
"%s\n * %s\n */",
substr($docCommentText, 0, -4),
substr($docCommentText, 0, -self::WP_INDENT_SIZE),
implode("\n * ", $additions)
);

Expand Down Expand Up @@ -712,7 +717,7 @@ private static function getElementsFromDescription(Description $tagDescription,
private static function getTypesAtLevel(string $text, bool $optional, int $level): array
{
// Populate `$types` with the value of each top level `@type`.
$spaces = str_repeat(' ', ($level * 4));
$spaces = str_repeat(' ', ($level * self::WP_INDENT_SIZE));
$types = preg_split("/\R+{$spaces}@type /", $text);

if ($types === false) {
Expand Down

0 comments on commit f0a3175

Please sign in to comment.