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