• 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

20.37
/src/Mapping/MapperConfig.php
1
<?php
2

3
namespace Ninja\Granite\Mapping;
4

5
use InvalidArgumentException;
6
use Ninja\Granite\Enums\CacheType;
7
use Ninja\Granite\Mapping\Contracts\NamingConvention;
8

9
final readonly class MapperConfig
10
{
11
    private function __construct(
10✔
12
        public CacheType $cacheType = CacheType::Memory,
13
        public bool $warmupCache = true,
14
        public bool $useConventions = false,
15
        public float $conventionThreshold = 0.8,
16
        public array $profiles = [],
17
        public array $conventions = [],
18
    ) {}
10✔
19

20
    public static function default(): self
×
21
    {
22
        return new self();
×
23
    }
24

25
    public static function create(): self
10✔
26
    {
27
        return new self();
10✔
28
    }
29

30
    // =================
31
    // Preset Configurations
32
    // =================
33

NEW
34
    public static function forDevelopment(): self
×
35
    {
NEW
36
        return self::create()
×
NEW
37
            ->withMemoryCache()
×
NEW
38
            ->withoutWarmup()
×
NEW
39
            ->withConventions(true, 0.7);
×
40
    }
41

NEW
42
    public static function forProduction(): self
×
43
    {
NEW
44
        return self::create()
×
NEW
45
            ->withSharedCache()
×
NEW
46
            ->withWarmup()
×
NEW
47
            ->withConventions();
×
48
    }
49

NEW
50
    public static function forTesting(): self
×
51
    {
NEW
52
        return self::create()
×
NEW
53
            ->withMemoryCache()
×
NEW
54
            ->withoutWarmup()
×
NEW
55
            ->withoutConventions();
×
56
    }
57

NEW
58
    public static function minimal(): self
×
59
    {
NEW
60
        return self::create()
×
NEW
61
            ->withMemoryCache()
×
NEW
62
            ->withoutWarmup()
×
NEW
63
            ->withoutConventions();
×
64
    }
65

66
    // =================
67
    // Cache Configuration
68
    // =================
69

70
    public function withCacheType(CacheType $type): self
×
71
    {
72
        return new self(
×
73
            $type,
×
74
            $this->warmupCache,
×
75
            $this->useConventions,
×
76
            $this->conventionThreshold,
×
77
            $this->profiles,
×
NEW
78
            $this->conventions,
×
79
        );
×
80
    }
81

82
    public function withMemoryCache(): self
×
83
    {
84
        return $this->withCacheType(CacheType::Memory);
×
85
    }
86

87
    public function withSharedCache(): self
×
88
    {
89
        return $this->withCacheType(CacheType::Shared);
×
90
    }
91

92
    public function withPersistentCache(): self
×
93
    {
94
        return $this->withCacheType(CacheType::Persistent);
×
95
    }
96

97
    public function withWarmup(bool $enabled = true): self
×
98
    {
99
        return new self(
×
100
            $this->cacheType,
×
101
            $enabled,
×
102
            $this->useConventions,
×
103
            $this->conventionThreshold,
×
104
            $this->profiles,
×
NEW
105
            $this->conventions,
×
106
        );
×
107
    }
108

109
    public function withoutWarmup(): self
×
110
    {
111
        return $this->withWarmup(false);
×
112
    }
113

114
    // ======================
115
    // Convention Configuration
116
    // ======================
117

118
    public function withConventions(bool $enabled = true, float $threshold = 0.8): self
×
119
    {
120
        return new self(
×
121
            $this->cacheType,
×
122
            $this->warmupCache,
×
123
            $enabled,
×
124
            $threshold,
×
125
            $this->profiles,
×
NEW
126
            $this->conventions,
×
127
        );
×
128
    }
129

130
    public function withoutConventions(): self
×
131
    {
132
        return $this->withConventions(false);
×
133
    }
134

135
    public function withConventionThreshold(float $threshold): self
×
136
    {
137
        return new self(
×
138
            $this->cacheType,
×
139
            $this->warmupCache,
×
140
            $this->useConventions,
×
141
            max(0.0, min(1.0, $threshold)),
×
142
            $this->profiles,
×
NEW
143
            $this->conventions,
×
144
        );
×
145
    }
146

147
    public function addConvention(NamingConvention $convention): self
×
148
    {
149
        return new self(
×
150
            $this->cacheType,
×
151
            $this->warmupCache,
×
152
            $this->useConventions,
×
153
            $this->conventionThreshold,
×
154
            $this->profiles,
×
NEW
155
            [...$this->conventions, $convention],
×
156
        );
×
157
    }
158

159
    // ==================
160
    // Profile Configuration
161
    // ==================
162

163
    public function withProfile(MappingProfile $profile): self
9✔
164
    {
165
        return new self(
9✔
166
            $this->cacheType,
9✔
167
            $this->warmupCache,
9✔
168
            $this->useConventions,
9✔
169
            $this->conventionThreshold,
9✔
170
            [...$this->profiles, $profile],
9✔
171
            $this->conventions,
9✔
172
        );
9✔
173
    }
174

175
    public function withProfiles(array $profiles): self
1✔
176
    {
177
        return new self(
1✔
178
            $this->cacheType,
1✔
179
            $this->warmupCache,
1✔
180
            $this->useConventions,
1✔
181
            $this->conventionThreshold,
1✔
182
            [...$this->profiles, ...$profiles],
1✔
183
            $this->conventions,
1✔
184
        );
1✔
185
    }
186

187
    // ================
188
    // Validation
189
    // ================
190

191
    public function validate(): void
×
192
    {
193
        if ($this->conventionThreshold < 0.0 || $this->conventionThreshold > 1.0) {
×
194
            throw new InvalidArgumentException('Convention threshold must be between 0.0 and 1.0');
×
195
        }
196

197
        foreach ($this->profiles as $profile) {
×
NEW
198
            if ( ! $profile instanceof MappingProfile) {
×
199
                throw new InvalidArgumentException('All profiles must be instances of MappingProfile');
×
200
            }
201
        }
202

203
        foreach ($this->conventions as $convention) {
×
NEW
204
            if ( ! $convention instanceof NamingConvention) {
×
205
                throw new InvalidArgumentException('All conventions must implement NamingConvention');
×
206
            }
207
        }
208
    }
209
}
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