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

tempestphp / tempest-framework / 12021710761

25 Nov 2024 06:54PM UTC coverage: 79.441% (-2.6%) from 81.993%
12021710761

push

github

web-flow
ci: close stale issues and pull requests

7879 of 9918 relevant lines covered (79.44%)

61.32 hits per line

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

51.52
/src/Tempest/Core/src/DiscoveryCache.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace Tempest\Core;
6

7
use Psr\Cache\CacheItemPoolInterface;
8
use Symfony\Component\Cache\Adapter\PhpFilesAdapter;
9
use Tempest\Cache\Cache;
10
use Tempest\Cache\CacheConfig;
11
use Tempest\Cache\DiscoveryCacheStrategy;
12
use Tempest\Cache\IsCache;
13
use function Tempest\path;
14

15
final class DiscoveryCache implements Cache
16
{
17
    use IsCache {
18
        clear as parentClear;
19
    }
20

21
    public const string CURRENT_DISCOVERY_STRATEGY = __DIR__ . '/.cache/current_discovery_strategy';
22

23
    private CacheItemPoolInterface $pool;
24

25
    public function __construct(
382✔
26
        private readonly CacheConfig $cacheConfig,
27
        ?CacheItemPoolInterface $pool = null,
28
    ) {
29
        $this->pool = $pool ?? new PhpFilesAdapter(
382✔
30
            directory: path($this->cacheConfig->directory, 'discovery')->toString(),
382✔
31
        );
382✔
32
    }
33

34
    public function restore(string $className): ?DiscoveryItems
382✔
35
    {
36
        $key = str_replace('\\', '_', $className);
382✔
37

38
        return $this->get($key);
382✔
39
    }
40

41
    public function store(Discovery $discovery, DiscoveryItems $discoveryItems): void
×
42
    {
43
        $key = str_replace('\\', '_', $discovery::class);
×
44

45
        $item = $this->pool
×
46
            ->getItem($key)
×
47
            ->set($discoveryItems);
×
48

49
        $this->pool->save($item);
×
50
    }
51

52
    protected function getCachePool(): CacheItemPoolInterface
382✔
53
    {
54
        return $this->pool;
382✔
55
    }
56

57
    public function isEnabled(): bool
382✔
58
    {
59
        if (! $this->isValid()) {
382✔
60
            return false;
×
61
        }
62

63
        if ($this->cacheConfig->enable) {
382✔
64
            return true;
×
65
        }
66

67
        return $this->cacheConfig->discoveryCache->isEnabled();
382✔
68
    }
69

70
    public function isValid(): bool
382✔
71
    {
72
        return $this->cacheConfig->discoveryCache->isValid();
382✔
73
    }
74

75
    public function clear(): void
×
76
    {
77
        $this->parentClear();
×
78

79
        $this->storeStrategy(DiscoveryCacheStrategy::INVALID);
×
80
    }
81

82
    public function getStrategy(): DiscoveryCacheStrategy
382✔
83
    {
84
        return $this->cacheConfig->discoveryCache;
382✔
85
    }
86

87
    public function storeStrategy(DiscoveryCacheStrategy $strategy): void
×
88
    {
89
        $dir = dirname(self::CURRENT_DISCOVERY_STRATEGY);
×
90

91
        if (! is_dir($dir)) {
×
92
            mkdir($dir, recursive: true);
×
93
        }
94

95
        file_put_contents(self::CURRENT_DISCOVERY_STRATEGY, $strategy->value);
×
96
    }
97
}
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