Skip to content

Commit

Permalink
small refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Sep 26, 2023
1 parent 329088d commit 3a947ef
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
9 changes: 4 additions & 5 deletions src/RobotLoader/RobotLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -253,20 +253,19 @@ private function refreshClasses(): void
private function createFileIterator(string $dir): Nette\Utils\Finder
{
if (!is_dir($dir)) {
throw new Nette\IOException(sprintf("File or directory '%s' not found.", $dir));
throw new Nette\IOException(sprintf("Directory '%s' not found.", $dir));
}

$dir = realpath($dir) ?: $dir; // realpath does not work in phar
$disallow = [];
foreach (array_merge($this->ignoreDirs, $this->excludeDirs) as $item) {
if ($item = realpath($item)) {
$disallow[FileSystem::unixSlashes($item)] = true;
$disallow[$item] = true;
}
}

return Nette\Utils\Finder::findFiles($this->acceptFiles)
->filter($filter = fn(SplFileInfo $file) => $file->getRealPath() === false
|| !isset($disallow[FileSystem::unixSlashes($file->getRealPath())]))
->filter($filter = fn(SplFileInfo $file) => $file->getRealPath() === false || !isset($disallow[$file->getRealPath()]))
->descentFilter($filter)
->from($dir)
->exclude($this->ignoreDirs);
Expand All @@ -286,7 +285,7 @@ private function updateFile(string $file): void
foreach ($foundClasses as $class) {
[$prevFile, $prevMtime] = $this->classes[$class] ?? null;

if (isset($prevFile) && @filemtime($prevFile) !== $prevMtime) { // @ file may not exists
if (isset($prevFile) && @filemtime($prevFile) !== $prevMtime) { // @ file may not exist

Check failure on line 288 in src/RobotLoader/RobotLoader.php

View workflow job for this annotation

GitHub Actions / PHPStan

Variable $prevFile in isset() always exists and is not nullable.
$this->updateFile($prevFile);
[$prevFile] = $this->classes[$class] ?? null;
}
Expand Down
4 changes: 2 additions & 2 deletions tests/Loaders/RobotLoader.phar.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ $loader->addDirectory("phar://$pharFile/non-dir");
Assert::exception(
fn() => $loader->rebuild(),
Nette\IOException::class,
"File or directory 'phar://$pharFile/non-dir' not found.",
"Directory 'phar://$pharFile/non-dir' not found.",
);


Expand All @@ -58,5 +58,5 @@ $loader->addDirectory("phar://$pharFile/non-file.php");
Assert::exception(
fn() => $loader->rebuild(),
Nette\IOException::class,
"File or directory 'phar://$pharFile/non-file.php' not found.",
"Directory 'phar://$pharFile/non-file.php' not found.",
);

0 comments on commit 3a947ef

Please sign in to comment.