Skip to content

Commit

Permalink
[Scoped] Remove namespace from polyfill (#1749)
Browse files Browse the repository at this point in the history
* [Scoped] Remove namespace from polyfill

* [Scoped] Remove namespace from polyfill
  • Loading branch information
samsonasik committed Jan 31, 2022
1 parent 412043b commit b7b4dc0
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 @@ -47,6 +47,14 @@
],
'packages/Testing/PHPUnit/AbstractTestCase.php' => ['PHPUnit\Framework\TestCase'],
];


/**
* @see https://regex101.com/r/RBZ0bN/1
* @var string
*/
const POLYFILL_STUBS_NAME_REGEX = '#vendor\/symfony\/polyfill\-(.*)\/Resources\/stubs#';

// see https://github.com/humbug/php-scoper
return [
ScoperOption::PREFIX => 'RectorPrefix' . $timestamp,
Expand Down Expand Up @@ -236,5 +244,18 @@ function (string $filePath, string $prefix, string $content): string {

return Strings::replace($content, '#services\->load\(\'#', "services->load('" . $prefix . '\\');
},

// remove namespace from polyfill stubs
function (string $filePath, string $prefix, string $content): string {
if (! Strings::match($filePath, POLYFILL_STUBS_NAME_REGEX)) {
return $content;
}

// remove alias to class have origin PHP names - fix in
$content = Strings::replace($content, '#\\\\class_alias(.*?);#', '');

return Strings::replace($content, '#namespace ' . $prefix . ';#', '');
},

],
];

0 comments on commit b7b4dc0

Please sign in to comment.