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

fractalzombie / frzb-metrics-power / 8479488191

29 Mar 2024 09:31AM UTC coverage: 92.417%. Remained the same
8479488191

push

github

fractalzombie
[MetricsPower] Refactoring for ContextExtractors and ContextExtractorLocator

51 of 55 new or added lines in 13 files covered. (92.73%)

1 existing line in 1 file now uncovered.

195 of 211 relevant lines covered (92.42%)

6.89 hits per line

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

75.0
/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): ?Metrical
38
    {
39
        return ArrayList::collect(AttributeHelper::getAttributes($target, Metrical::class))->firstElement()->get();
22✔
40
    }
41

42
    /** @return array<OptionsInterface> */
43
    public static function getOptions(object|string $target): array
44
    {
45
        return ArrayList::collect(self::getMetrical($target)?->options ?? [])
16✔
46
            ->toList();
16✔
47
    }
48

49
    public static function getFirstOptions(object|string $target): ?OptionsInterface
50
    {
51
        return ArrayList::collect(self::getOptions($target))
16✔
52
            ->firstElement()
16✔
53
            ->getOrElse(new LoggerOptions());
16✔
54
    }
55

56
    public static function getCounterName(PrometheusOptions $options): string
57
    {
UNCOV
58
        return str_replace('-', '_', "{$options->topic}-{$options->name}");
×
59
    }
60
}
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