Skip to content

Commit 11e677e

Browse files
committed
remove comments from undocumented globals
1 parent 7c2eaa2 commit 11e677e

File tree

4 files changed

+10
-8
lines changed

4 files changed

+10
-8
lines changed

src/NodeVisitor.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -418,13 +418,21 @@ function (\PhpParser\Node\Const_ $const) {
418418
// We'll keep regular global variable declarations, depending on
419419
// whether or not they are documented.
420420
// Only @var comments are actual, useful documentation for stubs
421-
$hasValidComment = $node->getDocComment() && preg_match('/@(?:[a-z]+-)?var\s/', $node->getDocComment()->getText());
421+
$hasValidComment = $node->getDocComment() && preg_match('/@(?:[a-z]+-)?var\s/', $node->getDocComment()->getText());
422422

423423
if ($this->needsDocumentedGlobals && $hasValidComment) {
424424
$this->count('globals', $node->expr->var->name);
425425
return $this->needsDocumentedGlobals;
426-
} elseif ($this->needsUndocumentedGlobals && !$hasValidComment) {
426+
}
427+
428+
if ($this->needsUndocumentedGlobals && !$hasValidComment) {
427429
$this->count('globals', $node->expr->var->name);
430+
431+
// remove useless comments
432+
if ($node->getComments() !== []) {
433+
$node->setAttribute('comments', []);
434+
}
435+
428436
return $this->needsUndocumentedGlobals;
429437
}
430438
}

test/files/globals.all.out.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99

1010
$d = 'd' . 'd';
1111

12-
/** doc */
1312
$x = 'x' . 'x';
1413

15-
/** @doc */
1614
$y = 'y' . 'y';

test/files/globals.no-doc.out.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33

44
$d = 'd' . 'd';
55

6-
/** doc */
76
$x = 'x' . 'x';
87

9-
/** @doc */
108
$y = 'y' . 'y';

test/files/globals.nullified.out.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99

1010
$d = \null;
1111

12-
/** doc */
1312
$x = \null;
1413

15-
/** @doc */
1614
$y = \null;

0 commit comments

Comments
 (0)