From 2c094dbe10f6ea13a9caa2fa370191629b13d54e Mon Sep 17 00:00:00 2001 From: Rolland Csatari Date: Tue, 18 Jun 2024 16:06:06 +0200 Subject: [PATCH] chore(upgrade): Monolog --- CHANGELOG.md | 11 ++++++++ Command/EncryptCommand.php | 5 ---- Monolog/Processor/GdprProcessor.php | 24 ++++-------------- Tests/Monolog/Processor/GdprProcessorTest.php | 25 ++++++++++++------- composer.json | 18 ++++++------- 5 files changed, 41 insertions(+), 42 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e78e2db..b374971 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,18 @@ CHANGELOG master ------ +* todo... + +v3.0.0 +------ + * Bump PHP version from ^8.0 to ^8.1 and configure CI with 8.1 and 8.2 +* Bump Monolog version from ^1.24 || ~2.0 to ^3.6.0 +* Bump symfony/(config|console|dependency-injection|form|http-kernel|options-resolver|translation|validator) from ^4.4 || ^5.3 || ^6.0 to ^5.4 || ^6.4 || ^7.0 +* Adapt `Monolog/Processor/GdprProcessor` to the new `Monolog\Processor\ProcessorInterface` +* Improve `Monolog/Processor/GdprProcessor` type hinting +* Update `Tests/Monolog/Processor/GdprProcessorTest.php` +* Update `Command/EncryptCommand.php` v2.0.0 ------ diff --git a/Command/EncryptCommand.php b/Command/EncryptCommand.php index 0431808..e4913a0 100644 --- a/Command/EncryptCommand.php +++ b/Command/EncryptCommand.php @@ -28,11 +28,6 @@ #[AsCommand(name: 'ekino-data-protection:encrypt')] final class EncryptCommand extends Command { - /** - * {@inheritdoc} - */ - protected static $defaultName = 'ekino-data-protection:encrypt'; - /** * @var string */ diff --git a/Monolog/Processor/GdprProcessor.php b/Monolog/Processor/GdprProcessor.php index 7146102..325ef80 100644 --- a/Monolog/Processor/GdprProcessor.php +++ b/Monolog/Processor/GdprProcessor.php @@ -14,6 +14,7 @@ namespace Ekino\DataProtectionBundle\Monolog\Processor; use Ekino\DataProtectionBundle\Encryptor\EncryptorInterface; +use Monolog\LogRecord; use Monolog\Processor\ProcessorInterface; /** @@ -21,32 +22,17 @@ * * @author Rémi Marseille * @author Benoit Mazière + * @author Rolland Csatari */ class GdprProcessor implements ProcessorInterface { - /** - * @var EncryptorInterface - */ - private $encryptor; - - /** - * GdprProcessor constructor. - * - * @param EncryptorInterface $encryptor - */ - public function __construct(EncryptorInterface $encryptor) + public function __construct(private EncryptorInterface $encryptor) { - $this->encryptor = $encryptor; } - /** - * @param array $record - * - * @return array - */ - public function __invoke(array $record) + public function __invoke(LogRecord $record): LogRecord { - foreach ($record['context'] as $key => &$val) { + foreach ($record->context as $key => &$val) { if (preg_match('#^private_#', (string) $key)) { $encoded = json_encode($val); if (false === $encoded) { diff --git a/Tests/Monolog/Processor/GdprProcessorTest.php b/Tests/Monolog/Processor/GdprProcessorTest.php index e131313..c57debf 100644 --- a/Tests/Monolog/Processor/GdprProcessorTest.php +++ b/Tests/Monolog/Processor/GdprProcessorTest.php @@ -15,6 +15,8 @@ use Ekino\DataProtectionBundle\Encryptor\EncryptorInterface; use Ekino\DataProtectionBundle\Monolog\Processor\GdprProcessor; +use Monolog\Level; +use Monolog\LogRecord; use PHPUnit\Framework\TestCase; /** @@ -22,6 +24,7 @@ * * @author Rémi Marseille * @author Benoit Mazière + * @author Rolland Csatari */ class GdprProcessorTest extends TestCase { @@ -33,20 +36,24 @@ public function testProcessor(): void $encryptor = $this->createMock(EncryptorInterface::class); $encryptor->expects($this->once())->method('encrypt')->willReturn('encrypted_data'); - $processor = new GdprProcessor($encryptor); - - $this->assertSame(['context' => [ - 0 => 'numeric index', - 'foo' => 'bar', - 'private_data' => 'encrypted_data', - ]], $processor->__invoke([ - 'context' => [ + $record = new LogRecord( + new \DateTimeImmutable(), + 'main', + Level::Debug, + 'The log context includes private data.', + [ 0 => 'numeric index', 'foo' => 'bar', 'private_data' => [ 'foo' => 'baz', ], ], - ])); + ); + + $this->assertSame([ + 0 => 'numeric index', + 'foo' => 'bar', + 'private_data' => 'encrypted_data', + ], ((new GdprProcessor($encryptor))($record))->context); } } diff --git a/composer.json b/composer.json index ca9cda7..68be399 100644 --- a/composer.json +++ b/composer.json @@ -16,15 +16,15 @@ "php": "^8.1", "ext-json": "*", "ext-openssl": "*", - "monolog/monolog": "^1.24 || ~2.0", - "symfony/config": "^4.4 || ^5.3 || ^6.0", - "symfony/console": "^4.4 || ^5.3 || ^6.0", - "symfony/dependency-injection": "^4.4 || ^5.3 || ^6.0", - "symfony/form": "^4.4 || ^5.3 || ^6.0", - "symfony/http-kernel": "^4.4 || ^5.3 || ^6.0", - "symfony/options-resolver": "^4.4 || ^5.3 || ^6.0", - "symfony/translation": "^4.4 || ^5.3 || ^6.0", - "symfony/validator": "^4.4 || ^5.3 || ^6.0" + "monolog/monolog": "^3.6.0", + "symfony/config": "^5.4 || ^6.4 || ^7.0", + "symfony/console": "^5.4 || ^6.4 || ^7.0", + "symfony/dependency-injection": "^5.4 || ^6.4 || ^7.0", + "symfony/form": "^5.4 || ^6.4 || ^7.0", + "symfony/http-kernel": "^5.4 || ^6.4 || ^7.0", + "symfony/options-resolver": "^5.4 || ^6.4 || ^7.0", + "symfony/translation": "^5.4 || ^6.4 || ^7.0", + "symfony/validator": "^5.4 || ^6.4 || ^7.0" }, "require-dev": { "dg/bypass-finals": "^1.4",