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

move-elevator / composer-translation-validator / 16190804208

10 Jul 2025 09:02AM UTC coverage: 94.544% (+0.05%) from 94.496%
16190804208

push

github

web-flow
Merge pull request #22 from move-elevator/parser-cache

feat: implement ParserCache for caching parser instances and add cache statistics

41 of 50 new or added lines in 7 files covered. (82.0%)

953 of 1008 relevant lines covered (94.54%)

6.07 hits per line

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

92.86
/src/Parser/ParserCache.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace MoveElevator\ComposerTranslationValidator\Parser;
6

7
class ParserCache
8
{
9
    /** @var array<string, ParserInterface> */
10
    private static array $cache = [];
11

12
    public static function get(string $filePath, ?string $parserClass): ParserInterface|bool
18✔
13
    {
14
        if (null === $parserClass) {
18✔
NEW
15
            return false;
×
16
        }
17

18
        $cacheKey = $filePath.'::'.$parserClass;
18✔
19

20
        if (!isset(self::$cache[$cacheKey])) {
18✔
21
            self::$cache[$cacheKey] = new $parserClass($filePath);
16✔
22
        }
23

24
        return self::$cache[$cacheKey];
14✔
25
    }
26

27
    public static function clear(): void
16✔
28
    {
29
        self::$cache = [];
16✔
30
    }
31

32
    /** @return array<string, mixed> */
33
    public static function getCacheStats(): array
12✔
34
    {
35
        return [
12✔
36
            'cached_parsers' => count(self::$cache),
12✔
37
            'cache_keys' => array_keys(self::$cache),
12✔
38
        ];
12✔
39
    }
40
}
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