From 291e198cffe46cb829fcd8eb230ed7a0fb9c146f Mon Sep 17 00:00:00 2001 From: Nattfarinn Date: Tue, 3 Oct 2023 10:13:44 +0200 Subject: [PATCH 1/6] IBX-5827: Replaced deprecated string interpolation (PHP 8.2+) --- .../EzPublishCoreBundle/Features/Context/UserContext.php | 2 +- eZ/Publish/API/Repository/Tests/BaseTest.php | 2 +- eZ/Publish/API/Repository/Tests/ContentTypeServiceTest.php | 2 +- eZ/Publish/Core/FieldType/GatewayBasedStorage.php | 2 +- eZ/Publish/Core/Persistence/Cache/AbstractHandler.php | 4 ++-- eZ/Publish/Core/Persistence/Cache/AbstractInMemoryHandler.php | 2 +- eZ/Publish/Core/Persistence/Cache/ContentHandler.php | 4 ++-- 7 files changed, 9 insertions(+), 9 deletions(-) diff --git a/eZ/Bundle/EzPublishCoreBundle/Features/Context/UserContext.php b/eZ/Bundle/EzPublishCoreBundle/Features/Context/UserContext.php index 2f4f835741..885ac2569b 100644 --- a/eZ/Bundle/EzPublishCoreBundle/Features/Context/UserContext.php +++ b/eZ/Bundle/EzPublishCoreBundle/Features/Context/UserContext.php @@ -544,7 +544,7 @@ public function assertUserWithNameExistsWithFields($username, TableNode $table) */ private function findNonExistingUserEmail($username = 'User') { - $email = "${username}@ez.no"; + $email = "{$username}@ez.no"; if ($this->checkUserExistenceByEmail($email)) { return $email; } diff --git a/eZ/Publish/API/Repository/Tests/BaseTest.php b/eZ/Publish/API/Repository/Tests/BaseTest.php index fec0373452..ef4b0ecd76 100644 --- a/eZ/Publish/API/Repository/Tests/BaseTest.php +++ b/eZ/Publish/API/Repository/Tests/BaseTest.php @@ -171,7 +171,7 @@ protected function getSetupFactory(): SetupFactory if (null === $this->setupFactory) { if (false === ($setupClass = getenv('setupFactory'))) { $setupClass = LegacySetupFactory::class; - putenv("setupFactory=${setupClass}"); + putenv("setupFactory={$setupClass}"); } if (false === getenv('fixtureDir')) { diff --git a/eZ/Publish/API/Repository/Tests/ContentTypeServiceTest.php b/eZ/Publish/API/Repository/Tests/ContentTypeServiceTest.php index 79f9e425c5..b76bab4f72 100644 --- a/eZ/Publish/API/Repository/Tests/ContentTypeServiceTest.php +++ b/eZ/Publish/API/Repository/Tests/ContentTypeServiceTest.php @@ -841,7 +841,7 @@ public function testCreateContentTypeStructValues(array $data) $this->assertEquals( $typeCreate->$propertyName, $contentType->$propertyName, - "Did not assert that property '${propertyName}' is equal on struct and resulting value object" + "Did not assert that property '{$propertyName}' is equal on struct and resulting value object" ); break; } diff --git a/eZ/Publish/Core/FieldType/GatewayBasedStorage.php b/eZ/Publish/Core/FieldType/GatewayBasedStorage.php index 6e0eedf5b1..261c115029 100644 --- a/eZ/Publish/Core/FieldType/GatewayBasedStorage.php +++ b/eZ/Publish/Core/FieldType/GatewayBasedStorage.php @@ -87,7 +87,7 @@ protected function getGateway(array $context) ); if (!isset($this->gateways[$context['identifier']])) { - throw new \OutOfBoundsException("No gateway for ${context['identifier']} available."); + throw new \OutOfBoundsException("No gateway for {$context['identifier']} available."); } $gateway = $this->gateways[$context['identifier']]; diff --git a/eZ/Publish/Core/Persistence/Cache/AbstractHandler.php b/eZ/Publish/Core/Persistence/Cache/AbstractHandler.php index f5509d6c0f..9daaec953a 100644 --- a/eZ/Publish/Core/Persistence/Cache/AbstractHandler.php +++ b/eZ/Publish/Core/Persistence/Cache/AbstractHandler.php @@ -66,11 +66,11 @@ public function __construct( /** * Helper for getting multiple cache items in one call and do the id extraction for you. * - * Cache items must be stored with a key in the following format "${keyPrefix}${id}", like "ez-content-info-${id}", + * Cache items must be stored with a key in the following format "{$keyPrefix}{$id}", like "ez-content-info-{$id}", * in order for this method to be able to prefix key on id's and also extract key prefix afterwards. * * It also optionally supports a key suffixs, for use on a variable argument that affects all lookups, - * like translations, i.e. "ez-content-${id}-${translationKey}" where $keySuffixes = [$id => "-${translationKey}"]. + * like translations, i.e. "ez-content-{$id}-{$translationKey}" where $keySuffixes = [$id => "-{$translationKey}"]. * * @param array $ids * @param string $keyPrefix E.g "ez-content-" diff --git a/eZ/Publish/Core/Persistence/Cache/AbstractInMemoryHandler.php b/eZ/Publish/Core/Persistence/Cache/AbstractInMemoryHandler.php index 3cbd1dcb7c..7424f45d26 100644 --- a/eZ/Publish/Core/Persistence/Cache/AbstractInMemoryHandler.php +++ b/eZ/Publish/Core/Persistence/Cache/AbstractInMemoryHandler.php @@ -183,7 +183,7 @@ final protected function getListCacheValue( * Load items from in-memory cache, symfony cache pool or backend in that order. * If not cached the returned objects will be placed in cache. * - * Cache items must be stored with a key in the following format "${keyPrefix}${id}", like "ez-content-info-${id}", + * Cache items must be stored with a key in the following format "{$keyPrefix}{$id}", like "ez-content-info-{$id}", * in order for this method to be able to prefix key on id's and also extract key prefix afterwards. * * @param array $ids diff --git a/eZ/Publish/Core/Persistence/Cache/ContentHandler.php b/eZ/Publish/Core/Persistence/Cache/ContentHandler.php index 4e77e1ddf6..eacaa7fcd8 100644 --- a/eZ/Publish/Core/Persistence/Cache/ContentHandler.php +++ b/eZ/Publish/Core/Persistence/Cache/ContentHandler.php @@ -128,7 +128,7 @@ public function copy($contentId, $versionNo = null, $newOwnerId = null) */ public function load($contentId, $versionNo = null, array $translations = null) { - $keySuffix = $versionNo ? "-${versionNo}-" : '-'; + $keySuffix = $versionNo ? "-{$versionNo}-" : '-'; $keySuffix .= empty($translations) ? self::ALL_TRANSLATIONS_KEY : implode('|', $translations); return $this->getCacheValue( @@ -235,7 +235,7 @@ function () use ($remoteId) { */ public function loadVersionInfo($contentId, $versionNo = null) { - $keySuffix = $versionNo ? "-${versionNo}" : ''; + $keySuffix = $versionNo ? "-{$versionNo}" : ''; $cacheItem = $this->cache->getItem( $this->cacheIdentifierGenerator->generateKey( self::CONTENT_VERSION_INFO_IDENTIFIER, From 2090bf9708f65e8954a59d9f2375b7db3eded3cf Mon Sep 17 00:00:00 2001 From: Nattfarinn Date: Wed, 29 Nov 2023 10:23:09 +0100 Subject: [PATCH 2/6] IBX-5827: Added custom ErrorHandler to hide deprecations in PHP 8.2 --- composer.json | 1 + .../Php82HideDeprecationsErrorHandler.php | 22 ++++++++ .../Php82HideDeprecationsErrorHandlerTest.php | 53 +++++++++++++++++++ 3 files changed, 76 insertions(+) create mode 100644 src/lib/MVC/Symfony/ErrorHandler/Php82HideDeprecationsErrorHandler.php create mode 100644 tests/lib/MVC/Symfony/ErrorHandler/Php82HideDeprecationsErrorHandlerTest.php diff --git a/composer.json b/composer.json index 208d172a7d..f6fa756dc3 100644 --- a/composer.json +++ b/composer.json @@ -27,6 +27,7 @@ "symfony/mime": "^5.3.0", "symfony/translation": "^5.3.0", "symfony/yaml": "^5.3.0", + "symfony/runtime": "^5.3.0", "symfony/security-core": "^5.3.0", "symfony/security-http": "^5.3.0", "symfony/security-bundle": "^5.3.0", diff --git a/src/lib/MVC/Symfony/ErrorHandler/Php82HideDeprecationsErrorHandler.php b/src/lib/MVC/Symfony/ErrorHandler/Php82HideDeprecationsErrorHandler.php new file mode 100644 index 0000000000..a6e0d78458 --- /dev/null +++ b/src/lib/MVC/Symfony/ErrorHandler/Php82HideDeprecationsErrorHandler.php @@ -0,0 +1,22 @@ + 80200) { + error_reporting(E_ALL & ~E_DEPRECATED); + } + } +} diff --git a/tests/lib/MVC/Symfony/ErrorHandler/Php82HideDeprecationsErrorHandlerTest.php b/tests/lib/MVC/Symfony/ErrorHandler/Php82HideDeprecationsErrorHandlerTest.php new file mode 100644 index 0000000000..d1020c1597 --- /dev/null +++ b/tests/lib/MVC/Symfony/ErrorHandler/Php82HideDeprecationsErrorHandlerTest.php @@ -0,0 +1,53 @@ +originalErrorReporting = error_reporting(); + set_error_handler( + $this->originalErrorHandler = set_error_handler( + static function () {} + ) + ); + } + + protected function tearDown(): void + { + error_reporting($this->originalErrorReporting); + set_error_handler($this->originalErrorHandler); + } + + public function testRegister(): void + { + if (PHP_VERSION_ID < 80200) { + $this->markTestSkipped('Does not affect versions below PHP 8.2.0'); + } + + $errorHandler = new Php82HideDeprecationsErrorHandler(); + + $errorHandler::register(true); + $debugErrorReporting = error_reporting(); + + $errorHandler::register(false); + $noDebugErrorReporting = error_reporting(); + + $this->assertSame(E_ALL & ~E_DEPRECATED, $debugErrorReporting); + $this->assertSame(E_ALL & ~E_DEPRECATED, $noDebugErrorReporting); + } +} From 45f88450063313f5a27e20072074db471a5a8071 Mon Sep 17 00:00:00 2001 From: Nattfarinn Date: Wed, 29 Nov 2023 10:28:58 +0100 Subject: [PATCH 3/6] fix: Split test into separate cases --- .../Php82HideDeprecationsErrorHandlerTest.php | 32 +++++++++---------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/tests/lib/MVC/Symfony/ErrorHandler/Php82HideDeprecationsErrorHandlerTest.php b/tests/lib/MVC/Symfony/ErrorHandler/Php82HideDeprecationsErrorHandlerTest.php index d1020c1597..857fedbe65 100644 --- a/tests/lib/MVC/Symfony/ErrorHandler/Php82HideDeprecationsErrorHandlerTest.php +++ b/tests/lib/MVC/Symfony/ErrorHandler/Php82HideDeprecationsErrorHandlerTest.php @@ -14,40 +14,38 @@ final class Php82HideDeprecationsErrorHandlerTest extends TestCase { private int $originalErrorReporting; - /** @var callable|null */ - private $originalErrorHandler; - protected function setUp(): void { $this->originalErrorReporting = error_reporting(); - set_error_handler( - $this->originalErrorHandler = set_error_handler( - static function () {} - ) - ); } protected function tearDown(): void { error_reporting($this->originalErrorReporting); - set_error_handler($this->originalErrorHandler); + restore_error_handler(); } - public function testRegister(): void + public function testRegisterDebug(): void { if (PHP_VERSION_ID < 80200) { $this->markTestSkipped('Does not affect versions below PHP 8.2.0'); } - $errorHandler = new Php82HideDeprecationsErrorHandler(); + Php82HideDeprecationsErrorHandler::register(true); + $errorReporting = error_reporting(); + + $this->assertSame(E_ALL & ~E_DEPRECATED, $errorReporting); + } - $errorHandler::register(true); - $debugErrorReporting = error_reporting(); + public function testRegisterNoDebug(): void + { + if (PHP_VERSION_ID < 80200) { + $this->markTestSkipped('Does not affect versions below PHP 8.2.0'); + } - $errorHandler::register(false); - $noDebugErrorReporting = error_reporting(); + Php82HideDeprecationsErrorHandler::register(false); + $errorReporting = error_reporting(); - $this->assertSame(E_ALL & ~E_DEPRECATED, $debugErrorReporting); - $this->assertSame(E_ALL & ~E_DEPRECATED, $noDebugErrorReporting); + $this->assertSame(E_ALL & ~E_DEPRECATED, $errorReporting); } } From f5affc9a92852f227d763af7e9a081323cad7bda Mon Sep 17 00:00:00 2001 From: Nattfarinn Date: Wed, 29 Nov 2023 10:33:32 +0100 Subject: [PATCH 4/6] fix: Support PHP 7.3 --- .../ErrorHandler/Php82HideDeprecationsErrorHandlerTest.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/lib/MVC/Symfony/ErrorHandler/Php82HideDeprecationsErrorHandlerTest.php b/tests/lib/MVC/Symfony/ErrorHandler/Php82HideDeprecationsErrorHandlerTest.php index 857fedbe65..0014624a18 100644 --- a/tests/lib/MVC/Symfony/ErrorHandler/Php82HideDeprecationsErrorHandlerTest.php +++ b/tests/lib/MVC/Symfony/ErrorHandler/Php82HideDeprecationsErrorHandlerTest.php @@ -12,7 +12,8 @@ final class Php82HideDeprecationsErrorHandlerTest extends TestCase { - private int $originalErrorReporting; + /** @var int */ + private $originalErrorReporting; protected function setUp(): void { From e5e280fcaf67c4074e17a02991f42fe546014a16 Mon Sep 17 00:00:00 2001 From: Nattfarinn Date: Wed, 29 Nov 2023 11:06:51 +0100 Subject: [PATCH 5/6] fix: Coding Standards --- .../Symfony/ErrorHandler/Php82HideDeprecationsErrorHandler.php | 2 +- .../ErrorHandler/Php82HideDeprecationsErrorHandlerTest.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib/MVC/Symfony/ErrorHandler/Php82HideDeprecationsErrorHandler.php b/src/lib/MVC/Symfony/ErrorHandler/Php82HideDeprecationsErrorHandler.php index a6e0d78458..a346434efa 100644 --- a/src/lib/MVC/Symfony/ErrorHandler/Php82HideDeprecationsErrorHandler.php +++ b/src/lib/MVC/Symfony/ErrorHandler/Php82HideDeprecationsErrorHandler.php @@ -6,8 +6,8 @@ */ namespace Ibexa\Core\MVC\Symfony\ErrorHandler; -use Symfony\Component\Runtime\Internal\BasicErrorHandler; use const PHP_VERSION_ID; +use Symfony\Component\Runtime\Internal\BasicErrorHandler; final class Php82HideDeprecationsErrorHandler extends BasicErrorHandler { diff --git a/tests/lib/MVC/Symfony/ErrorHandler/Php82HideDeprecationsErrorHandlerTest.php b/tests/lib/MVC/Symfony/ErrorHandler/Php82HideDeprecationsErrorHandlerTest.php index 0014624a18..fae3145978 100644 --- a/tests/lib/MVC/Symfony/ErrorHandler/Php82HideDeprecationsErrorHandlerTest.php +++ b/tests/lib/MVC/Symfony/ErrorHandler/Php82HideDeprecationsErrorHandlerTest.php @@ -7,8 +7,8 @@ namespace Ibexa\Tests\Core\MVC\Symfony\ErrorHandler; use Ibexa\Core\MVC\Symfony\ErrorHandler\Php82HideDeprecationsErrorHandler; -use PHPUnit\Framework\TestCase; use const PHP_VERSION_ID; +use PHPUnit\Framework\TestCase; final class Php82HideDeprecationsErrorHandlerTest extends TestCase { From c25ce8e41b8dd846efc39a3e09c622ee12e97979 Mon Sep 17 00:00:00 2001 From: Nattfarinn Date: Thu, 30 Nov 2023 09:44:38 +0100 Subject: [PATCH 6/6] fix: Code review --- composer.json | 4 ++-- .../Php82HideDeprecationsErrorHandler.php | 8 +++++--- .../Php82HideDeprecationsErrorHandlerTest.php | 16 ++++++---------- 3 files changed, 13 insertions(+), 15 deletions(-) rename src/{lib => contracts}/MVC/Symfony/ErrorHandler/Php82HideDeprecationsErrorHandler.php (71%) diff --git a/composer.json b/composer.json index f6fa756dc3..8cbab703f1 100644 --- a/composer.json +++ b/composer.json @@ -27,7 +27,6 @@ "symfony/mime": "^5.3.0", "symfony/translation": "^5.3.0", "symfony/yaml": "^5.3.0", - "symfony/runtime": "^5.3.0", "symfony/security-core": "^5.3.0", "symfony/security-http": "^5.3.0", "symfony/security-bundle": "^5.3.0", @@ -70,7 +69,8 @@ "matthiasnoback/symfony-dependency-injection-test": "^4.1", "symfony/phpunit-bridge": "^5.1", "symfony/proxy-manager-bridge": "^5.3", - "phpstan/phpstan": "^1.2" + "phpstan/phpstan": "^1.2", + "symfony/runtime": "^5.3.0" }, "conflict": { "friendsofphp/php-cs-fixer": "3.5.0", diff --git a/src/lib/MVC/Symfony/ErrorHandler/Php82HideDeprecationsErrorHandler.php b/src/contracts/MVC/Symfony/ErrorHandler/Php82HideDeprecationsErrorHandler.php similarity index 71% rename from src/lib/MVC/Symfony/ErrorHandler/Php82HideDeprecationsErrorHandler.php rename to src/contracts/MVC/Symfony/ErrorHandler/Php82HideDeprecationsErrorHandler.php index a346434efa..d9521c6c68 100644 --- a/src/lib/MVC/Symfony/ErrorHandler/Php82HideDeprecationsErrorHandler.php +++ b/src/contracts/MVC/Symfony/ErrorHandler/Php82HideDeprecationsErrorHandler.php @@ -4,16 +4,18 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ -namespace Ibexa\Core\MVC\Symfony\ErrorHandler; +declare(strict_types=1); + +namespace Ibexa\Contracts\Core\MVC\Symfony\ErrorHandler; use const PHP_VERSION_ID; use Symfony\Component\Runtime\Internal\BasicErrorHandler; -final class Php82HideDeprecationsErrorHandler extends BasicErrorHandler +final class Php82HideDeprecationsErrorHandler { public static function register(bool $debug): void { - parent::register($debug); + BasicErrorHandler::register($debug); if (PHP_VERSION_ID > 80200) { error_reporting(E_ALL & ~E_DEPRECATED); diff --git a/tests/lib/MVC/Symfony/ErrorHandler/Php82HideDeprecationsErrorHandlerTest.php b/tests/lib/MVC/Symfony/ErrorHandler/Php82HideDeprecationsErrorHandlerTest.php index fae3145978..a4eadebe86 100644 --- a/tests/lib/MVC/Symfony/ErrorHandler/Php82HideDeprecationsErrorHandlerTest.php +++ b/tests/lib/MVC/Symfony/ErrorHandler/Php82HideDeprecationsErrorHandlerTest.php @@ -4,12 +4,16 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); + namespace Ibexa\Tests\Core\MVC\Symfony\ErrorHandler; -use Ibexa\Core\MVC\Symfony\ErrorHandler\Php82HideDeprecationsErrorHandler; -use const PHP_VERSION_ID; +use Ibexa\Contracts\Core\MVC\Symfony\ErrorHandler\Php82HideDeprecationsErrorHandler; use PHPUnit\Framework\TestCase; +/** + * @requires PHP >= 8.2.0 + */ final class Php82HideDeprecationsErrorHandlerTest extends TestCase { /** @var int */ @@ -28,10 +32,6 @@ protected function tearDown(): void public function testRegisterDebug(): void { - if (PHP_VERSION_ID < 80200) { - $this->markTestSkipped('Does not affect versions below PHP 8.2.0'); - } - Php82HideDeprecationsErrorHandler::register(true); $errorReporting = error_reporting(); @@ -40,10 +40,6 @@ public function testRegisterDebug(): void public function testRegisterNoDebug(): void { - if (PHP_VERSION_ID < 80200) { - $this->markTestSkipped('Does not affect versions below PHP 8.2.0'); - } - Php82HideDeprecationsErrorHandler::register(false); $errorReporting = error_reporting();