| Total Complexity | 12 |
| Total Lines | 67 |
| Duplicated Lines | 0 % |
| Coverage | 57.69% |
| 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 |
|
| 19 | { |
||
| 20 | 14 | return (bool) preg_match($this->getPattern(), $token); |
|
| 21 | } |
||
| 22 | |||
| 23 | public function __toString(): string |
||
| 26 | } |
||
| 27 | |||
| 28 | /** |
||
| 29 | * @param int $count |
||
| 30 | * @param array<string, float> $thresholds |
||
| 31 | * |
||
| 32 | * @return string |
||
| 33 | */ |
||
| 34 | 5 | public function getStatColor(int $count, array $thresholds): string |
|
| 35 | { |
||
| 36 | 5 | if (!isset($thresholds[$this->getName()])) { |
|
| 37 | 5 | return 'white'; |
|
| 38 | } |
||
| 39 | if ($this->isWithinThreshold($count, $thresholds)) { |
||
| 40 | return 'green'; |
||
| 41 | } |
||
| 42 | $this->exceedThreshold = true; |
||
| 43 | return 'red'; |
||
| 44 | } |
||
| 45 | |||
| 46 | /** @param array<string, float> $thresholds */ |
||
| 47 | protected function isWithinThreshold(int $count, array $thresholds): bool |
||
| 48 | { |
||
| 49 | $comparisonValue = $thresholds[static::NAME]; |
||
| 50 | |||
| 51 | if (static::COMPARISON_TYPE === '>=') { |
||
|
|
|||
| 52 | return $count >= $comparisonValue; |
||
| 53 | } |
||
| 54 | |||
| 55 | 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 | 7 | public function getName(): string |
|
| 76 | } |
||
| 77 | } |
||
| 78 |