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

php-bug-catcher / bug-catcher / 11174163337

04 Oct 2024 04:47AM UTC coverage: 86.701%. Remained the same
11174163337

push

github

tito10047
Fix missing archive it parameter

841 of 970 relevant lines covered (86.7%)

13.51 hits per line

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

61.9
/src/EventSubscriber/NotifyCalculateListener.php
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: Jozef Môstka
5
 * Date: 26. 7. 2024
6
 * Time: 16:08
7
 */
8
namespace BugCatcher\EventSubscriber;
9

10
use BugCatcher\DTO\NotifierStatus;
11
use BugCatcher\Entity\Project;
12
use BugCatcher\Enum\Importance;
13
use BugCatcher\Event\NotifyCalculateEvent;
14
use BugCatcher\Repository\RecordRepository;
15
use Symfony\Component\EventDispatcher\Attribute\AsEventListener;
16

17
#[AsEventListener]
18
final class NotifyCalculateListener
19
{
20

21

22
        public function __construct(
23
                private readonly RecordRepository $recordRepo,
24
        ) {}
8✔
25

26
        public function __invoke(NotifyCalculateEvent $event): void {
27

28

29
                $projects = array_filter($event->notifier->getProjects()->toArray(), fn(Project $p) => $p->isEnabled());
8✔
30
                $projects = array_map(fn(Project $p) => $p->getId()->toBinary(), $projects);
8✔
31

32
                switch ($event->notifier->getComponent()) {
8✔
33
                        case 'project-error-count':
8✔
34
                                $this->calculateProjectErrors($event, $projects);
×
35
                                break;
×
36
                        case 'same-error-count':
8✔
37
                                $this->calculateSameErrors($event, $projects);
8✔
38
                                break;
8✔
39
                }
40
        }
41

42
        private function calculateProjectErrors(NotifyCalculateEvent $event, array $projects): void {
43

44

45
                $records = $this->recordRepo->createQueryBuilder("record")
×
46
//                                ->from(Record::class, "record")
×
47
                        ->join("record.project", "project")
×
48
                        ->addSelect("COUNT(record) as count")
×
49
                        ->where("record.status like :status")
×
50
                        ->andWhere("record.project IN (:projects)")
×
51
                        ->setParameter("status", 'new')
×
52
                        ->setParameter('projects', $projects)
×
53
                        ->groupBy("record.project")
×
54
                        ->getQuery()->enableResultCache(10)->getResult();
×
55
                foreach ($records as $record) {
×
56
                        $status = new NotifierStatus($record[0]->getProject());
×
57
                        $event->addStatus($status);
×
58
                        $status->incrementImportance(Importance::Normal, $record['count'], $event->notifier->getThreshold());
×
59
                }
60
        }
61

62
        private function calculateSameErrors(NotifyCalculateEvent $event, array $projects): void {
63
                $records = $this->recordRepo->createQueryBuilder("record")
8✔
64
//                        ->from(Record::class, "record")
8✔
65
                        ->addSelect("COUNT(record) as count")
8✔
66
                        ->where("record.status like :status")
8✔
67
                        ->andWhere("record.project IN (:projects)")
8✔
68
                        ->setParameter("status", 'new')
8✔
69
                        ->setParameter('projects', $projects)
8✔
70
                        ->groupBy("record.project", "record.hash")
8✔
71
                        ->getQuery()->enableResultCache(10)->getResult();
8✔
72
                $statuses = [];
8✔
73
                foreach ($records as $record) {
8✔
74
                        $key                = $record[0]->getProject()->getId()->__toString();
8✔
75
                        $status             = $statuses[$key]??null;
8✔
76
                        if (!$status) {
8✔
77
                                $status = new NotifierStatus($record[0]->getProject());
8✔
78
                                $statuses[$key] = $status;
8✔
79
                                $event->addStatus($status);
8✔
80
                        }
81
                        $status->incrementImportance(Importance::High, $record['count'], $event->notifier->getThreshold());
8✔
82
                }
83
        }
84

85

86
}
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