Skip to content

Commit

Permalink
return
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasVotruba committed Jun 7, 2022
1 parent 145096b commit 39c7ae6
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions scoper.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,27 @@ function (string $filePath, string $prefix, string $content): string {
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
Expand Down

0 comments on commit 39c7ae6

Please sign in to comment.