Skip to content

Commit 9f21af7

Browse files
committed
class summary
1 parent dcbb174 commit 9f21af7

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

src/Php/Doc/PhpDocComment.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ public function getDescription(): string
3030
$str = $this->text;
3131
$str = str_replace(["\r\n", "\r", "\n"], "\n", $str);
3232
$lines = explode("\n", $str);
33-
return array_shift($lines);
33+
$firstLine = array_shift($lines);
34+
return preg_replace('/\@\S+.*/', '', $firstLine);
3435
}
3536

3637
public function getVarTypeName(): string {

test/PhpDocCommentTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,4 +118,18 @@ public function test_getReturnType(): void {
118118

119119
$this->assertSame("int|null", $doc->getReturnTypeName(), 'return type name.');
120120
}
121+
public function test_getClassComment(): void {
122+
$parser = (new ParserFactory)->create(ParserFactory::PREFER_PHP7);
123+
$filename = sprintf('%s/php8/product/Product.php', $this->fixtureDir);
124+
try {
125+
$ast = $parser->parse(file_get_contents($filename));
126+
} catch (Error $error) {
127+
throw new \Exception("Parse error: {$error->getMessage()} file: {$filename}\n");
128+
}
129+
130+
$class = $ast[0]->stmts[2];
131+
$doc = new PhpDocComment($class);
132+
133+
$this->assertSame('', $doc->getDescription(), 'class type name.');
134+
}
121135
}

test/fixtures/php8/product/Product.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
};
88
use hoge\fuga\product\tag\Tag;
99

10+
/**
11+
* @hoge hogehoge
12+
*/
1013
class Product {
1114
private ?string $nullableString;
1215
private int|string $intOrString;

0 commit comments

Comments
 (0)