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

fractalzombie / frzb-metrics-power / 8449913782

27 Mar 2024 10:01AM UTC coverage: 79.904%. Remained the same
8449913782

push

github

fractalzombie
[MetricsPower] Added unit and feature tests, Added LoggerOptions attribute

23 of 25 new or added lines in 11 files covered. (92.0%)

3 existing lines in 1 file now uncovered.

167 of 209 relevant lines covered (79.9%)

6.47 hits per line

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

71.43
/Helper/AttributeHelper.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 Fp\Functional\Option\Option;
20
use FRZB\Component\MetricsPower\Traits\WithPrivateEmptyConstructor;
21
use JetBrains\PhpStorm\Immutable;
22

23
/** @internal */
24
#[Immutable]
25
final class AttributeHelper
26
{
27
    use WithPrivateEmptyConstructor;
28

29
    public static function hasAttribute(object|string $target, string $attributeClass): bool
30
    {
31
        return !empty(self::getReflectionAttributes($target, $attributeClass));
×
32
    }
33

34
    /**
35
     * @template T
36
     *
37
     * @param class-string<T> $attributeClass
38
     *
39
     * @return null|T
40
     */
41
    public static function getAttribute(object|string $target, string $attributeClass): ?object
42
    {
43
        return ArrayList::collect(self::getAttributes($target, $attributeClass))
×
44
            ->firstElement()
×
NEW
45
            ->get();
×
46
    }
47

48
    /**
49
     * @template T
50
     *
51
     * @param class-string<T> $attributeClass
52
     *
53
     * @return array<T>
54
     */
55
    public static function getAttributes(object|string $target, string $attributeClass): array
56
    {
57
        return ArrayList::collect(self::getReflectionAttributes($target, $attributeClass))
9✔
58
            ->map(static fn (\ReflectionAttribute $a) => $a->newInstance())
9✔
59
            ->toList();
9✔
60
    }
61

62
    /**
63
     * @template T
64
     *
65
     * @param class-string<T> $attributeClass
66
     *
67
     * @return array<\ReflectionAttribute<T>>
68
     */
69
    public static function getReflectionAttributes(object|string $target, string $attributeClass): array
70
    {
71
        return Option::fromNullable(ClassHelper::getReflectionClass($target))
9✔
72
            ->map(
9✔
73
                static fn (\ReflectionClass $rClass) => Option::fromNullable(ClassHelper::getParentReflectionClass($rClass))
9✔
74
                    ->map(static fn (\ReflectionClass $rClass) => [...ClassHelper::getReflectionAttributes($rClass, $attributeClass), ...self::getReflectionAttributes($rClass, $attributeClass)])
9✔
75
                    ->getOrElse(ClassHelper::getReflectionAttributes($rClass, $attributeClass))
9✔
76
            )
9✔
77
            ->getOrElse([]);
9✔
78
    }
79
}
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