Skip to content

Commit 4db6c3c

Browse files
committed
Helpers::dump() generates PHP 5.4 short array syntax
1 parent fe6f2ff commit 4db6c3c

File tree

5 files changed

+16
-16
lines changed

5 files changed

+16
-16
lines changed

src/PhpGenerator/Helpers.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ private static function _dump(& $var, $level = 0)
8989
}
9090
unset($var[$marker]);
9191
}
92-
return 'array(' . (strpos($out, "\n") === FALSE && strlen($out) < 40 ? $out : $outAlt) . ')';
92+
return '[' . (strpos($out, "\n") === FALSE && strlen($out) < 40 ? $out : $outAlt) . ']';
9393

9494
} elseif ($var instanceof \Serializable) {
9595
$var = serialize($var);
@@ -121,8 +121,8 @@ private static function _dump(& $var, $level = 0)
121121
$out .= $space;
122122
}
123123
return $class === 'stdClass'
124-
? "(object) array($out)"
125-
: __CLASS__ . "::createObject('$class', array($out))";
124+
? "(object) [$out]"
125+
: __CLASS__ . "::createObject('$class', [$out])";
126126

127127
} elseif (is_resource($var)) {
128128
throw new Nette\InvalidArgumentException('Cannot dump resource.');

tests/PhpGenerator/ClassType.expect

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ abstract final class Example extends ParentClass implements IExample, IOne
1818

1919
public $order = RecursiveIteratorIterator::SELF_FIRST;
2020

21-
public static $sections = array('first' => TRUE);
21+
public static $sections = ['first' => TRUE];
2222

2323

2424
/**

tests/PhpGenerator/ClassType.from.expect

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class Class2 extends Class1 implements Interface2
4444
/** @var int */
4545
protected $protected = 10;
4646

47-
private $private = array();
47+
private $private = [];
4848

4949
public static $static;
5050

tests/PhpGenerator/Helpers.dump().phpt

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,17 @@ Assert::same( "'I\xc3\xb1t\xc3\xabrn\xc3\xa2ti\xc3\xb4n\xc3\xa0liz\xc3\xa6ti\xc3
2424
Assert::same( '"\rHello \$"', Helpers::dump("\rHello $") );
2525
Assert::same( "'He\\llo'", Helpers::dump('He\llo') );
2626
Assert::same( '\'He\ll\\\\\o \\\'wor\\\\\\\'ld\\\\\'', Helpers::dump('He\ll\\\o \'wor\\\'ld\\') );
27-
Assert::same( 'array()', Helpers::dump([]) );
27+
Assert::same( '[]', Helpers::dump([]) );
2828

29-
Assert::same( "array(\$s)", Helpers::dump([new PhpLiteral('$s')]) );
29+
Assert::same( "[\$s]", Helpers::dump([new PhpLiteral('$s')]) );
3030

31-
Assert::same( "array(1, 2, 3)", Helpers::dump([1,2,3]) );
32-
Assert::same( "array('a', 7 => 'b', 'c', '9a' => 'd', 'e')", Helpers::dump(['a', 7 => 'b', 'c', '9a' => 'd', 9 => 'e']) );
33-
Assert::same( "array(\n\tarray(\n\t\t'a',\n\t\t'loooooooooooooooooooooooooooooooooong',\n\t),\n)", Helpers::dump([['a', 'loooooooooooooooooooooooooooooooooong']]) );
34-
Assert::same( "array('a' => 1, array(\"\\r\" => \"\\r\", 2), 3)", Helpers::dump(['a' => 1, ["\r" => "\r", 2], 3]) );
31+
Assert::same( "[1, 2, 3]", Helpers::dump([1,2,3]) );
32+
Assert::same( "['a', 7 => 'b', 'c', '9a' => 'd', 'e']", Helpers::dump(['a', 7 => 'b', 'c', '9a' => 'd', 9 => 'e']) );
33+
Assert::same( "[\n\t[\n\t\t'a',\n\t\t'loooooooooooooooooooooooooooooooooong',\n\t],\n]", Helpers::dump([['a', 'loooooooooooooooooooooooooooooooooong']]) );
34+
Assert::same( "['a' => 1, [\"\\r\" => \"\\r\", 2], 3]", Helpers::dump(['a' => 1, ["\r" => "\r", 2], 3]) );
3535

36-
Assert::same( "(object) array(\n\t'a' => 1,\n\t'b' => 2,\n)", Helpers::dump((object) ['a' => 1, 'b' => 2]) );
37-
Assert::same( "(object) array(\n\t'a' => (object) array(\n\t\t'b' => 2,\n\t),\n)" , Helpers::dump((object) ['a' => (object) ['b' => 2]]) );
36+
Assert::same( "(object) [\n\t'a' => 1,\n\t'b' => 2,\n]", Helpers::dump((object) ['a' => 1, 'b' => 2]) );
37+
Assert::same( "(object) [\n\t'a' => (object) [\n\t\t'b' => 2,\n\t],\n]" , Helpers::dump((object) ['a' => (object) ['b' => 2]]) );
3838

3939

4040
class Test
@@ -44,7 +44,7 @@ class Test
4444
private $c = 3;
4545
}
4646

47-
Assert::same( "Nette\\PhpGenerator\\Helpers::createObject('Test', array(\n\t'a' => 1,\n\t\"\\x00*\\x00b\" => 2,\n\t\"\\x00Test\\x00c\" => 3,\n))", Helpers::dump(new Test) );
47+
Assert::same( "Nette\\PhpGenerator\\Helpers::createObject('Test', [\n\t'a' => 1,\n\t\"\\x00*\\x00b\" => 2,\n\t\"\\x00Test\\x00c\" => 3,\n])", Helpers::dump(new Test) );
4848
Assert::equal( new Test, eval('return ' . Helpers::dump(new Test) . ';') );
4949

5050

@@ -63,7 +63,7 @@ class Test2 extends Test
6363
}
6464
}
6565

66-
Assert::same( "Nette\\PhpGenerator\\Helpers::createObject('Test2', array(\n\t\"\\x00Test2\\x00c\" => 4,\n\t'a' => 1,\n\t\"\\x00*\\x00b\" => 2,\n))", Helpers::dump(new Test2) );
66+
Assert::same( "Nette\\PhpGenerator\\Helpers::createObject('Test2', [\n\t\"\\x00Test2\\x00c\" => 4,\n\t'a' => 1,\n\t\"\\x00*\\x00b\" => 2,\n])", Helpers::dump(new Test2) );
6767
Assert::equal( new Test2, eval('return ' . Helpers::dump(new Test2) . ';') );
6868

6969

tests/PhpGenerator/Helpers.format.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Assert::same( 'func(1)', Helpers::format('func(?)', 1, 2) );
1616

1717
Assert::same( 'func', Helpers::formatArgs('func', [1, 2]) );
1818
Assert::same( 'func(1)', Helpers::formatArgs('func(?)', [1, 2]) );
19-
Assert::same( "func(array(1, 2))", Helpers::formatArgs('func(?)', [[1, 2]]) );
19+
Assert::same( "func([1, 2])", Helpers::formatArgs('func(?)', [[1, 2]]) );
2020
Assert::same( 'func(1, 2)', Helpers::formatArgs('func(?*)', [[1, 2]]) );
2121
Assert::same(
2222
"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)",

0 commit comments

Comments
 (0)