2022-08-31 21:51:50 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare (strict_types=1);
|
|
|
|
namespace Rector\Skipper\FileSystem;
|
|
|
|
|
2023-02-02 09:24:12 +00:00
|
|
|
use RectorPrefix202302\Nette\Utils\Strings;
|
2022-08-31 21:51:50 +00:00
|
|
|
use Rector\Skipper\Enum\AsteriskMatch;
|
|
|
|
/**
|
|
|
|
* @see \Rector\Tests\Skipper\FileSystem\FnMatchPathNormalizerTest
|
|
|
|
*/
|
|
|
|
final class FnMatchPathNormalizer
|
|
|
|
{
|
|
|
|
public function normalizeForFnmatch(string $path) : string
|
|
|
|
{
|
|
|
|
// ends with *
|
|
|
|
if (Strings::match($path, AsteriskMatch::ONLY_ENDS_WITH_ASTERISK_REGEX) !== null) {
|
|
|
|
return '*' . $path;
|
|
|
|
}
|
|
|
|
// starts with *
|
|
|
|
if (Strings::match($path, AsteriskMatch::ONLY_STARTS_WITH_ASTERISK_REGEX) !== null) {
|
|
|
|
return $path . '*';
|
|
|
|
}
|
|
|
|
if (\strpos($path, '..') !== \false) {
|
|
|
|
$path = \realpath($path);
|
|
|
|
if ($path === \false) {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $path;
|
|
|
|
}
|
|
|
|
}
|