Skip to content

Commit cea734d

Browse files
committed
Make echoOrYield methods static
Signed-off-by: Maurício Meneghini Fauth <[email protected]>
1 parent d74a7e3 commit cea734d

File tree

3 files changed

+25
-25
lines changed

3 files changed

+25
-25
lines changed

src/Node/TransNode.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ public function compile(Compiler $compiler)
145145

146146
if ($vars) {
147147
$compiler
148-
->raw($this->echoOrYield() . ' strtr(' . $function . '(');
148+
->raw(self::echoOrYield() . ' strtr(' . $function . '(');
149149

150150
if ($hasDomain) {
151151
[$domain] = $this->compileString($this->getNode('domain'));
@@ -195,7 +195,7 @@ public function compile(Compiler $compiler)
195195
$compiler->raw("));\n");
196196
} else {
197197
$compiler
198-
->raw($this->echoOrYield() . ' ' . $function . '(');
198+
->raw(self::echoOrYield() . ' ' . $function . '(');
199199

200200
if ($hasDomain) {
201201
[$domain] = $this->compileString($this->getNode('domain'));
@@ -326,7 +326,7 @@ protected function getTransFunction(bool $hasPlural, bool $hasContext, bool $has
326326
return $functionPrefix . ($hasContext ? 'pgettext' : 'gettext');
327327
}
328328

329-
private function echoOrYield(): string
329+
private static function echoOrYield(): string
330330
{
331331
return class_exists(YieldReady::class) ? 'yield' : 'echo';
332332
}

test/Node/MoTranslatorTransTest.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
class MoTranslatorTransTest extends NodeTestCase
3030
{
31-
private function echoOrYield(): string
31+
private static function echoOrYield(): string
3232
{
3333
return class_exists(YieldReady::class) ? 'yield' : 'echo';
3434
}
@@ -91,7 +91,7 @@ public function getTests(): array
9191
$node = new TransNode($body, null, null, null, null, $domain, 0);
9292
$tests[] = [
9393
$node,
94-
sprintf($this->echoOrYield() . ' _dgettext("coredomain", %s);', $this->getVariableGetter('foo')),
94+
sprintf(self::echoOrYield() . ' _dgettext("coredomain", %s);', $this->getVariableGetter('foo')),
9595
];
9696

9797
$body = new NameExpression('foo', 0);
@@ -105,7 +105,7 @@ public function getTests(): array
105105
$tests[] = [
106106
$node,
107107
sprintf(
108-
$this->echoOrYield() . ' _dpgettext("coredomain", "The context", %s);',
108+
self::echoOrYield() . ' _dpgettext("coredomain", "The context", %s);',
109109
$this->getVariableGetter('foo')
110110
),
111111
];
@@ -119,7 +119,7 @@ public function getTests(): array
119119
$tests[] = [
120120
$node,
121121
sprintf(
122-
$this->echoOrYield() . ' strtr(_gettext("J\'ai %%foo%% pommes"), array("%%foo%%" => %s, ));',
122+
self::echoOrYield() . ' strtr(_gettext("J\'ai %%foo%% pommes"), array("%%foo%%" => %s, ));',
123123
$this->getVariableGetter('foo')
124124
),
125125
];
@@ -141,7 +141,7 @@ public function getTests(): array
141141
$tests[] = [
142142
$node,
143143
sprintf(
144-
$this->echoOrYield() . ' strtr(_ngettext("Hey %%name%%, I have one apple", "Hey %%name%%,'
144+
self::echoOrYield() . ' strtr(_ngettext("Hey %%name%%, I have one apple", "Hey %%name%%,'
145145
. ' I have %%count%% apples", abs(12)), array("%%name%%" => %s,'
146146
. ' "%%name%%" => %s, "%%count%%" => abs(12), ));',
147147
$this->getVariableGetter('name'),
@@ -161,7 +161,7 @@ public function getTests(): array
161161
$tests[] = [
162162
$node,
163163
sprintf(
164-
$this->echoOrYield()
164+
self::echoOrYield()
165165
. ' strtr(_pgettext("The context", "J\'ai %%foo%% pommes"), array("%%foo%%" => %s, ));',
166166
$this->getVariableGetter('foo')
167167
),
@@ -187,7 +187,7 @@ public function getTests(): array
187187
$tests[] = [
188188
$node,
189189
sprintf(
190-
$this->echoOrYield()
190+
self::echoOrYield()
191191
. ' strtr(_npgettext("The context", "Hey %%name%%, I have one apple", "Hey %%name%%,'
192192
. ' I have %%count%% apples", abs(12)), array("%%name%%" => %s,'
193193
. ' "%%name%%" => %s, "%%count%%" => abs(12), ));',
@@ -211,7 +211,7 @@ public function getTests(): array
211211
$tests[] = [
212212
$node,
213213
sprintf(
214-
$this->echoOrYield()
214+
self::echoOrYield()
215215
. ' strtr(_dpgettext("mydomain", "The context", "J\'ai %%foo%% pommes"), array("%%foo%%" => %s, ));',
216216
$this->getVariableGetter('foo')
217217
),
@@ -240,7 +240,7 @@ public function getTests(): array
240240
$tests[] = [
241241
$node,
242242
sprintf(
243-
$this->echoOrYield()
243+
self::echoOrYield()
244244
. ' strtr(_dnpgettext("mydomain", "The context", "Hey %%name%%, I have one apple",'
245245
. ' "Hey %%name%%, I have %%count%% apples", abs(12)), array("%%name%%" => %s,'
246246
. ' "%%name%%" => %s, "%%count%%" => abs(12), ));',

test/Node/TransTest.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
class TransTest extends NodeTestCase
3131
{
32-
private function echoOrYield(): string
32+
private static function echoOrYield(): string
3333
{
3434
return class_exists(YieldReady::class) ? 'yield' : 'echo';
3535
}
@@ -97,7 +97,7 @@ public function testEnableDebugNotEnabled(): void
9797
$sourceCode = $compiler->compile($node)->getSource();
9898
$this->assertSame(
9999
'// custom: Notes for translators' . "\n"
100-
. $this->echoOrYield() . ' strtr(ngettext("There is 1 pending task",'
100+
. self::echoOrYield() . ' strtr(ngettext("There is 1 pending task",'
101101
. ' "There are %count% pending tasks", abs(5)), array("%count%" => abs(5), ));' . "\n",
102102
$sourceCode
103103
);
@@ -126,7 +126,7 @@ public function testEnableDebugEnabled(): void
126126
$sourceCode = $compiler->compile($node)->getSource();
127127
$this->assertSame(
128128
'// line 80' . "\n" . '// custom: Notes for translators' . "\n"
129-
. $this->echoOrYield() . ' strtr(ngettext("There'
129+
. self::echoOrYield() . ' strtr(ngettext("There'
130130
. ' is 1 pending task", "There are %count% pending tasks", abs(5)), array("%count%" => abs(5), ));' . "\n",
131131
$sourceCode
132132
);
@@ -149,22 +149,22 @@ public function getTests(): array
149149
$node = new TransNode($body, null, null, null, null, $domain, 0);
150150
$tests[] = [
151151
$node,
152-
sprintf($this->echoOrYield() . ' dgettext("coredomain", %s);', $this->getVariableGetter('foo')),
152+
sprintf(self::echoOrYield() . ' dgettext("coredomain", %s);', $this->getVariableGetter('foo')),
153153
];
154154

155155
$body = new NameExpression('foo', 0);
156156
$node = new TransNode($body, null, null, null, null, null, 0);
157-
$tests[] = [$node, sprintf($this->echoOrYield() . ' gettext(%s);', $this->getVariableGetter('foo'))];
157+
$tests[] = [$node, sprintf(self::echoOrYield() . ' gettext(%s);', $this->getVariableGetter('foo'))];
158158

159159
$body = new ConstantExpression('Hello', 0);
160160
$node = new TransNode($body, null, null, null, null, null, 0);
161-
$tests[] = [$node, $this->echoOrYield() . ' gettext("Hello");'];
161+
$tests[] = [$node, self::echoOrYield() . ' gettext("Hello");'];
162162

163163
$body = new Node([
164164
new TextNode('Hello', 0),
165165
], [], 0);
166166
$node = new TransNode($body, null, null, null, null, null, 0);
167-
$tests[] = [$node, $this->echoOrYield() . ' gettext("Hello");'];
167+
$tests[] = [$node, self::echoOrYield() . ' gettext("Hello");'];
168168

169169
$body = new Node([
170170
new TextNode('J\'ai ', 0),
@@ -175,7 +175,7 @@ public function getTests(): array
175175
$tests[] = [
176176
$node,
177177
sprintf(
178-
$this->echoOrYield() . ' strtr(gettext("J\'ai %%foo%% pommes"), array("%%foo%%" => %s, ));',
178+
self::echoOrYield() . ' strtr(gettext("J\'ai %%foo%% pommes"), array("%%foo%%" => %s, ));',
179179
$this->getVariableGetter('foo')
180180
),
181181
];
@@ -197,7 +197,7 @@ public function getTests(): array
197197
$tests[] = [
198198
$node,
199199
sprintf(
200-
$this->echoOrYield() . ' strtr(ngettext("Hey %%name%%, I have one apple", "Hey %%name%%, I have'
200+
self::echoOrYield() . ' strtr(ngettext("Hey %%name%%, I have one apple", "Hey %%name%%, I have'
201201
. ' %%count%% apples", abs(12)), array("%%name%%" => %s,'
202202
. ' "%%name%%" => %s, "%%count%%" => abs(12), ));',
203203
$this->getVariableGetter('name'),
@@ -219,7 +219,7 @@ public function getTests(): array
219219
$tests[] = [
220220
$node,
221221
sprintf(
222-
$this->echoOrYield() . ' strtr(gettext("J\'ai %%foo%% pommes"), array("%%foo%%" => %s, ));',
222+
self::echoOrYield() . ' strtr(gettext("J\'ai %%foo%% pommes"), array("%%foo%%" => %s, ));',
223223
$this->getVariableGetter('foo')
224224
),
225225
];
@@ -228,15 +228,15 @@ public function getTests(): array
228228
$body = new ConstantExpression('Hello', 0);
229229
$notes = new TextNode('Notes for translators', 0);
230230
$node = new TransNode($body, null, null, null, $notes, null, 0);
231-
$tests[] = [$node, "// notes: Notes for translators\n" . $this->echoOrYield() . ' gettext("Hello");'];
231+
$tests[] = [$node, "// notes: Notes for translators\n" . self::echoOrYield() . ' gettext("Hello");'];
232232

233233
$body = new ConstantExpression('Hello', 0);
234234
$notes = new TextNode("Notes for translators\nand line breaks", 0);
235235
$node = new TransNode($body, null, null, null, $notes, null, 0);
236236
$tests[] = [
237237
$node,
238238
"// notes: Notes for translators and line breaks\n"
239-
. $this->echoOrYield() . ' gettext("Hello");',
239+
. self::echoOrYield() . ' gettext("Hello");',
240240
];
241241

242242
$count = new ConstantExpression(5, 0);
@@ -251,7 +251,7 @@ public function getTests(): array
251251
$tests[] = [
252252
$node,
253253
'// notes: Notes for translators' . "\n"
254-
. $this->echoOrYield() . ' strtr(ngettext("There is 1 pending task",'
254+
. self::echoOrYield() . ' strtr(ngettext("There is 1 pending task",'
255255
. ' "There are %count% pending tasks", abs(5)), array("%count%" => abs(5), ));',
256256
];
257257

0 commit comments

Comments
 (0)