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

php-bug-catcher / bug-catcher / 10990845772

23 Sep 2024 08:50AM UTC coverage: 78.669% (+1.4%) from 77.225%
10990845772

push

github

tito10047
extracted Transaction.php to package

4 of 29 new or added lines in 1 file covered. (13.79%)

804 of 1022 relevant lines covered (78.67%)

11.64 hits per line

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

13.79
/src/Service/RecordLogWithholder.php
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: Jozef Môstka
5
 * Date: 14. 7. 2024
6
 * Time: 21:06
7
 */
8

9
namespace BugCatcher\Service;
10

11
use BugCatcher\Entity\RecordLog;
12
use BugCatcher\Repository\RecordLogRepository;
13
use BugCatcher\Repository\RecordLogWithholderRepository;
14
use Doctrine\ORM\EntityManagerInterface;
15

16
readonly final class RecordLogWithholder
17
{
18

19

20
    public function __construct(
21
        private RecordLogRepository $logRepo,
22
        private RecordLogWithholderRepository $withholderRepo,
23
        private EntityManagerInterface $em,
24
    ) {
25
    }
25✔
26

27
    public function process(RecordLog $log): void
28
    {
29
        $withholders = $this->withholderRepo->findBy(["project" => $log->getProject()]);
10✔
30
        foreach ($withholders as $withholder) {
10✔
NEW
31
            $regex = $withholder->getRegex();
×
NEW
32
            if (!preg_match($regex, $log->getMessage())) {
×
NEW
33
                continue;
×
34
            }
NEW
35
            $status = "withheld-{$withholder->getId()}";
×
NEW
36
            $withholderLogs = $this->logRepo->findBy([
×
NEW
37
                "hash" => $log->calculateHash(),
×
NEW
38
                "status" => [$status, "new"],
×
NEW
39
                "project" => $log->getProject(),
×
NEW
40
            ], ["date" => "DESC"]);
×
NEW
41
            array_unshift($withholderLogs, $log);
×
NEW
42
            $log->setStatus($status);
×
NEW
43
            $start = $log->getDate()->getTimestamp();
×
NEW
44
            $count = 0;
×
NEW
45
            for ($i = 0; $i < count($withholderLogs); $i++) {
×
NEW
46
                $log = $withholderLogs[$i];
×
NEW
47
                $end = $log->getDate()->getTimestamp();
×
NEW
48
                $diff = $start - $end;
×
NEW
49
                if ($diff <= $withholder->getThresholdInterval()) {
×
NEW
50
                    $count++;
×
NEW
51
                    if ($count > $withholder->getThreshold() && $status !== "new") {
×
NEW
52
                        $status = "new";
×
NEW
53
                        $i = -1;
×
NEW
54
                        continue;
×
55
                    }
NEW
56
                    $log->setStatus($status);
×
57
                } else {
NEW
58
                    $log->setStatus($status == "new" ? "new" : "resolved-{$withholder->getId()}");
×
59
                }
60
            }
61
        }
62
        $this->em->flush();
10✔
63
    }
64
}
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