| Total Complexity | 11 |
| Total Lines | 50 |
| Duplicated Lines | 0 % |
| Coverage | 95.83% |
| Changes | 4 | ||
| Bugs | 0 | Features | 1 |
| 1 | <?php |
||
| 11 | { |
||
| 12 | /** @var array<array-key, CommentTypeInterface> */ |
||
| 13 | private array $commentTypes; |
||
| 14 | |||
| 15 | /** |
||
| 16 | * @param string[] $allowedTypes |
||
| 17 | */ |
||
| 18 | 19 | public function __construct(private array $allowedTypes = []) |
|
| 19 | { |
||
| 20 | 19 | $this->commentTypes = [ |
|
| 21 | 19 | new TodoComment(), |
|
| 22 | 19 | new FixMeComment(), |
|
| 23 | 19 | new RegularComment(), |
|
| 24 | 19 | new LicenseComment(), |
|
| 25 | 19 | new DocBlockComment(), |
|
| 26 | 19 | ]; |
|
| 27 | } |
||
| 28 | |||
| 29 | 3 | public function getCommentTypes(): Generator |
|
| 30 | { |
||
| 31 | 3 | foreach ($this->commentTypes as $commentType) { |
|
| 32 | 3 | yield $commentType; |
|
| 33 | } |
||
| 34 | } |
||
| 35 | |||
| 36 | 7 | public function getCommentType(string $name): ?CommentTypeInterface |
|
| 37 | { |
||
| 38 | 7 | foreach ($this->commentTypes as $commentType) { |
|
| 39 | 7 | if ($commentType->getName() === $name) { |
|
| 40 | 7 | return $commentType; |
|
| 41 | } |
||
| 42 | } |
||
| 43 | 7 | return null; |
|
| 44 | } |
||
| 45 | |||
| 46 | 14 | public function classifyComment(string $token): ?CommentTypeInterface |
|
| 47 | { |
||
| 48 | 14 | foreach ($this->commentTypes as $commentType) { |
|
| 49 | 14 | if (! $commentType->matchesPattern($token)) { |
|
| 50 | 12 | continue; |
|
| 51 | } |
||
| 52 | if ( |
||
| 53 | 14 | empty($this->allowedTypes) |
|
| 54 | 14 | || in_array($commentType->getName(), $this->allowedTypes, true) |
|
| 55 | ) { |
||
| 56 | 14 | return $commentType; |
|
| 57 | } |
||
| 58 | } |
||
| 59 | return null; |
||
| 60 | } |
||
| 61 | } |
||
| 62 |