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

diego-ninja / granite / 34018013180

06 Sep 2026 07:01AM UTC coverage: 84.549% (+1.2%) from 83.371%
34018013180

Pull #22

github

web-flow
Merge ca5019787 into f40f1b915
Pull Request #22: fix: harden object pipelines and improve performance

822 of 986 new or added lines in 49 files covered. (83.37%)

14 existing lines in 13 files now uncovered.

3513 of 4155 relevant lines covered (84.55%)

16.56 hits per line

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

86.67
/src/Mapping/Cache/InMemoryMappingCache.php
1
<?php
2
// ABOUTME: Defines InMemoryMappingCache as part of the object mapping pipeline.
3
// ABOUTME: Owns the InMemoryMappingCache boundary between mapping configuration and execution.
4

5
namespace Ninja\Granite\Mapping\Cache;
6

7
use Ninja\Granite\Mapping\Contracts\MappingCache;
8

9
/**
10
 * In-memory implementation of mapping cache.
11
 */
12
class InMemoryMappingCache implements MappingCache
13
{
14
    /**
15
     * Cached mapping configurations.
16
     *
17
     * @var array<string, array<string, array<string, mixed>>>
18
     */
19
    private array $cache = [];
20

21
    /**
22
     * Check if a mapping configuration exists in cache.
23
     *
24
     * @param string $sourceType Source type name
25
     * @param string $destinationType Destination type name
26
     * @return bool Whether the mapping exists in cache
27
     */
28
    public function has(string $sourceType, string $destinationType): bool
43 ✔
29
    {
30
        $key = $this->getCacheKey($sourceType, $destinationType);
43 ✔
31
        return isset($this->cache[$key]);
43 ✔
32
    }
33

34
    /**
35
     * Get a mapping configuration from cache.
36
     *
37
     * @param string $sourceType Source type name
38
     * @param string $destinationType Destination type name
39
     * @return array<string, array<string, mixed>>|null Mapping configuration or null if not found
40
     */
41
    public function get(string $sourceType, string $destinationType): ?array
22 ✔
42
    {
43
        $key = $this->getCacheKey($sourceType, $destinationType);
22 ✔
44
        return $this->cache[$key] ?? null;
22 ✔
45
    }
46

47
    /**
48
     * Store a mapping configuration in cache.
49
     *
50
     * @param string $sourceType Source type name
51
     * @param string $destinationType Destination type name
52
     * @param array<string, array<string, mixed>> $config Mapping configuration
53
     * @return void
54
     */
55
    public function put(string $sourceType, string $destinationType, array $config): void
48 ✔
56
    {
57
        $key = $this->getCacheKey($sourceType, $destinationType);
48 ✔
58
        $this->cache[$key] = $config;
48 ✔
59
    }
60

61
    /**
62
     * Clear all cached mapping configurations.
63
     *
64
     * @return void
65
     */
66
    public function clear(): void
45 ✔
67
    {
68
        $this->cache = [];
45 ✔
69
    }
70

71
    /**
72
     * Get all cached mapping configurations.
73
     *
74
     * @return array<string, array<string, array<string, mixed>>>
75
     */
NEW
76
    public function all(): array
×
77
    {
NEW
78
        return $this->cache;
×
79
    }
80

81
    /**
82
     * Get cache key for a type pair.
83
     *
84
     * @param string $sourceType Source type name
85
     * @param string $destinationType Destination type name
86
     * @return string Cache key
87
     */
88
    private function getCacheKey(string $sourceType, string $destinationType): string
50 ✔
89
    {
90
        return $sourceType . '->' . $destinationType;
50 ✔
91
    }
92
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc