Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 0 additions & 26 deletions src/Skipper/Fnmatcher.php

This file was deleted.

55 changes: 49 additions & 6 deletions src/Skipper/Matcher/FileInfoMatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,11 @@

use SplFileInfo;
use Symplify\EasyCodingStandard\Skipper\FileSystem\FnMatchPathNormalizer;
use Symplify\EasyCodingStandard\Skipper\Fnmatcher;
use Symplify\EasyCodingStandard\Skipper\RealpathMatcher;

final readonly class FileInfoMatcher
{
public function __construct(
private FnMatchPathNormalizer $fnMatchPathNormalizer,
private Fnmatcher $fnmatcher,
private RealpathMatcher $realpathMatcher,
) {
}

Expand Down Expand Up @@ -54,10 +50,57 @@ private function doesFileInfoMatchPattern(SplFileInfo|string $file, string $igno
return true;
}

if ($this->fnmatcher->match($ignoredPath, $filePath)) {
if ($this->matchesFnmatch($ignoredPath, $filePath)) {
return true;
}

return $this->realpathMatcher->match($ignoredPath, $filePath);
return $this->matchesRealpath($ignoredPath, $filePath);
}

private function matchesFnmatch(string $matchingPath, string $filePath): bool
{
$normalizedMatchingPath = $this->normalizePath($matchingPath);
$normalizedFilePath = $this->normalizePath($filePath);

if (fnmatch($normalizedMatchingPath, $normalizedFilePath)) {
return true;
}

// in case of relative compare
return fnmatch('*/' . $normalizedMatchingPath, $normalizedFilePath);
}

private function matchesRealpath(string $matchingPath, string $filePath): bool
{
/** @var non-empty-string|false $realPathMatchingPath */
$realPathMatchingPath = realpath($matchingPath);
if ($realPathMatchingPath === false) {
return false;
}

$realpathFilePath = realpath($filePath);
if ($realpathFilePath === false) {
return false;
}

$normalizedMatchingPath = $this->normalizePath($realPathMatchingPath);
$normalizedFilePath = $this->normalizePath($realpathFilePath);

// skip define direct path
if (is_file($normalizedMatchingPath)) {
return $normalizedMatchingPath === $normalizedFilePath;
}

// ensure add / suffix to ensure no same prefix directory
if (is_dir($normalizedMatchingPath)) {
$normalizedMatchingPath = rtrim($normalizedMatchingPath, '/') . '/';
}

return str_starts_with($normalizedFilePath, $normalizedMatchingPath);
}

private function normalizePath(string $path): string
{
return str_replace('\\', '/', $path);
}
}
42 changes: 0 additions & 42 deletions src/Skipper/RealpathMatcher.php

This file was deleted.

Loading