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

fractalzombie / frzb-metrics-power / 8464240914

28 Mar 2024 08:06AM UTC coverage: 85.185% (-4.5%) from 89.706%
8464240914

push

github

fractalzombie
[MetricsPower] Added ContextExtractor for logger

79 of 98 new or added lines in 16 files covered. (80.61%)

1 existing line in 1 file now uncovered.

184 of 216 relevant lines covered (85.19%)

8.44 hits per line

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

84.62
/Helper/MetricalHelper.php
1
<?php
2

3
declare(strict_types=1);
4

5
/**
6
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
7
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
8
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
9
 *
10
 * Copyright (c) 2024 Mykhailo Shtanko fractalzombie@gmail.com
11
 *
12
 * For the full copyright and license information, please view the LICENSE.MD
13
 * file that was distributed with this source code.
14
 */
15

16
namespace FRZB\Component\MetricsPower\Helper;
17

18
use Fp\Collections\ArrayList;
19
use FRZB\Component\MetricsPower\Attribute\LoggerOptions;
20
use FRZB\Component\MetricsPower\Attribute\Metrical;
21
use FRZB\Component\MetricsPower\Attribute\OptionsInterface;
22
use FRZB\Component\MetricsPower\Attribute\PrometheusOptions;
23
use FRZB\Component\MetricsPower\Traits\WithPrivateEmptyConstructor;
24
use JetBrains\PhpStorm\Immutable;
25

26
/** @internal */
27
#[Immutable]
28
final class MetricalHelper
29
{
30
    use WithPrivateEmptyConstructor;
31

32
    public static function isMetrical(object|string $target): bool
33
    {
34
        return AttributeHelper::hasAttribute($target, Metrical::class);
×
35
    }
36

37
    public static function getMetrical(object|string $target): array
38
    {
39
        return AttributeHelper::getAttributes($target, Metrical::class);
15✔
40
    }
41

42
    public static function getFirstMetrical(object|string $target): ?Metrical
43
    {
44
        return ArrayList::collect(self::getMetrical($target))
9✔
45
            ->firstElement()
9✔
46
            ->get();
9✔
47
    }
48

49
    /** @return array<OptionsInterface> */
50
    public static function getOptions(object|string $target): array
51
    {
52
        return ArrayList::collect(self::getMetrical($target))
6✔
53
            ->map(static fn (Metrical $metrical) => $metrical->options)
6✔
54
            ->flatten()
6✔
55
            ->toList();
6✔
56
    }
57

58
    public static function getFirstOptions(object|string $target): ?OptionsInterface
59
    {
60
        return ArrayList::collect(self::getOptions($target))
6✔
61
            ->firstElement()
6✔
62
            ->getOrElse(fn () => new LoggerOptions());
6✔
63
    }
64

65
    public static function getCounterName(PrometheusOptions $options): string
66
    {
UNCOV
67
        return str_replace('-', '_', "{$options->topic}-{$options->name}");
×
68
    }
69
}
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