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

diego-ninja / granite / 16608963009

29 Jul 2025 10:37PM UTC coverage: 50.423%. First build
16608963009

Pull #5

github

web-flow
Merge 43d8840d7 into 6a6caca51
Pull Request #5: code: adds phpstan level max, pint with per and github actions

321 of 632 new or added lines in 77 files covered. (50.79%)

1132 of 2245 relevant lines covered (50.42%)

9.88 hits per line

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

64.71
/src/Mapping/Core/AttributeProcessor.php
1
<?php
2

3
namespace Ninja\Granite\Mapping\Core;
4

5
use Ninja\Granite\Mapping\Attributes\Ignore;
6
use Ninja\Granite\Mapping\Attributes\MapCollection;
7
use Ninja\Granite\Mapping\Attributes\MapDefault;
8
use Ninja\Granite\Mapping\Attributes\MapFrom;
9
use Ninja\Granite\Mapping\Attributes\MapWhen;
10
use Ninja\Granite\Mapping\Attributes\MapWith;
11
use ReflectionAttribute;
12
use ReflectionProperty;
13

14
final readonly class AttributeProcessor
15
{
16
    public function processProperty(ReflectionProperty $property): array
13✔
17
    {
18
        $config = [
13✔
19
            'source' => $property->getName(),
13✔
20
            'transformer' => null,
13✔
21
            'condition' => null,
13✔
22
            'default' => null,
13✔
23
            'hasDefault' => false,
13✔
24
            'ignore' => false,
13✔
25
        ];
13✔
26

27
        $attributes = $property->getAttributes();
13✔
28

29
        foreach ($attributes as $attribute) {
13✔
30
            $this->processAttribute($attribute, $config);
4✔
31
        }
32

33
        return $config;
13✔
34
    }
35

36
    private function processAttribute(ReflectionAttribute $attribute, array &$config): void
4✔
37
    {
38
        $attrName = $attribute->getName();
4✔
39
        $attrInstance = $attribute->newInstance();
4✔
40

41
        switch ($attrName) {
42
            case Ignore::class:
43
                $config['ignore'] = true;
×
44
                break;
×
45

46
            case MapFrom::class:
47
                if ($attrInstance instanceof MapFrom) {
2✔
48
                    $config['source'] = $attrInstance->source;
2✔
49
                }
50
                break;
2✔
51

52
            case MapWith::class:
53
                if ($attrInstance instanceof MapWith) {
3✔
54
                    $config['transformer'] = $attrInstance->transformer;
3✔
55
                }
56
                break;
3✔
57

58
            case MapWhen::class:
NEW
59
                if ($attrInstance instanceof MapWhen) {
×
NEW
60
                    $config['condition'] = $attrInstance->condition;
×
61
                }
62
                break;
×
63

64
            case MapDefault::class:
NEW
65
                if ($attrInstance instanceof MapDefault) {
×
NEW
66
                    $config['default'] = $attrInstance->value;
×
NEW
67
                    $config['hasDefault'] = true;
×
68
                }
69
                break;
×
70

71
            case MapCollection::class:
NEW
72
                if ($attrInstance instanceof MapCollection) {
×
NEW
73
                    $config['transformer'] = $attrInstance->createTransformer(null);
×
74
                }
75
                break;
×
76
        }
77
    }
78
}
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