Skip to content

Commit 84bea01

Browse files
committed
Helpers: changed WRAP_LENGTH to 100, added INDENT_LENGTH
1 parent 02fa926 commit 84bea01

File tree

3 files changed

+17
-8
lines changed

3 files changed

+17
-8
lines changed

src/PhpGenerator/Helpers.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,11 @@ class Helpers
1919

2020
const PHP_IDENT = '[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*';
2121

22-
const MAX_DEPTH = 50;
22+
const WRAP_LENGTH = 100;
23+
24+
const INDENT_LENGTH = 4;
2325

24-
const WRAP_LENGTH = 70;
26+
const MAX_DEPTH = 50;
2527

2628

2729
/**
@@ -82,20 +84,21 @@ private static function _dump(&$var, $level = 0)
8284

8385
} else {
8486
$out = '';
85-
$outAlt = "\n$space";
87+
$outWrapped = "\n$space";
8688
$var[$marker] = true;
8789
$counter = 0;
8890
foreach ($var as $k => &$v) {
8991
if ($k !== $marker) {
9092
$item = ($k === $counter ? '' : self::_dump($k, $level + 1) . ' => ') . self::_dump($v, $level + 1);
9193
$counter = is_int($k) ? max($k + 1, $counter) : $counter;
9294
$out .= ($out === '' ? '' : ', ') . $item;
93-
$outAlt .= "\t$item,\n$space";
95+
$outWrapped .= "\t$item,\n$space";
9496
}
9597
}
9698
unset($var[$marker]);
9799
}
98-
return '[' . (strpos($out, "\n") === false && strlen($out) < self::WRAP_LENGTH ? $out : $outAlt) . ']';
100+
$wrap = strpos($out, "\n") !== false || strlen($out) > self::WRAP_LENGTH - $level * self::INDENT_LENGTH;
101+
return '[' . ($wrap ? $outWrapped : $out) . ']';
99102

100103
} elseif ($var instanceof \Serializable) {
101104
$var = serialize($var);

tests/PhpGenerator/Helpers.dump().phpt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,12 @@ Assert::same('[$s]', Helpers::dump([new PhpLiteral('$s')]));
3737

3838
Assert::same('[1, 2, 3]', Helpers::dump([1, 2, 3]));
3939
Assert::same("['a', 7 => 'b', 'c', '9a' => 'd', 'e']", Helpers::dump(['a', 7 => 'b', 'c', '9a' => 'd', 9 => 'e']));
40-
Assert::same("[\n\t[\n\t\t'a',\n\t\t'loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong',\n\t],\n]", Helpers::dump([['a', 'loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong']]));
40+
Assert::match("[
41+
[
42+
'a',
43+
'loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong',
44+
],
45+
]", Helpers::dump([['a', 'loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong']]));
4146
Assert::same("['a' => 1, [\"\\r\" => \"\\r\", 2], 3]", Helpers::dump(['a' => 1, ["\r" => "\r", 2], 3]));
4247

4348
Assert::same("(object) [\n\t'a' => 1,\n\t'b' => 2,\n]", Helpers::dump((object) ['a' => 1, 'b' => 2]));

tests/PhpGenerator/Helpers.format.phpt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@ Assert::same('func(1 ? 2 : 3)', Helpers::formatArgs('func(1 \? 2 : 3)', []));
2020
Assert::same('func([1, 2])', Helpers::formatArgs('func(?)', [[1, 2]]));
2121
Assert::same('func(1, 2)', Helpers::formatArgs('func(...?)', [[1, 2]]));
2222
Assert::same('func(1, 2)', Helpers::formatArgs('func(?*)', [[1, 2]])); // old way
23-
Assert::same(
24-
"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)",
23+
Assert::match(
24+
'func(10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34,
25+
35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50)',
2526
Helpers::formatArgs('func(?*)', [range(10, 50)])
2627
);
2728

0 commit comments

Comments
 (0)