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

nepada / bust-cache / 5143471446

pending completion
5143471446

Pull #96

github

web-flow
Merge 22bd8fddd into c682a9643
Pull Request #96: Update phpstan/phpstan requirement from 1.10.14 to 1.10.15

310 of 314 relevant lines covered (98.73%)

0.99 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
     * @param Path $baseDirectoryPath
13
     * @throws DirectoryNotFoundException
14
     */
15
    public function __construct(Path $baseDirectoryPath)
1✔
16
    {
17
        $baseDirectoryPath = $baseDirectoryPath->normalize();
1✔
18
        if (! is_dir($baseDirectoryPath->toString())) {
1✔
19
            throw DirectoryNotFoundException::at($baseDirectoryPath->toString());
×
20
        }
21
        $this->baseDirectoryPath = $baseDirectoryPath;
1✔
22
    }
1✔
23

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

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

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

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