Fix gregwar/captcha PHP 8.2 deprecation notices

[MAILPOET-4874]
This commit is contained in:
alex-mailpoet
2023-01-24 13:08:21 +03:00
committed by Aschepikov
parent 310d689219
commit a11a462eee
2 changed files with 32 additions and 2 deletions

View File

@@ -77,12 +77,14 @@
"post-update-cmd": [
"./tools/vendor/composer.phar --working-dir=tasks/code_sniffer install",
"./tools/vendor/composer.phar --working-dir=tasks/phpstan install",
"php ./tasks/fix-guzzle.php"
"php ./tasks/fix-guzzle.php",
"php ./tasks/fix-php82-deprecations.php"
],
"post-install-cmd": [
"./tools/vendor/composer.phar --working-dir=tasks/code_sniffer install",
"./tools/vendor/composer.phar --working-dir=tasks/phpstan install",
"php ./tasks/fix-guzzle.php"
"php ./tasks/fix-guzzle.php",
"php ./tasks/fix-php82-deprecations.php"
],
"pre-autoload-dump": [
"php ./tasks/fix-codeception-stub.php",

View File

@@ -0,0 +1,28 @@
<?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);
});
// Fixes for PHP8.2 Compatibility
// Production packages
$replacements = [
[
'file' => __DIR__ . '/../vendor-prefixed/gregwar/captcha/src/Gregwar/Captcha/CaptchaBuilder.php',
'find' => [
'protected $backgroundColor = null;' . "\n" . ' /**',
],
'replace' => [
'protected $backgroundColor = null;' . PHP_EOL . ' protected $background = null;' . PHP_EOL . ' /**',
],
],
];
// 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);
}