Skip to content
Snippets Groups Projects
Unverified Commit 1c4a0921 authored by Alexey Korepov's avatar Alexey Korepov Committed by GitHub
Browse files

feat(FunctionT): Allow passing constants to t() (#3326197 by Murz)

parent e4e2e227
No related branches found
No related tags found
No related merge requests found
......@@ -75,7 +75,10 @@ class FunctionTSniff extends FunctionCall
return;
}
if ($tokens[$argument['start']]['code'] !== T_CONSTANT_ENCAPSED_STRING) {
if ($tokens[$argument['start']]['code'] !== T_CONSTANT_ENCAPSED_STRING
&& $tokens[$argument['start']]['code'] !== T_STRING
&& $tokens[$argument['start']]['code'] !== T_SELF
) {
// Not a translatable string literal.
$warning = 'Only string literals should be passed to t() where possible';
$phpcsFile->addWarning($warning, $argument['start'], 'NotLiteralString');
......
......@@ -20,6 +20,7 @@ $x = '<p>' . t('Test') . '</p><p>More text.</p>';
$x = t('Test') . ' (disabled)';
class Test {
const FOO='bar';
public function doSomething() {
return $this->t('This string should avoid backslashes for \'');
......@@ -33,4 +34,15 @@ 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);
......@@ -20,7 +20,7 @@ class FunctionTUnitTest extends CoderSniffUnitTest
*/
protected function getErrorList(string $testFile): array
{
return [29 => 1];
return [30 => 1];
}//end getErrorList()
......@@ -41,9 +41,9 @@ class FunctionTUnitTest extends CoderSniffUnitTest
4 => 1,
17 => 1,
20 => 1,
25 => 1,
29 => 1,
33 => 1,
26 => 1,
30 => 1,
34 => 1,
];
}//end getWarningList()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment