From d37ddedd909dd99a5d3a337d17331761a10155ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20B=C3=BCnte?= Date: Mon, 30 May 2022 05:04:51 +0200 Subject: [PATCH] Fix i18nTextCollector produces corrupt output / namespaces when running under PHP8.0 (#10228) * FIX i18nTextCollector produces corrupt output / namespaces when running under PHP8.0 --- src/i18n/TextCollection/i18nTextCollector.php | 9 +-------- tests/php/i18n/i18nTextCollectorTest.php | 8 +++++++- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/i18n/TextCollection/i18nTextCollector.php b/src/i18n/TextCollection/i18nTextCollector.php index b95bde50d95..e7d5e95fb15 100644 --- a/src/i18n/TextCollection/i18nTextCollector.php +++ b/src/i18n/TextCollection/i18nTextCollector.php @@ -571,20 +571,13 @@ public function collectFromCode($content, $fileName, Module $module) if (is_array($token)) { list($id, $text) = $token; - // PHP 8 namespace tokens - if (\defined('T_NAME_QUALIFIED') && in_array($id, [T_NAME_FULLY_QUALIFIED, T_NAME_QUALIFIED])) { - $inNamespace = true; - $currentClass[] = $text; - continue; - } - // Check class if ($id === T_NAMESPACE) { $inNamespace = true; $currentClass = []; continue; } - if ($inNamespace && $id === T_STRING) { + if ($inNamespace && ($id === T_STRING || (defined('T_NAME_QUALIFIED') && $id === T_NAME_QUALIFIED))) { $currentClass[] = $text; continue; } diff --git a/tests/php/i18n/i18nTextCollectorTest.php b/tests/php/i18n/i18nTextCollectorTest.php index e9d22805a05..6812c9cc6fe 100644 --- a/tests/php/i18n/i18nTextCollectorTest.php +++ b/tests/php/i18n/i18nTextCollectorTest.php @@ -300,9 +300,14 @@ public function testCollectFromCodeNamespace() assertEquals( [ 'SilverStripe\\Framework\\Core\\MyClass.NEWLINES' => "New Lines",