Skip to content

Commit 47c9380

Browse files
committed
Extractor::extractAll() fixed file comment parsing
1 parent 3e1f6ba commit 47c9380

File tree

2 files changed

+48
-1
lines changed

2 files changed

+48
-1
lines changed

src/PhpGenerator/Extractor.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,11 @@ public function enterNode(Node $node)
207207
}
208208
};
209209

210-
if ($this->statements) {
210+
if (
211+
$this->statements
212+
&& !$this->statements[0] instanceof Node\Stmt\ClassLike
213+
&& !$this->statements[0] instanceof Node\Stmt\Function_
214+
) {
211215
$this->addCommentAndAttributes($phpFile, $this->statements[0]);
212216
}
213217

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Nette\PhpGenerator\Extractor;
6+
use Tester\Assert;
7+
require __DIR__ . '/../bootstrap.php';
8+
9+
10+
$file = (new Extractor(<<<'XX'
11+
<?php
12+
13+
/** doc comment */
14+
class Class1
15+
{
16+
}
17+
18+
XX))->extractAll();
19+
20+
Assert::null($file->getComment());
21+
Assert::same('doc comment', $file->getClasses()['Class1']->getComment());
22+
23+
24+
$file = (new Extractor(<<<'XX'
25+
<?php
26+
27+
/** doc comment */
28+
29+
namespace Abc;
30+
XX))->extractAll();
31+
32+
Assert::same('doc comment', $file->getComment());
33+
34+
35+
$file = (new Extractor(<<<'XX'
36+
<?php
37+
38+
#[ExampleAttribute]
39+
40+
function () {};
41+
XX))->extractAll();
42+
43+
Assert::null($file->getComment());

0 commit comments

Comments
 (0)