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

CommentFactory::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 6
c 1
b 0
f 1
dl 0
loc 8
ccs 7
cts 7
cp 1
rs 10
cc 1
nc 1
nop 0
crap 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