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

68publishers / smart-nette-component / 3671567024

pending completion
3671567024

Pull #3

github

GitHub
Merge 8c2bf16fd into d93ee51a5
Pull Request #3: WIP: v1

389 of 389 new or added lines in 24 files covered. (100.0%)

408 of 419 relevant lines covered (97.37%)

0.97 hits per line

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

95.83
/src/Reader/StaticAttributeReader.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace SixtyEightPublishers\SmartNetteComponent\Reader;
6

7
use SixtyEightPublishers\SmartNetteComponent\Attribute\AttributeInterface;
8
use function array_map;
9
use function array_merge;
10
use function array_reverse;
11
use function array_key_exists;
12

13
final class StaticAttributeReader implements AttributeReaderInterface
14
{
15
        public function __construct(
1✔
16
                private readonly AttributesMap $map,
17
        ) {
18
        }
1✔
19

20
        public function getClassAttributes(string $classname, ?string $stopBeforeParent = null): array
1✔
21
        {
22
                return $this->doFindAttributes($classname, null, $stopBeforeParent);
1✔
23
        }
24

25
        public function getMethodAttributes(string $classname, string $method, ?string $stopBeforeParent = null): array
1✔
26
        {
27
                return $this->doFindAttributes($classname, $method, $stopBeforeParent);
1✔
28
        }
29

30
        /**
31
         * @param class-string $classname
32
         *
33
         * @return array<AttributeInfo>
34
         */
35
        public function doFindAttributes(string $classname, ?string $method, ?string $stopBeforeParent): array
1✔
36
        {
37
                if (!array_key_exists($classname, $this->map->classHierarchy)) {
1✔
38
                        return [];
×
39
                }
40

41
                $current = $classname;
1✔
42
                $attributes = [];
1✔
43

44
                do {
45
                        $key = $current . '::' . ($method ?? 'class');
1✔
46

47
                        if (isset($this->map->attributes[$key])) {
1✔
48
                                $attributes[] = array_map(
1✔
49
                                        static fn (AttributeInterface $attribute): AttributeInfo => new AttributeInfo($current, $attribute),
1✔
50
                                        $this->map->attributes[$key]
1✔
51
                                );
52
                        }
53

54
                        if ($current === $stopBeforeParent) {
1✔
55
                                $current = false;
1✔
56
                        }
57

58
                        if ($current) {
1✔
59
                                $current = $this->map->classHierarchy[$current];
1✔
60

61
                                if ($current === $stopBeforeParent) {
1✔
62
                                        $current = false;
1✔
63
                                }
64
                        }
65
                } while ($current);
1✔
66

67
                return array_merge(...array_reverse($attributes));
1✔
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

© 2025 Coveralls, Inc