diff --git a/.github/scripts/run-scoper.sh b/.github/scripts/run-scoper.sh index b82b40d..8e1c9c8 100755 --- a/.github/scripts/run-scoper.sh +++ b/.github/scripts/run-scoper.sh @@ -25,4 +25,13 @@ else cd matomo fi +sudo sed -i 's/memory_limit[[:space:]]*=[[:space:]]*[0-9-]\+/memory_limit = 2048M/g' /etc/php/8.2/cli/php.ini + +if [[ -f "/etc/php/8.2/cli/conf.d/99-pecl.ini" ]]; then + sudo sed -i 's/memory_limit[[:space:]]*=[[:space:]]*[0-9-]\+[[:space:]]*M/memory_limit = 2048M/g' /etc/php/8.2/cli/conf.d/99-pecl.ini +fi + +echo "Memory limit used:" +php -r 'echo ini_get("memory_limit")."\n";' + php8.2 "$MATOMO_SCOPER_PATH" scope -y --rename-references . diff --git a/README.md b/README.md index 87de54a..2e360a4 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,7 @@ Every time you need to update a prefixed dependency or prefix a new one, you wil ### How to scope Matomo core + Pre-requisites: * make sure you are using PHP 8.1 or greater. diff --git a/resources/core-scoper.inc.php b/resources/core-scoper.inc.php index ab51919..50b7ce1 100644 --- a/resources/core-scoper.inc.php +++ b/resources/core-scoper.inc.php @@ -29,6 +29,7 @@ ->exclude('build') ->exclude('vendor/prefixed') ->exclude('vendor/composer') + ->exclude('vendor/phpmailer') // wordfence creates a false positive here ->exclude('node_modules') ->exclude('tmp') ->exclude('@types') @@ -45,6 +46,7 @@ ->notPath('%^tests/PHPUnit/System/ConsoleTest\\.php$%') ->notPath('%^tests/PHPUnit/System/FrontControllerTest\\.php$%') ->notPath('%^tests/resources/trigger-fatal\\.php$%') + ->notPath('%^tests/resources/overlay-test-site(-real)?/opt-out\\.php$%') ->filter(function (\SplFileInfo $file) { return !($file->isLink() && $file->isDir()); @@ -93,6 +95,21 @@ static function (string $filePath, string $prefix, string $content) use ($isRena $content = preg_replace('/([^\\\\A-Za-z0-9_])\\\\?Archive_Tar(?!\\/)/', '$1\\Matomo\\Dependencies\\Archive_Tar', $content); $content = preg_replace('/([^\\\\A-Za-z0-9_])\\\\?Console_Getopt(?!\\/)/', '$1\\Matomo\\Dependencies\\Console_Getopt', $content); $content = preg_replace('/([^\\\\A-Za-z0-9_])\\\\?OS_Guess(?!\\/)/', '$1\\Matomo\\Dependencies\\OS_Guess', $content); + + return $content; + }, + + static function (string $filePath, string $prefix, string $content) use ($isRenamingReferences): string { + if ($isRenamingReferences) { + return $content; + } + + if (strpos($filePath, 'pear/pear-core-minimal') !== false) { + $content = str_replace("'PEAR_Error'", "'\\\\Matomo\\\\Dependencies\\\\PEAR_Error'", $content); + $content = str_replace("'PEAR_ErrorStack'", "'\\\\Matomo\\\\Dependencies\\\\PEAR_ErrorStack'", $content); + $content = str_replace("'System'", "'\\\\Matomo\\\\Dependencies\\\\System'", $content); + } + return $content; }, @@ -118,6 +135,11 @@ static function (string $filePath, string $prefix, string $content) use ($isRena $content = preg_replace("/([^\\\\])(_?twig_[a-z_0-9]+)\('/", '${1}\\Matomo\\Dependencies\\\${2}(\'', $content); } + // scope escaped classes in template strings + if (!$isRenamingReferences && strpos($filePath, 'twig/twig') !== false) { + $content = preg_replace("/(['\"])\\\\\\\\Twig\\\\\\\\/", '${1}\\\\\\\\Matomo\\\\\\\\Dependencies\\\\\\\\Twig\\\\\\\\', $content); + } + return $content; }, @@ -195,6 +217,15 @@ static function (string $filePath, string $prefix, string $content) use ($isRena $content = str_replace('it(', 'it.skip(', $content); } + if ($filePath === __DIR__ . '/plugins/TestRunner/Commands/CheckDirectDependencyUse.php') { + $replacementCode = <<