Skip to content
Draft
Show file tree
Hide file tree
Changes from all 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
6 changes: 6 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,9 @@ parameters:
identifier: property.dynamicName
count: 2
path: src/Printer/Printer.php

-
message: '#^Variable property access on PHPStan\\PhpDocParser\\Ast\\Node\.$#'
identifier: property.dynamicName
count: 1
path: tests/PHPStan/Parser/TypeParserTest.php
17 changes: 9 additions & 8 deletions src/Ast/Comment.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,26 @@

use function trim;

class Comment
class Comment implements Node
{

public string $text;

public int $startLine;
use NodeAttributes;

public int $startIndex;
public string $text;

public function __construct(string $text, int $startLine = -1, int $startIndex = -1)
public function __construct(string $text)
{
$this->text = $text;
$this->startLine = $startLine;
$this->startIndex = $startIndex;
}

public function getReformattedText(): string
{
return trim($this->text);
}

public function __toString(): string
{
return $this->getReformattedText();
}

}
25 changes: 23 additions & 2 deletions src/Parser/TokenIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace PHPStan\PhpDocParser\Parser;

use LogicException;
use PHPStan\PhpDocParser\Ast\Attribute;
use PHPStan\PhpDocParser\Ast\Comment;
use PHPStan\PhpDocParser\Lexer\Lexer;
use function array_pop;
Expand Down Expand Up @@ -232,8 +233,18 @@ public function skip新建LineTokens(): void
public function skip新建LineTokensAndConsumeComments(): void
{
if ($this->currentTokenType() === Lexer::TOKEN_COMMENT) {
$this->comments[] = new Comment($this->currentTokenValue(), $this->currentTokenLine(), $this->currentTokenIndex());
$startLine = $this->currentTokenLine();
$startIndex = $this->currentTokenIndex();
$text = $this->currentTokenValue();

$this->next();

$c = new Comment($text);
$c->setAttribute(Attribute::START_LINE, $startLine);
$c->setAttribute(Attribute::START_INDEX, $startIndex);
$c->setAttribute(Attribute::END_LINE, $this->currentTokenLine());
$c->setAttribute(Attribute::END_INDEX, $this->currentTokenIndex());
$this->comments[] = $c;
}

if (!$this->isCurrentTokenType(Lexer::TOKEN_PHPDOC_EOL)) {
Expand All @@ -246,8 +257,18 @@ public function skip新建LineTokensAndConsumeComments(): void
continue;
}

$this->comments[] = new Comment($this->currentTokenValue(), $this->currentTokenLine(), $this->currentTokenIndex());
$startLine = $this->currentTokenLine();
$startIndex = $this->currentTokenIndex();
$text = $this->currentTokenValue();

$this->next();

$c = new Comment($text);
$c->setAttribute(Attribute::START_LINE, $startLine);
$c->setAttribute(Attribute::START_INDEX, $startIndex);
$c->setAttribute(Attribute::END_LINE, $this->currentTokenLine());
$c->setAttribute(Attribute::END_INDEX, $this->currentTokenIndex());
$this->comments[] = $c;
} while ($found新建Line === true);
}

Expand Down
Loading