|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace TypeLang\PhpDoc\DocBlock\Tag\PhanFileSuppressTag; |
| 6 | + |
| 7 | +use TypeLang\PhpDoc\DocBlock\Combinator\DescriptionCombinator; |
| 8 | +use TypeLang\PhpDoc\DocBlock\Combinator\IssueNameCombinator; |
| 9 | +use TypeLang\PhpDoc\DocBlock\Description\DescriptionInterface; |
| 10 | +use TypeLang\PhpDoc\DocBlock\TagDefinition\Spec; |
| 11 | +use TypeLang\PhpDoc\DocBlock\TagDefinition\TagDefinition; |
| 12 | +use TypeLang\PhpDoc\DocBlock\TagDefinition\TagPayload; |
| 13 | +use TypeLang\PhpDoc\DocBlock\TagDefinition\TagPlacement; |
| 14 | + |
| 15 | +/** |
| 16 | + * The `@phan-file-suppress` tag silences the listed issue types for the |
| 17 | + * whole file it appears in, rather than just a single element or line. |
| 18 | + * |
| 19 | + * ``` |
| 20 | + * "@phan-file-suppress" <IssueName> { "," <IssueName> } [ <Description> ] |
| 21 | + * ``` |
| 22 | + */ |
| 23 | +final class PhanFileSuppressTagDefinition extends TagDefinition |
| 24 | +{ |
| 25 | + public const string NAME = 'phan-file-suppress'; |
| 26 | + |
| 27 | + public function __construct() |
| 28 | + { |
| 29 | + parent::__construct( |
| 30 | + name: self::NAME, |
| 31 | + spec: Spec::sequence( |
| 32 | + Spec::rule(IssueNameCombinator::NAME, 'issue'), |
| 33 | + Spec::repeat( |
| 34 | + Spec::sequence( |
| 35 | + Spec::literal(','), |
| 36 | + Spec::rule(IssueNameCombinator::NAME, 'issue'), |
| 37 | + ), |
| 38 | + ), |
| 39 | + Spec::maybe( |
| 40 | + Spec::rule(DescriptionCombinator::NAME, 'description'), |
| 41 | + ), |
| 42 | + ), |
| 43 | + placement: TagPlacement::Block, |
| 44 | + ); |
| 45 | + } |
| 46 | + |
| 47 | + public function create(string $name, TagPayload $result): PhanFileSuppressTag |
| 48 | + { |
| 49 | + /** @var non-empty-list<non-empty-string> $issues */ |
| 50 | + $issues = $result->getAll('issue'); |
| 51 | + |
| 52 | + /** @var DescriptionInterface|null $description */ |
| 53 | + $description = $result->find('description'); |
| 54 | + |
| 55 | + return new PhanFileSuppressTag($name, $issues, $description); |
| 56 | + } |
| 57 | +} |
0 commit comments