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

php-bug-catcher / reporter-bundle / 17046879263

18 Aug 2025 04:45PM UTC coverage: 63.971% (-0.2%) from 64.179%
17046879263

push

github

tito10047
add code to errors so you can track your errors

1 of 2 new or added lines in 1 file covered. (50.0%)

87 of 136 relevant lines covered (63.97%)

6.57 hits per line

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

92.0
/src/Service/BugCatcher.php
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: Jozef Môstka
5
 * Date: 12. 6. 2024
6
 * Time: 15:29
7
 */
8
namespace BugCatcher\Reporter\Service;
9

10
use BugCatcher\Reporter\Event\RecordWriteEvent;
11
use BugCatcher\Reporter\UrlCatcher\UriCatcherInterface;
12
use BugCatcher\Reporter\Writer\CollectCodeFrame;
13
use BugCatcher\Reporter\Writer\WriterInterface;
14
use Symfony\Component\EventDispatcher\EventDispatcher;
15
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
16
use Throwable;
17

18
class BugCatcher implements BugCatcherInterface {
19

20
        public function __construct(
21
                private readonly WriterInterface     $writer,
22
                private readonly UriCatcherInterface $uriCatcher,
23
        private readonly EventDispatcherInterface $eventDispatcher,
24
                private readonly string              $project,
25
                private readonly string              $minLevel
26
        ) {}
15✔
27

28
        public function log(array $data): void {
29
                if (!array_key_exists("projectCode", $data)) {
6✔
30
                        $data["projectCode"] = $this->project;
×
31
                }
32
        $event = $this->eventDispatcher->dispatch(new RecordWriteEvent($data));
6✔
33
        $this->writer->write($event->getData());
6✔
34
        }
35

36
        public function logRecord(string $message, int $level, ?string $requestUri = null, array $additional = []): void {
37
        $data = $additional + [
6✔
38
                "api_uri" => "/api/record_logs",
6✔
39
                "message" => substr($message, 0, 750),
6✔
40
                "level" => $level,
6✔
41
                "projectCode" => $this->project,
6✔
42
                "requestUri" => $requestUri ?? $this->uriCatcher->getUri(),
6✔
43
            ];
6✔
44
        $event = $this->eventDispatcher->dispatch(new RecordWriteEvent($data));
6✔
45
        $this->writer->write($event->getData());
6✔
46
        }
47

48
        public function logException(Throwable $throwable, int $level = 500, ?string $requestUri = null, ?string $meCode = null): void {
49

50
                $data = [
3✔
51
                        "api_uri" => "/api/record_log_traces",
3✔
52
                        "message" => substr($throwable->getMessage(), 0, 750),
3✔
53
                        "level"       => $level,
3✔
54
                        "projectCode" => $this->project,
3✔
55
                        "requestUri"  => $requestUri??$this->uriCatcher->getUri(),
3✔
56
                ];
3✔
57
                if ($meCode) {
3✔
NEW
58
                        $data["code"] = $meCode;
×
59
                }
60
        $event = $this->eventDispatcher->dispatch(new RecordWriteEvent($data, $throwable));
3✔
61
        $this->writer->write($event->getData());
3✔
62
        }
63
}
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

© 2026 Coveralls, Inc