Skip to content

Commit 093f4b9

Browse files
committed
Improvements in PhpCode extractor
1 parent 6dada5d commit 093f4b9

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

Gettext/Extractors/PhpCode.php

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,22 @@ class PhpCode extends Extractor {
1515

1616
static public function parse ($file, Entries $entries) {
1717
$tokens = token_get_all(file_get_contents($file));
18+
$count = count($tokens);
1819
$functions = array();
19-
$currentFunction = null;
20+
$bufferFunctions = array();
21+
22+
for ($k = 0; $k < $count; $k++) {
23+
$value = $tokens[$k];
2024

21-
foreach ($tokens as $k => $value) {
2225
if (is_string($value)) {
23-
if ($value === ')' && $currentFunction) {
24-
$functions[] = $currentFunction;
25-
$currentFunction = null;
26+
if ($value === ')' && isset($bufferFunctions[0])) {
27+
$functions[] = array_shift($bufferFunctions);
2628
}
2729

2830
continue;
2931
}
3032

31-
if ($currentFunction && ($value[0] === T_CONSTANT_ENCAPSED_STRING)) {
33+
if (isset($bufferFunctions[0]) && ($value[0] === T_CONSTANT_ENCAPSED_STRING)) {
3234
$val = $value[1];
3335

3436
if ($val[0] === '"') {
@@ -37,12 +39,13 @@ static public function parse ($file, Entries $entries) {
3739
$val = str_replace("\\'", "'", $val);
3840
}
3941

40-
$currentFunction[] = substr($val, 1, -1);
42+
$bufferFunctions[0][] = substr($val, 1, -1);
4143
continue;
4244
}
4345

44-
if (!$currentFunction && ($value[0] === T_STRING) && is_string($tokens[$k + 1]) && ($tokens[$k + 1] === '(')) {
45-
$currentFunction = array($value[1], $value[2]);
46+
if (($value[0] === T_STRING) && is_string($tokens[$k + 1]) && ($tokens[$k + 1] === '(')) {
47+
array_unshift($bufferFunctions, array($value[1], $value[2]));
48+
$k++;
4649
continue;
4750
}
4851
}

0 commit comments

Comments
 (0)