Skip to content

Commit 059135a

Browse files
committed
Helpers::formatArgs() ...? is substitution for ?*
1 parent 0ca50a7 commit 059135a

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

src/PhpGenerator/Helpers.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ public static function format($statement, ...$args)
165165
*/
166166
public static function formatArgs($statement, array $args)
167167
{
168-
$tokens = preg_split('#(\$\?|->\?|::\?|\?\*|\?)#', $statement, -1, PREG_SPLIT_DELIM_CAPTURE);
168+
$tokens = preg_split('#(\.\.\.\?|\$\?|->\?|::\?|\?\*|\?)#', $statement, -1, PREG_SPLIT_DELIM_CAPTURE);
169169
$res = '';
170170
foreach ($tokens as $n => $token) {
171171
if ($n % 2 === 0) {
@@ -174,7 +174,7 @@ public static function formatArgs($statement, array $args)
174174
throw new Nette\InvalidArgumentException('Insufficient number of arguments.');
175175
} elseif ($token === '?') {
176176
$res .= self::dump(array_shift($args));
177-
} elseif ($token === '?*') {
177+
} elseif ($token === '...?' || $token === '?*') {
178178
$arg = array_shift($args);
179179
if (!is_array($arg)) {
180180
throw new Nette\InvalidArgumentException('Argument must be an array.');

tests/PhpGenerator/Helpers.format.phpt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,15 @@ Assert::same('func(1)', Helpers::format('func(?)', 1, 2));
1717
Assert::same('func', Helpers::formatArgs('func', [1, 2]));
1818
Assert::same('func(1)', Helpers::formatArgs('func(?)', [1, 2]));
1919
Assert::same('func([1, 2])', Helpers::formatArgs('func(?)', [[1, 2]]));
20-
Assert::same('func(1, 2)', Helpers::formatArgs('func(?*)', [[1, 2]]));
20+
Assert::same('func(1, 2)', Helpers::formatArgs('func(...?)', [[1, 2]]));
21+
Assert::same('func(1, 2)', Helpers::formatArgs('func(?*)', [[1, 2]])); // old way
2122
Assert::same(
2223
"func(10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26,\n\t27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44,\n\t45, 46, 47, 48, 49, 50)",
2324
Helpers::formatArgs('func(?*)', [range(10, 50)])
2425
);
2526

2627
Assert::exception(function () {
27-
Helpers::formatArgs('func(?*)', [1, 2]);
28+
Helpers::formatArgs('func(...?)', [1, 2]);
2829
}, Nette\InvalidArgumentException::class, 'Argument must be an array.');
2930

3031
Assert::exception(function () {

0 commit comments

Comments
 (0)