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

CDS   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
eloc 13
c 1
b 0
f 0
dl 0
loc 32
ccs 0
cts 17
cp 0
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 2 1
A prepareCDS() 0 6 1
A hasExceededThreshold() 0 3 1
A getColorForCDS() 0 10 3
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