rector/packages/Skipper/FileSystem/FnMatchPathNormalizer.php
Tomas Votruba 764b0a2692 Updated Rector to commit cb5b01223d46272004e947f122ae1e36d516f83a
cb5b01223d [automated] Re-Generate Nodes/Rectors Documentation (#3259)
2023-01-01 00:36:31 +00:00

32 lines
854 B
PHP

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