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

nepada / bust-cache / 8294617124

01 Mar 2024 10:19AM UTC coverage: 95.395%. Remained the same
8294617124

push

github

web-flow
Bump the phpstan group with 2 updates (#114)

290 of 304 relevant lines covered (95.39%)

0.95 hits per line

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

95.0
/src/BustCache/FileSystem/LocalFileSystem.php
1
<?php
2
declare(strict_types = 1);
3

4
namespace Nepada\BustCache\FileSystem;
5

6
final class LocalFileSystem implements FileSystem
7
{
8

9
    private Path $baseDirectoryPath;
10

11
    /**
12
     * @throws DirectoryNotFoundException
13
     */
14
    public function __construct(Path $baseDirectoryPath)
1✔
15
    {
16
        $baseDirectoryPath = $baseDirectoryPath->normalize();
1✔
17
        if (! is_dir($baseDirectoryPath->toString())) {
1✔
18
            throw DirectoryNotFoundException::at($baseDirectoryPath->toString());
×
19
        }
20
        $this->baseDirectoryPath = $baseDirectoryPath;
1✔
21
    }
1✔
22

23
    /**
24
     * @return LocalFileSystem
25
     * @throws DirectoryNotFoundException
26
     */
27
    public static function forDirectory(string $baseDir): self
1✔
28
    {
29
        return new self(Path::of($baseDir));
1✔
30
    }
31

32
    public function fileExists(Path $path): bool
1✔
33
    {
34
        try {
35
            $this->getFile($path);
1✔
36
            return true;
1✔
37
        } catch (FileNotFoundException $exception) {
1✔
38
            return false;
1✔
39
        }
40
    }
41

42
    /**
43
     * @throws FileNotFoundException
44
     */
45
    public function getFile(Path $path): File
1✔
46
    {
47
        $fullLocalPath = Path::join($this->baseDirectoryPath, $path);
1✔
48
        if (! is_file($fullLocalPath->toString())) {
1✔
49
            throw FileNotFoundException::at($fullLocalPath->toString());
1✔
50
        }
51
        if (! str_starts_with((string) realpath($fullLocalPath->toString()), realpath($this->baseDirectoryPath->toString()) . DIRECTORY_SEPARATOR)) {
1✔
52
            throw FileNotFoundException::inBaseDirectory($fullLocalPath->toString(), $this->baseDirectoryPath->toString());
1✔
53
        }
54
        return File::fromLocalPath($fullLocalPath);
1✔
55
    }
56

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