Skip to content

Commit c317205

Browse files
committed
fixed concat values #14
1 parent 7a9f21b commit c317205

File tree

4 files changed

+35
-5
lines changed

4 files changed

+35
-5
lines changed

src/PhpNodeVisitor.php

+6
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,12 @@ protected static function getValue(Expr $value)
143143
case 'Scalar_LNumber':
144144
case 'Scalar_DNumber':
145145
return $value->value;
146+
case 'Expr_BinaryOp_Concat':
147+
$values = [];
148+
foreach ($value->getSubNodeNames() as $name) {
149+
$values[] = static::getValue($value->$name);
150+
}
151+
return implode('', $values);
146152
case 'Expr_Array':
147153
$arr = [];
148154

src/PhpScanner.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33

44
namespace Gettext\Scanner;
55

6-
use Gettext\Translations;
76
use Gettext\Translation;
7+
use Gettext\Translations;
88

99
/**
1010
* Class to scan PHP files and get gettext translations
@@ -55,10 +55,10 @@ protected function saveTranslation(
5555
$original = $translation->getOriginal();
5656

5757
//Check if it includes a sprintf
58-
if (strpos($original, "%") !== false) {
58+
if (strpos($original, '%') !== false) {
5959
// %[argnum$][flags][width][.precision]specifier
6060
if (preg_match('/%(\d+\$)?([\-\+\s0]|\'.)?(\d+)?(\.\d+)?[bcdeEfFgGhHosuxX]/', $original)) {
61-
$translation->getFlags()->add("php-format");
61+
$translation->getFlags()->add('php-format');
6262
}
6363
}
6464

tests/PhpFunctionsScannerTest.php

+21-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public function testPhpFunctionsExtractor()
2323
$code = file_get_contents($file);
2424
$functions = $scanner->scan($code, $file);
2525

26-
$this->assertCount(12, $functions);
26+
$this->assertCount(14, $functions);
2727

2828
//fn1
2929
$function = array_shift($functions);
@@ -167,6 +167,26 @@ public function testPhpFunctionsExtractor()
167167
$this->assertCount(1, $function->getComments());
168168
$comments = $function->getComments();
169169
$this->assertSame('Related comment 5', array_shift($comments));
170+
171+
//fn14
172+
$function = array_shift($functions);
173+
$this->assertSame('fn14', $function->getName());
174+
$this->assertSame(1, $function->countArguments());
175+
$this->assertSame(['Translatable string'], $function->getArguments());
176+
$this->assertSame(32, $function->getLine());
177+
$this->assertSame(32, $function->getLastLine());
178+
$this->assertSame($file, $function->getFilename());
179+
$this->assertCount(0, $function->getComments());
180+
181+
//fn15
182+
$function = array_shift($functions);
183+
$this->assertSame('fn15', $function->getName());
184+
$this->assertSame(1, $function->countArguments());
185+
$this->assertSame(['Translatable long string'], $function->getArguments());
186+
$this->assertSame(33, $function->getLine());
187+
$this->assertSame(34, $function->getLastLine());
188+
$this->assertSame($file, $function->getFilename());
189+
$this->assertCount(0, $function->getComments());
170190
}
171191

172192
public function _testPhpFunctionsScannerWithDisabledComments()

tests/assets/functions.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,8 @@
2727
/* No Related comment 4 */
2828
);
2929
//Related comment 5
30-
$bar = fn13("Translatable string","",["context"=>"Context string", 'foo']);
30+
$bar = fn13("Translatable string","",["context"=>"Context string", 'foo']);
31+
32+
fn14("Translatable " . "string");
33+
fn15("Translatable " . "long "
34+
. "string");

0 commit comments

Comments
 (0)