1: <?php
2:
3: declare(strict_types=1);
4:
5: namespace PHPStan\BetterReflection\SourceLocator;
6:
7: use PHPStan\BetterReflection\SourceLocator\Exception\InvalidFileLocation;
8:
9: use function is_file;
10: use function is_readable;
11: use function sprintf;
12:
13: class FileChecker
14: {
15: /** @throws InvalidFileLocation */
16: public static function assertReadableFile(string $filename): void
17: {
18: if (empty($filename)) {
19: throw new InvalidFileLocation('Filename was empty');
20: }
21:
22: if (! is_file($filename)) {
23: throw new InvalidFileLocation(sprintf('"%s" is not a file', $filename));
24: }
25:
26: if (! is_readable($filename)) {
27: throw new InvalidFileLocation(sprintf('File "%s" is not readable', $filename));
28: }
29: }
30: }
31: