Skip to content

Commit dd03b95

Browse files
committed
fix warnings parsing phpcode #22
1 parent 44ea33c commit dd03b95

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

Gettext/Extractors/PhpCode.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,23 +72,28 @@ public static function parse($file, Entries $entries)
7272

7373
$line = array_shift($args);
7474

75-
if (!isset($args[0])) {
76-
continue;
77-
}
78-
7975
switch (self::$functions[$function]) {
8076
case '__':
77+
if (!isset($args[0])) {
78+
continue 2;
79+
}
8180
$original = $args[0];
8281
$translation = $entries->find('', $original) ?: $entries->insert('', $original);
8382
break;
8483

8584
case 'n__':
85+
if (!isset($args[1])) {
86+
continue 2;
87+
}
8688
$original = $args[0];
8789
$plural = $args[1];
8890
$translation = $entries->find('', $original, $plural) ?: $entries->insert('', $original, $plural);
8991
break;
9092

9193
case 'p__':
94+
if (!isset($args[1])) {
95+
continue 2;
96+
}
9297
$context = $args[0];
9398
$original = $args[1];
9499
$translation = $entries->find($context, $original) ?: $entries->insert($context, $original);

tests/files/phpCode-example.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
<div>
66
<p><?php __($var); ?></p>
7+
<p><?php p__('context', $var); ?></p>
78
<p><?php __('text 2'); ?></p>
89
<p><?php __('text 3 (with parenthesis)'); ?></p>
910
<p><?php __('text 4 "with double quotes"'); ?></p>

0 commit comments

Comments
 (0)