• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

php-bug-catcher / bug-catcher / 11242549949

08 Oct 2024 07:41PM UTC coverage: 88.73% (+1.9%) from 86.783%
11242549949

push

github

tito10047
add more tests and fixed RecordPing.php

3 of 3 new or added lines in 1 file covered. (100.0%)

1 existing line in 1 file now uncovered.

866 of 976 relevant lines covered (88.73%)

14.12 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

97.06
/src/DTO/NotifierStatus.php
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: Jozef Môstka
5
 * Date: 7. 6. 2024
6
 * Time: 18:07
7
 */
8
namespace BugCatcher\DTO;
9

10
use BugCatcher\Entity\Project;
11
use BugCatcher\Enum\Importance;
12

13
final class NotifierStatus
14
{
15

16
        /** @var array<Importance, Importance> */
17
        private array $importances = [];
18
        private array $increments = [];
19

20
        /**
21
         * @param Importance[] $importances
22
         */
23
        public function __construct(
24
                public readonly Project $project
25
        ) {}
14✔
26

27

28
        public function levelUp(Importance $group): void {
29
                if (!array_key_exists($group->value, $this->importances)) {
5✔
30
                        $this->importances[$group->value] = Importance::min();
5✔
31
                }
32
                $all = Importance::all();
5✔
33
                foreach ($all as $key => $value) {
5✔
34
                        if ($value === $this->importances[$group->value] && $key < count($all) - 1) {
5✔
35
                                $this->importances[$group->value] = $all[$key + 1];
5✔
36

37
                                return;
5✔
38
                        }
39
                }
40
        }
41

42
        public function incrementImportance(Importance $group, int $importance, int $topImportance = 10): void {
43
                if (!$importance) {
9✔
UNCOV
44
                        return;
×
45
                }
46
                if (!array_key_exists($group->value, $this->increments)) {
9✔
47
                        $this->increments[$group->value] = 0;
9✔
48
                }
49
                $max = count(Importance::all()) - 1;
9✔
50
                $ratio            = $max / $topImportance;
9✔
51
                $newImportance = $importance * $ratio;
9✔
52
                $newImportance = $this->increments[$group->value] += $newImportance;
9✔
53
                $this->setImportance($group, $newImportance, $max);
9✔
54
        }
55

56
        public function setImportance(Importance $group, float $importance, float $topImportance = 10): void {
57
                $max                              = count(Importance::all()) - 1;
9✔
58
                $ratio                            = $max / $topImportance;
9✔
59
                $importance                       = $importance * $ratio;
9✔
60
                $importance                       = min($importance, $max);
9✔
61
                $importance                       = max($importance, 1);
9✔
62
                $importance                       = round($importance);
9✔
63
                $this->importances[$group->value] = Importance::all()[$importance];
9✔
64
        }
65

66
        public function ok(Importance $group): void {
67
        $this->importances[$group->value] = Importance::min();
3✔
68
        }
69

70
        public function danger(Importance $group): void {
71
        $this->importances[$group->value] = Importance::max();
1✔
72
        }
73

74
        public function getImportance(): Importance {
75
        $all = array_map(fn(Importance $importance) => $importance->value, Importance::all());
14✔
76
        $importances = $this->importances;
14✔
77
        uksort($importances, function ($a, $b) use ($all) {
14✔
78
                        return array_search($b, $all) <=> array_search($a, $all);
2✔
79
                });
14✔
80
        if ($importance = current($importances)) {
14✔
81
            return $importance;
14✔
82
        }
83
        return Importance::Normal;
1✔
84
        }
85
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc