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

daycry / jobs / 24850441053

23 Apr 2026 05:54PM UTC coverage: 52.404% (-1.5%) from 53.938%
24850441053

push

github

daycry
Fixes

104 of 219 new or added lines in 42 files covered. (47.49%)

14 existing lines in 9 files now uncovered.

1210 of 2309 relevant lines covered (52.4%)

4.37 hits per line

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

89.47
/src/Metrics/InMemoryMetricsCollector.php
1
<?php
2

3
declare(strict_types=1);
4

5
/**
6
 * This file is part of Daycry Queues.
7
 *
8
 * (c) Daycry <daycry9@proton.me>
9
 *
10
 * For the full copyright and license information, please view
11
 * the LICENSE file that was distributed with this source code.
12
 */
13

14
namespace Daycry\Jobs\Metrics;
15

16
final class InMemoryMetricsCollector implements MetricsCollectorInterface
17
{
18
    private array $counters   = [];
19
    private array $histograms = [];
20

21
    public function increment(string $counter, int $value = 1, array $labels = []): void
22
    {
23
        $key                  = $this->key($counter, $labels);
13✔
24
        $this->counters[$key] = ($this->counters[$key] ?? 0) + $value;
13✔
25
    }
26

27
    public function observe(string $metric, float $value, array $labels = []): void
28
    {
29
        $key    = $this->key($metric, $labels);
8✔
30
        $bucket = $this->histograms[$key] ?? ['count' => 0, 'sum' => 0.0, 'min' => null, 'max' => null];
8✔
31
        $bucket['count']++;
8✔
32
        $bucket['sum'] += $value;
8✔
33
        $bucket['min']          = $bucket['min'] === null ? $value : min($bucket['min'], $value);
8✔
34
        $bucket['max']          = $bucket['max'] === null ? $value : max($bucket['max'], $value);
8✔
35
        $this->histograms[$key] = $bucket;
8✔
36
    }
37

38
    public function getSnapshot(): array
39
    {
40
        return [
11✔
41
            'counters'   => $this->counters,
11✔
42
            'histograms' => $this->histograms,
11✔
43
        ];
11✔
44
    }
45

46
    /**
47
     * Reset all collected metrics to free memory in long-running workers.
48
     */
49
    public function reset(): void
50
    {
NEW
51
        $this->counters   = [];
×
NEW
52
        $this->histograms = [];
×
53
    }
54

55
    private function key(string $name, array $labels): string
56
    {
57
        if ($labels === []) {
13✔
58
            return $name;
1✔
59
        }
60
        ksort($labels);
13✔
61

62
        return $name . '|' . http_build_query($labels, '', ';');
13✔
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

© 2026 Coveralls, Inc