Passed
Push — main ( 2bf89b...450136 )
by mikhail
03:21
created

SimplePhpBaselineStorage   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 15
dl 0
loc 30
ccs 0
cts 16
cp 0
rs 10
c 1
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setComments() 0 9 2
A init() 0 7 2
A filterComments() 0 5 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SavinMikhail\CommentsDensity\Baseline\Storage;
6
7
use SavinMikhail\CommentsDensity\DTO\Output\CommentDTO;
0 ignored issues
show
Bug introduced by
The type SavinMikhail\CommentsDensity\DTO\Output\CommentDTO was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
9
final class SimplePhpBaselineStorage implements BaselineStorageInterface
10
{
11
    private string $path;
12
    private array $baselineData = [];
13
14
    public function init(string $path): void
15
    {
16
        $this->path = $path;
17
        if (!file_exists($path)) {
18
            file_put_contents($path, "<?php return [];");
19
        }
20
        $this->baselineData = include $path;
21
    }
22
23
    public function setComments(array $comments): void
24
    {
25
        foreach ($comments as $comment) {
26
            $this->baselineData[$comment->file . ':' . $comment->line] = [
27
                'comment' => $comment->content,
28
                'type' => $comment->commentType,
29
            ];
30
        }
31
        file_put_contents($this->path, "<?php return " . var_export($this->baselineData, true) . ";");
32
    }
33
34
    public function filterComments(array $comments): array
35
    {
36
        return array_filter(
37
            $comments,
38
            fn(CommentDTO $comment) => !isset($this->baselineData[$comment->file . ':' . $comment->line])
39
        );
40
    }
41
}
42