Skip to content

Commit

Permalink
realpath
Browse files Browse the repository at this point in the history
  • Loading branch information
janedbal committed Jan 8, 2024
1 parent 5b408ae commit 21e2483
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions src/Config/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use function in_array;
use function preg_last_error;
use function preg_match;
use function realpath;
use function strpos;

class Configuration
Expand Down Expand Up @@ -96,7 +97,7 @@ public function setFileExtensions(array $extensions): self
*/
public function addPathToScan(string $path, bool $isDev): self
{
$this->pathsToScan[] = new PathToScan($path, $isDev);
$this->pathsToScan[] = new PathToScan($this->realpath($path), $isDev);
return $this;
}

Expand All @@ -118,7 +119,7 @@ public function addPathsToScan(array $paths, bool $isDev): self
*/
public function addPathToExclude(string $path): self
{
$this->pathsToExclude[] = $path;
$this->pathsToExclude[] = $this->realpath($path);
return $this;
}

Expand All @@ -145,8 +146,10 @@ public function ignoreErrorsOnPath(string $path, array $errorTypes): self
throw new LogicException('Unused dependency errors cannot be ignored on a path');
}

$previousErrorTypes = $this->ignoredErrorsOnPath[$path] ?? [];
$this->ignoredErrorsOnPath[$path] = array_merge($previousErrorTypes, $errorTypes);
$realpath = $this->realpath($path);

$previousErrorTypes = $this->ignoredErrorsOnPath[$realpath] ?? [];
$this->ignoredErrorsOnPath[$realpath] = array_merge($previousErrorTypes, $errorTypes);
return $this;
}

Expand Down Expand Up @@ -328,4 +331,15 @@ private function isFilepathWithinPath(string $filePath, string $path): bool
return strpos($filePath, $path) === 0;
}

private function realpath(string $filePath): string
{
$realPath = realpath($filePath);

if ($realPath === false) {
throw new LogicException("Unable to realpath '$filePath'");
}

return $realPath;
}

}

0 comments on commit 21e2483

Please sign in to comment.