Passed
Push — main ( fcc13f...628042 )
by mikhail
02:55
created

CommentFactory   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Test Coverage

Coverage 94.44%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 7
eloc 16
c 1
b 0
f 1
dl 0
loc 34
ccs 17
cts 18
cp 0.9444
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A classifyComment() 0 8 3
A getCommentType() 0 8 3
A __construct() 0 8 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SavinMikhail\CommentsDensity\Comments;
6
7
class CommentFactory
8
{
9
    /** @var array<array-key, CommentTypeInterface> */
0 ignored issues
show
Documentation Bug introduced by
The doc comment array<array-key, CommentTypeInterface> at position 2 could not be parsed: Unknown type name 'array-key' at position 2 in array<array-key, CommentTypeInterface>.
Loading history...
10
    private array $commentTypes;
11
12 13
    public function __construct()
13
    {
14 13
        $this->commentTypes =  [
15 13
            new TodoComment(),
16 13
            new FixMeComment(),
17 13
            new RegularComment(),
18 13
            new LicenseComment(),
19 13
            new DocBlockComment(),
20 13
        ];
21
    }
22
23 2
    public function getCommentType(string $name): ?CommentTypeInterface
24
    {
25 2
        foreach ($this->commentTypes as $commentType) {
26 2
            if ($commentType->getName() === $name) {
27 2
                return $commentType;
28
            }
29
        }
30 2
        return null;
31
    }
32
33 10
    public function classifyComment(string $token): ?CommentTypeInterface
34
    {
35 10
        foreach ($this->commentTypes as $commentType) {
36 10
            if ($commentType->matchesPattern($token)) {
37 10
                return $commentType;
38
            }
39
        }
40
        return null;
41
    }
42
}
43