From a0b76c6c8ea277b07d58fa75dcacf102a203ad51 Mon Sep 17 00:00:00 2001 From: Klaus Purer <klaus.purer@protonmail.ch> Date: Mon, 17 Jul 2023 17:36:49 +0200 Subject: [PATCH] Revert "feat(FunctionT): Allow passing constants to t() (#3326197 by Murz)" --- .../Drupal/Sniffs/Semantics/FunctionTSniff.php | 5 +---- tests/Drupal/Semantics/FunctionTUnitTest.inc | 10 ---------- 2 files changed, 1 insertion(+), 14 deletions(-) diff --git a/coder_sniffer/Drupal/Sniffs/Semantics/FunctionTSniff.php b/coder_sniffer/Drupal/Sniffs/Semantics/FunctionTSniff.php index 30560030..4da9955f 100644 --- a/coder_sniffer/Drupal/Sniffs/Semantics/FunctionTSniff.php +++ b/coder_sniffer/Drupal/Sniffs/Semantics/FunctionTSniff.php @@ -75,10 +75,7 @@ class FunctionTSniff extends FunctionCall return; } - if ($tokens[$argument['start']]['code'] !== T_CONSTANT_ENCAPSED_STRING - && $tokens[$argument['start']]['code'] !== T_STRING - && $tokens[$argument['start']]['code'] !== T_SELF - ) { + if ($tokens[$argument['start']]['code'] !== T_CONSTANT_ENCAPSED_STRING) { // Not a translatable string literal. $warning = 'Only string literals should be passed to t() where possible'; $phpcsFile->addWarning($warning, $argument['start'], 'NotLiteralString'); diff --git a/tests/Drupal/Semantics/FunctionTUnitTest.inc b/tests/Drupal/Semantics/FunctionTUnitTest.inc index 02aff86c..0945ef06 100644 --- a/tests/Drupal/Semantics/FunctionTUnitTest.inc +++ b/tests/Drupal/Semantics/FunctionTUnitTest.inc @@ -34,14 +34,4 @@ class Test { return new TranslationWrapper(' Do not start with a space'); } - public function testConstants() { - // Using constants in t() should be allowed. - $x = t(self::FOO); - } - } - -// Using constants in t() should be allowed. -const FOO2 = 'bar2'; -$x = t(FOO2); -$x = t(Test::FOO); -- GitLab