rector/packages/Skipper/FileSystem/FnMatchPathNormalizer.php
Tomas Votruba 9038a0d99c Updated Rector to commit 1a91d04c5256e451c744eeb848aaa0182dd227c5
1a91d04c52 [CodeQuality] Add cast scalar support on ReturnTypeFromStrictScalarRector (#3544)
2023-04-01 10:14:17 +00:00

32 lines
854 B
PHP

<?php
declare (strict_types=1);
namespace Rector\Skipper\FileSystem;
use RectorPrefix202304\Nette\Utils\Strings;
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;
}
}