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

SimplePhpBaselineStorage::setComments()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

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