-
-
Notifications
You must be signed in to change notification settings - Fork 336
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Skipper] Handle provide direct relative path in Skipper (#2921)
Co-authored-by: GitHub Action <action@github.com>
- Loading branch information
1 parent
2975a1b
commit effe4d3
Showing
8 changed files
with
67 additions
and
4 deletions.
There are no files selected for viewing
1 change: 1 addition & 0 deletions
1
packages-tests/Skipper/Skipper/Skipper/Fixture/SomeSkippedPath/any.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
any content |
1 change: 1 addition & 0 deletions
1
packages-tests/Skipper/Skipper/Skipper/Fixture/SomeSkippedPathToFile/any.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
any content |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rector\Skipper; | ||
|
||
final class RealpathMatcher | ||
{ | ||
public function match(string $matchingPath, string $filePath): bool | ||
{ | ||
$realPathMatchingPath = realpath($matchingPath); | ||
$realpathFilePath = realpath($filePath); | ||
|
||
if (! is_string($realPathMatchingPath)) { | ||
return false; | ||
} | ||
|
||
if (! is_string($realpathFilePath)) { | ||
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters