Passed
Push — main ( b13408...5e6da4 )
by mikhail
03:02
created

CDS::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 0
c 1
b 0
f 0
dl 0
loc 2
ccs 0
cts 1
cp 0
rs 10
cc 1
nc 1
nop 1
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SavinMikhail\CommentsDensity;
6
7
use SavinMikhail\CommentsDensity\DTO\Output\CdsDTO;
0 ignored issues
show
Bug introduced by
The type SavinMikhail\CommentsDensity\DTO\Output\CdsDTO 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 CDS
10
{
11
    private bool $exceedThreshold = false;
12
13
    public function __construct(private readonly array $thresholds)
14
    {
15
    }
16
17
    public function prepareCDS(float $cds): CdsDTO
18
    {
19
        $cds = round($cds, 2);
20
        return new CdsDTO(
21
            $cds,
22
            $this->getColorForCDS($cds),
23
        );
24
    }
25
26
    private function getColorForCDS(float $cds): string
27
    {
28
        if (! isset($this->thresholds['CDS'])) {
29
            return 'white';
30
        }
31
        if ($cds >= $this->thresholds['CDS']) {
32
            return 'green';
33
        }
34
        $this->exceedThreshold = true;
35
        return 'red';
36
    }
37
38
    public function hasExceededThreshold(): bool
39
    {
40
        return $this->exceedThreshold;
41
    }
42
}
43