Skip to content

Commit e9f4429

Browse files
committed
Helpers: added WRAP_LENGTH
1 parent 41058dc commit e9f4429

File tree

3 files changed

+5
-4
lines changed

3 files changed

+5
-4
lines changed

src/PhpGenerator/Helpers.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class Helpers
1919

2020
const PHP_IDENT = '[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*';
2121
const MAX_DEPTH = 50;
22+
const WRAP_LENGTH = 70;
2223

2324

2425
/**
@@ -92,7 +93,7 @@ private static function _dump(& $var, $level = 0)
9293
}
9394
unset($var[$marker]);
9495
}
95-
return '[' . (strpos($out, "\n") === FALSE && strlen($out) < 40 ? $out : $outAlt) . ']';
96+
return '[' . (strpos($out, "\n") === FALSE && strlen($out) < self::WRAP_LENGTH ? $out : $outAlt) . ']';
9697

9798
} elseif ($var instanceof \Serializable) {
9899
$var = serialize($var);
@@ -176,7 +177,7 @@ public static function formatArgs($statement, array $args)
176177
$sep = '';
177178
foreach ($arg as $tmp) {
178179
$s .= $sep . self::dump($tmp);
179-
$sep = strlen($s) - strrpos($s, "\n") > 100 ? ",\n\t" : ', ';
180+
$sep = strlen($s) - strrpos($s, "\n") > self::WRAP_LENGTH ? ",\n\t" : ', ';
180181
}
181182
$statement = $s . substr($statement, $a + 2);
182183
$a = strlen($s);

tests/PhpGenerator/Helpers.dump().phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ 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'loooooooooooooooooooooooooooooooooong',\n\t],\n]", Helpers::dump([['a', 'loooooooooooooooooooooooooooooooooong']]));
40+
Assert::same("[\n\t[\n\t\t'a',\n\t\t'loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong',\n\t],\n]", Helpers::dump([['a', 'loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong']]));
4141
Assert::same("['a' => 1, [\"\\r\" => \"\\r\", 2], 3]", Helpers::dump(['a' => 1, ["\r" => "\r", 2], 3]));
4242

4343
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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Assert::same('func(1)', Helpers::formatArgs('func(?)', [1, 2]));
1919
Assert::same('func([1, 2])', Helpers::formatArgs('func(?)', [[1, 2]]));
2020
Assert::same('func(1, 2)', Helpers::formatArgs('func(?*)', [[1, 2]]));
2121
Assert::same(
22-
"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,\n\t35, 36, 37, 38, 39, 40)",
22+
"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)",
2323
Helpers::formatArgs('func(?*)', [range(10, 40)])
2424
);
2525

0 commit comments

Comments
 (0)