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

68publishers / asset / 4437761697

pending completion
4437761697

Pull #12

github

GitHub
Merge 1be5620bd into a045a321b
Pull Request #12: FileModifyTimeStrategy

33 of 33 new or added lines in 2 files covered. (100.0%)

184 of 191 relevant lines covered (96.34%)

0.96 hits per line

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

91.3
/src/VersionStrategy/CacheAssets.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace SixtyEightPublishers\Asset\VersionStrategy;
6

7
final class CacheAssets
8
{
9
        private bool $debugMode;
10

11
        private string $tempFile;
12

13
        /** @var ?array<int> */
14
        private ?array $files = null;
15

16
        private bool $save = false;
17

18

19
        public function __construct(bool $debugMode, string $tempDir)
1✔
20
        {
21
                $this->debugMode = $debugMode;
1✔
22
                $this->tempFile = $tempDir . '/_assets.php';
1✔
23
        }
1✔
24

25

26
        public function load(string $pathname): int
1✔
27
        {
28
                $this->loadCache();
1✔
29
                if (isset($this->files[$pathname])) {
1✔
30
                        return $this->files[$pathname];
1✔
31
                }
32

33
                $this->save = true;
1✔
34
                $mtime = filemtime($pathname);
1✔
35

36
                return $this->files[$pathname] = $mtime === false ? 0 : $mtime;
1✔
37
        }
38

39

40
        private function loadCache(): void
41
        {
42
                if ($this->files !== null) {
1✔
43
                        return;
1✔
44
                } elseif ($this->debugMode === true) {
1✔
45
                        $this->files = [];
1✔
46
                } else {
47
                        $this->files = require $this->tempFile;
×
48
                }
49
        }
1✔
50

51

52
        /**
53
         * Clear local cache
54
         * @return static
55
         */
56
        public function clear()
57
        {
58
                $this->files = [];
1✔
59
                $this->save = true;
1✔
60

61
                return $this;
1✔
62
        }
63

64

65
        public function __destruct()
66
        {
67
                if ($this->debugMode === false && $this->save === true) {
1✔
68
                        file_put_contents($this->tempFile, '<?php return ' . var_export($this->files, true) . ';');
×
69
                }
70
        }
1✔
71

72
}
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