Total Complexity | 12 |
Total Lines | 67 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 4 | ||
Bugs | 1 | Features | 0 |
1 | <?php |
||
9 | abstract class Comment implements Stringable, CommentTypeInterface, CommentConstantsInterface |
||
10 | { |
||
11 | protected bool $exceedThreshold = false; |
||
12 | |||
13 | 3 | public function hasExceededThreshold(): bool |
|
14 | { |
||
15 | 3 | return $this->exceedThreshold; |
|
16 | } |
||
17 | |||
18 | 14 | public function matchesPattern(string $token): bool |
|
21 | } |
||
22 | |||
23 | 1 | public function __toString(): string |
|
24 | { |
||
25 | 1 | return $this->getName(); |
|
26 | } |
||
27 | |||
28 | /** |
||
29 | * @param int $count |
||
30 | * @param array<string, float> $thresholds |
||
31 | * |
||
32 | * @return string |
||
33 | */ |
||
34 | 8 | public function getStatColor(int $count, array $thresholds): string |
|
35 | { |
||
36 | 8 | if (!isset($thresholds[$this->getName()])) { |
|
37 | 6 | return 'white'; |
|
38 | } |
||
39 | 2 | if ($this->isWithinThreshold($count, $thresholds)) { |
|
40 | 1 | return 'green'; |
|
41 | } |
||
42 | 1 | $this->exceedThreshold = true; |
|
43 | 1 | return 'red'; |
|
44 | } |
||
45 | |||
46 | /** @param array<string, float> $thresholds */ |
||
47 | 12 | protected function isWithinThreshold(int $count, array $thresholds): bool |
|
48 | { |
||
49 | 12 | $comparisonValue = $thresholds[static::NAME]; |
|
50 | |||
51 | 12 | if (static::COMPARISON_TYPE === '>=') { |
|
|
|||
52 | 4 | return $count >= $comparisonValue; |
|
53 | } |
||
54 | |||
55 | 8 | return $count <= $comparisonValue; |
|
56 | } |
||
57 | |||
58 | 14 | public function getPattern(): string |
|
59 | { |
||
60 | 14 | return static::PATTERN; |
|
61 | } |
||
62 | |||
63 | 5 | public function getColor(): string |
|
64 | { |
||
65 | 5 | return static::COLOR; |
|
66 | } |
||
67 | |||
68 | 7 | public function getWeight(): float |
|
69 | { |
||
70 | 7 | return static::WEIGHT; |
|
71 | } |
||
72 | |||
73 | 11 | public function getName(): string |
|
76 | } |
||
77 | } |
||
78 |