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

tempestphp / tempest-framework / 11292226413

11 Oct 2024 12:21PM UTC coverage: 82.134%. First build
11292226413

Pull #560

github

web-flow
Merge 5007f5fd5 into 571879663
Pull Request #560: chore: refactor view engine

429 of 471 new or added lines in 34 files covered. (91.08%)

6758 of 8228 relevant lines covered (82.13%)

38.48 hits per line

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

90.91
/src/Tempest/Cache/src/IsCache.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace Tempest\Cache;
6

7
use Closure;
8
use DateTimeInterface;
9
use Psr\Cache\CacheItemInterface;
10
use Psr\Cache\CacheItemPoolInterface;
11

12
trait IsCache
13
{
14
    abstract protected function getCachePool(): CacheItemPoolInterface;
15

16
    abstract protected function isEnabled(): bool;
17

18
    public function put(string $key, mixed $value, ?DateTimeInterface $expiresAt = null): CacheItemInterface
55✔
19
    {
20
        $item = $this->getCachePool()
55✔
21
            ->getItem($key)
55✔
22
            ->set($value);
55✔
23

24
        if ($expiresAt !== null) {
55✔
25
            $item = $item->expiresAt($expiresAt);
3✔
26
        }
27

28
        $this->getCachePool()->save($item);
55✔
29

30
        return $item;
55✔
31
    }
32

33
    public function get(string $key): mixed
4✔
34
    {
35
        return $this->getCachePool()->getItem($key)->get();
4✔
36
    }
37

38
    /** @param Closure(): mixed $cache */
39
    public function resolve(string $key, Closure $cache, ?DateTimeInterface $expiresAt = null): mixed
1✔
40
    {
41
        if (! $this->isEnabled()) {
1✔
NEW
42
            return $cache();
×
43
        }
44

45
        $item = $this->getCachePool()->getItem($key);
1✔
46

47
        if (! $item->isHit()) {
1✔
48
            $item = $this->put($key, $cache(), $expiresAt);
1✔
49
        }
50

51
        return $item->get();
1✔
52
    }
53

54
    public function remove(string $key): void
1✔
55
    {
56
        $this->getCachePool()->deleteItem($key);
1✔
57
    }
58

59
    public function clear(): void
47✔
60
    {
61
        if (! $this->getCachePool()->clear()) {
47✔
62
            throw new CouldNotClearCache();
×
63
        }
64
    }
65
}
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