Fix consolidation/robo PHP 8.2 deprecation notices

[MAILPOET-4900]

When a new robo version with a fix for 'self' in callables is released,
this patch can be removed. Check here:
https://github.com/consolidation/robo/issues/1135
This commit is contained in:
alex-mailpoet
2023-01-26 15:42:31 +03:00
committed by Veljko V
parent 3282e2f063
commit 46c45d9bef
2 changed files with 46 additions and 1 deletions

View File

@@ -86,7 +86,8 @@
], ],
"pre-autoload-dump": [ "pre-autoload-dump": [
"php ./tasks/fix-codeception-stub.php", "php ./tasks/fix-codeception-stub.php",
"php ./tasks/fix-requests.php" "php ./tasks/fix-requests.php",
"php ./tasks/fix-php82-robo.php"
] ]
}, },
"config": { "config": {

View File

@@ -0,0 +1,44 @@
<?php // phpcs:ignore SlevomatCodingStandard.TypeHints.DeclareStrictTypes.DeclareStrictTypesMissing
// throw exception if anything fails
set_error_handler(function ($severity, $message, $file, $line) {
throw new ErrorException($message, 0, $severity, $file, $line);
});
// Skip for production build
if (!file_exists(__DIR__ . '/../vendor/consolidation/robo/src/Common/CommandArguments.php')) {
exit;
}
// Fixes for PHP8.2 Compatibility
// Development packages
$replacements = [
// Robo patches can be removed after a new version with this fix is released:
// https://github.com/consolidation/robo/issues/1135
[
'file' => __DIR__ . '/../vendor/consolidation/robo/src/Common/CommandArguments.php',
'find' => [
'$this->arguments .= \' \' . implode(\' \', array_map(\'static::escape\', $args));',
],
'replace' => [
'$this->arguments .= \' \' . implode(\' \', array_map([static::class, \'escape\'], $args));',
],
],
[
'file' => __DIR__ . '/../vendor/consolidation/robo/src/Task/Base/Exec.php',
'find' => [
'$stopRunningJobs = Closure::fromCallable([\'self\', \'stopRunningJobs\']);',
],
'replace' => [
'$stopRunningJobs = Closure::fromCallable(self::class.\'::stopRunningJobs\');',
],
],
];
// Apply replacements
foreach ($replacements as $singleFile) {
$data = file_get_contents($singleFile['file']);
$data = str_replace($singleFile['find'], $singleFile['replace'], $data);
file_put_contents($singleFile['file'], $data);
}