-
Notifications
You must be signed in to change notification settings - Fork 127
Fix issue when processing invalid tags #198
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace phpDocumentor\Reflection\DocBlock\Tags; | ||
|
|
||
| use phpDocumentor\Reflection\DocBlock\Tag; | ||
| use Throwable; | ||
|
|
||
| /** | ||
| * This class represents an exception during the tag creation | ||
| * | ||
| * Since the internals of the library are relaying on the correct syntax of a docblock | ||
| * we cannot simply throw exceptions at all time because the exceptions will break the creation of a | ||
| * docklock. Just silently ignore the exceptions is not an option because the user as an issue to fix. | ||
| * | ||
| * This tag holds that error information until a using application is able to display it. The object wil just behave | ||
| * like any normal tag. So the normal application flow will not break. | ||
| */ | ||
| final class InvalidTag implements Tag | ||
| { | ||
| /** @var string */ | ||
| private $name; | ||
|
|
||
| /** @var string */ | ||
| private $body; | ||
|
|
||
| /** @var Throwable|null */ | ||
| private $throwable; | ||
|
|
||
| private function __construct(string $name, string $body) | ||
| { | ||
| $this->name = $name; | ||
| $this->body = $body; | ||
| } | ||
|
|
||
| public function getException() : ?Throwable | ||
| { | ||
| return $this->throwable; | ||
| } | ||
|
|
||
| public function getName() : string | ||
| { | ||
| return $this->name; | ||
| } | ||
|
|
||
| /** | ||
| * @return self | ||
| * | ||
| * @inheritDoc | ||
| */ | ||
| public static function create(string $body, string $name = '') | ||
| { | ||
| return new self($name, $body); | ||
| } | ||
|
|
||
| public function withError(Throwable $exception) : self | ||
| { | ||
| $tag = new self($this->name, $this->body); | ||
| $tag->throwable = $exception; | ||
|
|
||
| return $tag; | ||
| } | ||
|
|
||
| public function render(?Formatter $formatter = null) : string | ||
| { | ||
| if ($formatter === null) { | ||
| $formatter = new Formatter\PassthroughFormatter(); | ||
| } | ||
|
|
||
| return $formatter->format($this); | ||
| } | ||
|
|
||
| public function __toString() : string | ||
| { | ||
| return $this->body; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace phpDocumentor\Reflection\DocBlock\Tags; | ||
|
|
||
| use Exception; | ||
| use PHPUnit\Framework\TestCase; | ||
|
|
||
| /** | ||
| * @coversDefaultClass \phpDocumentor\Reflection\DocBlock\Tags\InvalidTag | ||
| * @covers ::<private> | ||
| * @covers ::getName | ||
| * @covers ::render | ||
| * @covers ::getException | ||
| * @covers ::create | ||
| */ | ||
| final class InvalidTagTest extends TestCase | ||
| { | ||
| public function testCreationWithoutError() : void | ||
| { | ||
| $tag = InvalidTag::create('Body', 'name'); | ||
|
|
||
| self::assertSame('name', $tag->getName()); | ||
| self::assertSame('@name Body', $tag->render()); | ||
| self::assertNull($tag->getException()); | ||
| } | ||
|
|
||
| /** | ||
| * @covers ::withError | ||
| */ | ||
| public function testCreationWithError() : void | ||
| { | ||
| $exception = new Exception(); | ||
| $tag = InvalidTag::create('Body', 'name')->withError($exception); | ||
|
|
||
| self::assertSame('name', $tag->getName()); | ||
| self::assertSame('@name Body', $tag->render()); | ||
| self::assertSame($exception, $tag->getException()); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.