This commit is contained in:
Tomas Votruba 2022-06-07 09:34:38 +02:00
parent 145096b208
commit 39c7ae65e9

View File

@ -144,6 +144,27 @@ return [
return Strings::replace($content, '#' . $prefix . '\\\\Composer\\\\#', 'Composer\\');
},
// fixes https://github.com/rectorphp/rector/issues/6007 - this is fixed in scoper 0.17.2+
function (string $filePath, string $prefix, string $content): string {
if (! \str_contains($filePath, 'vendor/')) {
return $content;
}
// @see https://regex101.com/r/lBV8IO/2
$fqcnReservedPattern = sprintf('#(\\\\)?%s\\\\(parent|self|static)#m', $prefix);
$matches = Strings::matchAll($content, $fqcnReservedPattern);
if ($matches === []) {
return $content;
}
foreach ($matches as $match) {
$content = str_replace($match[0], $match[2], $content);
}
return $content;
},
// unprefix string classes, as they're string on purpose - they have to be checked in original form, not prefixed
function (string $filePath, string $prefix, string $content): string {
// skip vendor, expect rector packages