Skip to content

Commit

Permalink
correctly rename strings of prefixed PEAR classes in pear-core-minimal (
Browse files Browse the repository at this point in the history
#15)

* correctly rename strings of prefixed PEAR classes in pear-core-minimal

* trigger build

* debug build failure

* undo debugging changes and add manual scoping of class references in strings in twig

* disable CheckDirectDependencyUse

* debug

* increase memory limit during github actions tests

* do not prefix overlay test site
  • Loading branch information
diosmosis authored Jun 12, 2024
1 parent 51ac8d4 commit 85dfb9a
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .github/scripts/run-scoper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 .
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
31 changes: 31 additions & 0 deletions resources/core-scoper.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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());
Expand Down Expand Up @@ -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;
},

Expand All @@ -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;
},

Expand Down Expand Up @@ -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 = <<<PHP
\\PHPUnit\\Framework\\Assert::markTestSkipped("do not run");
return 0;
PHP;

$content = preg_replace('/protected\s+function\s+doExecute\(\)\s+:\s+int\s+\{/', '$0' . $replacementCode, $content);
}

return $content;
},
],
Expand Down

0 comments on commit 85dfb9a

Please sign in to comment.