Skip to content

Commit 4567783

Browse files
committed
Helpers: changed WRAP_LENGTH to 100, added INDENT_LENGTH
1 parent 6a3d9cf commit 4567783

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
@@ -21,9 +21,11 @@ final class Helpers
2121

2222
public const PHP_IDENT = '[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*';
2323

24-
private const MAX_DEPTH = 50;
24+
public const WRAP_LENGTH = 100;
25+
26+
public const INDENT_LENGTH = 4;
2527

26-
private const WRAP_LENGTH = 70;
28+
private const MAX_DEPTH = 50;
2729

2830

2931
/**
@@ -83,20 +85,21 @@ private static function _dump(&$var, int $level = 0)
8385

8486
} else {
8587
$out = '';
86-
$outAlt = "\n$space";
88+
$outWrapped = "\n$space";
8789
$var[$marker] = true;
8890
$counter = 0;
8991
foreach ($var as $k => &$v) {
9092
if ($k !== $marker) {
9193
$item = ($k === $counter ? '' : self::_dump($k, $level + 1) . ' => ') . self::_dump($v, $level + 1);
9294
$counter = is_int($k) ? max($k + 1, $counter) : $counter;
9395
$out .= ($out === '' ? '' : ', ') . $item;
94-
$outAlt .= "\t$item,\n$space";
96+
$outWrapped .= "\t$item,\n$space";
9597
}
9698
}
9799
unset($var[$marker]);
98100
}
99-
return '[' . (strpos($out, "\n") === false && strlen($out) < self::WRAP_LENGTH ? $out : $outAlt) . ']';
101+
$wrap = strpos($out, "\n") !== false || strlen($out) > self::WRAP_LENGTH - $level * self::INDENT_LENGTH;
102+
return '[' . ($wrap ? $outWrapped : $out) . ']';
100103

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

tests/PhpGenerator/Helpers.dump().phpt

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

4040
Assert::same('[1, 2, 3]', Helpers::dump([1, 2, 3]));
4141
Assert::same("['a', 7 => 'b', 'c', '9a' => 'd', 'e']", Helpers::dump(['a', 7 => 'b', 'c', '9a' => 'd', 9 => 'e']));
42-
Assert::same("[\n\t[\n\t\t'a',\n\t\t'loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong',\n\t],\n]", Helpers::dump([['a', 'loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong']]));
42+
Assert::match("[
43+
[
44+
'a',
45+
'loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong',
46+
],
47+
]", Helpers::dump([['a', 'loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong']]));
4348
Assert::same("['a' => 1, [\"\\r\" => \"\\r\", 2], 3]", Helpers::dump(['a' => 1, ["\r" => "\r", 2], 3]));
4449

4550
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
@@ -21,8 +21,9 @@ Assert::same('func(1 ? 2 : 3)', Helpers::formatArgs('func(1 \? 2 : 3)', []));
2121
Assert::same('func([1, 2])', Helpers::formatArgs('func(?)', [[1, 2]]));
2222
Assert::same('func(1, 2)', Helpers::formatArgs('func(...?)', [[1, 2]]));
2323
Assert::same('func(1, 2)', Helpers::formatArgs('func(?*)', [[1, 2]])); // old way
24-
Assert::same(
25-
"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)",
24+
Assert::match(
25+
'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,
26+
35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50)',
2627
Helpers::formatArgs('func(?*)', [range(10, 50)])
2728
);
2829

0 commit comments

Comments
 (0)