Skip to content

Commit

Permalink
replaced array() by [] in *generated* PHP code
Browse files Browse the repository at this point in the history
  • Loading branch information
fabpot committed Mar 2, 2015
1 parent 5388a13 commit 6d50f98
Show file tree
Hide file tree
Showing 11 changed files with 37 additions and 32 deletions.
4 changes: 2 additions & 2 deletions lib/Twig/Compiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ public function repr($value)
} elseif (is_bool($value)) {
$this->raw($value ? 'true' : 'false');
} elseif (is_array($value)) {
$this->raw('array(');
$this->raw('[');
$first = true;
foreach ($value as $key => $v) {
if (!$first) {
Expand All @@ -191,7 +191,7 @@ public function repr($value)
$this->raw(' => ');
$this->repr($v);
}
$this->raw(')');
$this->raw(']');
} else {
$this->string($value);
}
Expand Down
6 changes: 3 additions & 3 deletions lib/Twig/Node/CheckSecurity.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ public function compile(Twig_Compiler $compiler)
->indent()
->write("\$this->env->getExtension('sandbox')->checkSecurity(\n")
->indent()
->write(!$tags ? "array(),\n" : "array('".implode("', '", array_keys($tags))."'),\n")
->write(!$filters ? "array(),\n" : "array('".implode("', '", array_keys($filters))."'),\n")
->write(!$functions ? "array()\n" : "array('".implode("', '", array_keys($functions))."')\n")
->write(!$tags ? "[],\n" : "['".implode("', '", array_keys($tags))."'],\n")
->write(!$filters ? "[],\n" : "['".implode("', '", array_keys($filters))."'],\n")
->write(!$functions ? "[]\n" : "['".implode("', '", array_keys($functions))."']\n")
->outdent()
->write(");\n")
->outdent()
Expand Down
4 changes: 2 additions & 2 deletions lib/Twig/Node/Expression/Array.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function addElement(Twig_Node_Expression $value, Twig_Node_Expression $ke
*/
public function compile(Twig_Compiler $compiler)
{
$compiler->raw('array(');
$compiler->raw('[');
$first = true;
foreach ($this->getKeyValuePairs() as $pair) {
if (!$first) {
Expand All @@ -81,6 +81,6 @@ public function compile(Twig_Compiler $compiler)
->subcompile($pair['value'])
;
}
$compiler->raw(')');
$compiler->raw(']');
}
}
2 changes: 1 addition & 1 deletion lib/Twig/Node/Include.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ protected function addGetTemplate(Twig_Compiler $compiler)
protected function addTemplateArguments(Twig_Compiler $compiler)
{
if (null === $this->getNode('variables')) {
$compiler->raw(false === $this->getAttribute('only') ? '$context' : 'array()');
$compiler->raw(false === $this->getAttribute('only') ? '$context' : '[]');
} elseif (false === $this->getAttribute('only')) {
$compiler
->raw('array_merge($context, ')
Expand Down
19 changes: 12 additions & 7 deletions lib/Twig/Node/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -238,11 +238,11 @@ protected function compileConstructor(Twig_Compiler $compiler)
->write("\$this->blocks = array_merge(\n")
->indent()
->write("\$this->traits,\n")
->write("array(\n")
->write("[\n")
;
} else {
$compiler
->write("\$this->blocks = array(\n")
->write("\$this->blocks = [\n")
;
}

Expand All @@ -253,20 +253,25 @@ protected function compileConstructor(Twig_Compiler $compiler)

foreach ($this->getNode('blocks') as $name => $node) {
$compiler
->write(sprintf("'%s' => array(\$this, 'block_%s'),\n", $name, $name))
->write(sprintf("'%s' => [\$this, 'block_%s'],\n", $name, $name))
;
}

if ($countTraits) {
$compiler
->outdent()
->write(")\n")
->write("]\n")
->outdent()
->write(");\n")
;
} else {
$compiler
->outdent()
->write("];\n")
;
}

$compiler
->outdent()
->write(");\n")
->outdent()
->subcompile($this->getNode('constructor_end'))
->write("}\n\n")
Expand All @@ -276,7 +281,7 @@ protected function compileConstructor(Twig_Compiler $compiler)
protected function compileDisplay(Twig_Compiler $compiler)
{
$compiler
->write("protected function doDisplay(array \$context, array \$blocks = array())\n", "{\n")
->write("protected function doDisplay(array \$context, array \$blocks = [])\n", "{\n")
->indent()
->subcompile($this->getNode('display_start'))
->subcompile($this->getNode('body'))
Expand Down
4 changes: 2 additions & 2 deletions lib/Twig/Node/Set.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,15 @@ public function compile(Twig_Compiler $compiler)
$compiler->raw(' = ');

if (count($this->getNode('names')) > 1) {
$compiler->write('array(');
$compiler->write('[');
foreach ($this->getNode('values') as $idx => $value) {
if ($idx) {
$compiler->raw(', ');
}

$compiler->subcompile($value);
}
$compiler->raw(')');
$compiler->raw(']');
} else {
if ($this->getAttribute('safe')) {
$compiler
Expand Down
2 changes: 1 addition & 1 deletion test/Twig/Tests/Node/Expression/ArrayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function getTests()
$node = new Twig_Node_Expression_Array($elements, 1);

return array(
array($node, 'array("foo" => "bar", "bar" => "foo")'),
array($node, '["foo" => "bar", "bar" => "foo"]'),
);
}
}
6 changes: 3 additions & 3 deletions test/Twig/Tests/Node/Expression/GetAttrTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,16 @@ public function getTests()
$attr = new Twig_Node_Expression_Constant('bar', 1);
$args = new Twig_Node_Expression_Array(array(), 1);
$node = new Twig_Node_Expression_GetAttr($expr, $attr, $args, Twig_Template::ANY_CALL, 1);
$tests[] = array($node, sprintf('%s%s, "bar", array())', $this->getAttributeGetter(), $this->getVariableGetter('foo', 1)));
$tests[] = array($node, sprintf('%s%s, "bar", [])', $this->getAttributeGetter(), $this->getVariableGetter('foo', 1)));

$node = new Twig_Node_Expression_GetAttr($expr, $attr, $args, Twig_Template::ARRAY_CALL, 1);
$tests[] = array($node, sprintf('%s%s, "bar", array(), "array")', $this->getAttributeGetter(), $this->getVariableGetter('foo', 1)));
$tests[] = array($node, sprintf('%s%s, "bar", [], "array")', $this->getAttributeGetter(), $this->getVariableGetter('foo', 1)));

$args = new Twig_Node_Expression_Array(array(), 1);
$args->addElement(new Twig_Node_Expression_Name('foo', 1));
$args->addElement(new Twig_Node_Expression_Constant('bar', 1));
$node = new Twig_Node_Expression_GetAttr($expr, $attr, $args, Twig_Template::METHOD_CALL, 1);
$tests[] = array($node, sprintf('%s%s, "bar", array(0 => %s, 1 => "bar"), "method")', $this->getAttributeGetter(), $this->getVariableGetter('foo', 1), $this->getVariableGetter('foo')));
$tests[] = array($node, sprintf('%s%s, "bar", [0 => %s, 1 => "bar"], "method")', $this->getAttributeGetter(), $this->getVariableGetter('foo', 1), $this->getVariableGetter('foo')));

return $tests;
}
Expand Down
6 changes: 3 additions & 3 deletions test/Twig/Tests/Node/IncludeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,22 +56,22 @@ public function getTests()
$node = new Twig_Node_Include($expr, $vars, false, false, 1);
$tests[] = array($node, <<<EOF
// line 1
\$this->loadTemplate("foo.twig", null, 1)->display(array_merge(\$context, array("foo" => true)));
\$this->loadTemplate("foo.twig", null, 1)->display(array_merge(\$context, ["foo" => true]));
EOF
);

$node = new Twig_Node_Include($expr, $vars, true, false, 1);
$tests[] = array($node, <<<EOF
// line 1
\$this->loadTemplate("foo.twig", null, 1)->display(array("foo" => true));
\$this->loadTemplate("foo.twig", null, 1)->display(["foo" => true]);
EOF
);

$node = new Twig_Node_Include($expr, $vars, true, true, 1);
$tests[] = array($node, <<<EOF
// line 1
try {
\$this->loadTemplate("foo.twig", null, 1)->display(array("foo" => true));
\$this->loadTemplate("foo.twig", null, 1)->display(["foo" => true]);
} catch (Twig_Error_Loader \$e) {
// ignore missing template
}
Expand Down
14 changes: 7 additions & 7 deletions test/Twig/Tests/Node/ModuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ public function __construct(Twig_Environment \$env)
\$this->parent = false;
\$this->blocks = array(
);
\$this->blocks = [
];
}
protected function doDisplay(array \$context, array \$blocks = array())
protected function doDisplay(array \$context, array \$blocks = [])
{
// line 1
echo "foo";
Expand Down Expand Up @@ -95,16 +95,16 @@ public function __construct(Twig_Environment \$env)
// line 1
\$this->parent = \$this->loadTemplate("layout.twig", "foo.twig", 1);
\$this->blocks = array(
);
\$this->blocks = [
];
}
protected function doGetParent(array \$context)
{
return "layout.twig";
}
protected function doDisplay(array \$context, array \$blocks = array())
protected function doDisplay(array \$context, array \$blocks = [])
{
// line 2
\$context["macro"] = \$this->loadTemplate("foo.twig", "foo.twig", 2);
Expand Down Expand Up @@ -152,7 +152,7 @@ protected function doGetParent(array \$context)
return \$this->loadTemplate(((true) ? ("foo") : ("foo")), "foo.twig", 2);
}
protected function doDisplay(array \$context, array \$blocks = array())
protected function doDisplay(array \$context, array \$blocks = [])
{
// line 4
\$context["foo"] = "foo";
Expand Down
2 changes: 1 addition & 1 deletion test/Twig/Tests/Node/SetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function getTests()
$node = new Twig_Node_Set(false, $names, $values, 1);
$tests[] = array($node, <<<EOF
// line 1
list(\$context["foo"], \$context["bar"]) = array("foo", {$this->getVariableGetter('bar')});
list(\$context["foo"], \$context["bar"]) = ["foo", {$this->getVariableGetter('bar')}];
EOF
);

Expand Down

0 comments on commit 6d50f98

Please sign in to comment.