8000 Move from array() to [] by fabpot · Pull Request #29903 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

Move from array() to [] #29903

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Jan 16, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fixed CS on generated container files
  • Loading branch information
fabpot committed Jan 16, 2019
commit afaa13e9469feb0f2979fd947ea3e8a84c09daad
55 changes: 28 additions & 27 deletions src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php
Original file line number Diff line number Diff line change
Expand Up @@ -215,11 +215,11 @@ public function dump(array $options = [])

if ($ids = array_keys($this->container->getRemovedIds())) {
sort($ids);
$c = "<?php\n\nreturn array(\n";
$c = "<?php\n\nreturn [\n";
foreach ($ids as $id) {
$c .= ' '.$this->doExport($id)." => true,\n";
}
$files['removed-ids.php'] = $c .= ");\n";
$files['removed-ids.php'] = $c .= "];\n";
}

foreach ($this->generateServiceFiles() as $file => $c) {
Expand Down Expand Up @@ -258,11 +258,11 @@ public function dump(array $options = [])
\\class_alias(\\Container{$hash}\\{$options['class']}::class, {$options['class']}::class, false);
}

return new \\Container{$hash}\\{$options['class']}(array(
return new \\Container{$hash}\\{$options['class']}([
'container.build_hash' => '$hash',
'container.build_id' => '$id',
'container.build_time' => $time,
), __DIR__.\\DIRECTORY_SEPARATOR.'Container{$hash}');
], __DIR__.\\DIRECTORY_SEPARATOR.'Container{$hash}');

EOF;
} else {
Expand Down Expand Up @@ -607,7 +607,7 @@ private function addServiceConfigurator(Definition $definition, $variableName =
return sprintf(" (%s)->%s(\$%s);\n", $this->dumpValue($callable[0]), $callable[1], $variableName);
}

return sprintf(" \\call_user_func(array(%s, '%s'), \$%s);\n", $this->dumpValue($callable[0]), $callable[1], $variableName);
return sprintf(" \\call_user_func([%s, '%s'], \$%s);\n", $this->dumpValue($callable[0]), $callable[1], $variableName);
}

return sprintf(" %s(\$%s);\n", $callable, $variableName);
Expand Down Expand Up @@ -900,7 +900,7 @@ private function addNewInstance(Definition $definition, $return, $instantiation,
return $return.sprintf("(%s)->%s(%s);\n", $class, $callable[1], $arguments ? implode(', ', $arguments) : '');
}

return $return.sprintf("\\call_user_func(array(%s, '%s')%s);\n", $class, $callable[1], $arguments ? ', '.implode(', ', $arguments) : '');
return $return.sprintf("\\call_user_func([%s, '%s']%s);\n", $class, $callable[1], $arguments ? ', '.implode(', ', $arguments) : '');
}

return $return.sprintf("%s(%s);\n", $this->dumpLiteralClass($this->dumpValue($callable)), $arguments ? implode(', ', $arguments) : '');
Expand Down Expand Up @@ -947,7 +947,7 @@ private function startClass($class, $baseClass, $baseClassWithNamespace)
class $class extends $baseClass
{
private \$parameters;
private \$targetDirs = array();
private \$targetDirs = [];

public function __construct()
{
Expand All @@ -965,7 +965,7 @@ public function __construct()
}
if ($this->asFiles) {
$code = str_replace('$parameters', "\$buildParameters;\n private \$containerDir;\n private \$parameters", $code);
$code = str_replace('__construct()', '__construct(array $buildParameters = array(), $containerDir = __DIR__)', $code);
$code = str_replace('__construct()', '__construct(array $buildParameters = [], $containerDir = __DIR__)', $code);
$code .= " \$this->buildParameters = \$buildParameters;\n";
$code .= " \$this->containerDir = \$containerDir;\n";
}
Expand All @@ -987,7 +987,7 @@ public function __construct()
$code .= " \$this->parameters = \$this->getDefaultParameters();\n\n";
}

$code .= " \$this->services = array();\n";
$code .= " \$this->services = [];\n";
} else {
$arguments = $this->container->getParameterBag()->all() ? 'new ParameterBag($this->getDefaultParameters())' : null;
$code .= " parent::__construct($arguments);\n";
Expand Down Expand Up @@ -1085,7 +1085,7 @@ private function addNormalizedIds()
}
}

return $code ? " \$this->normalizedIds = array(\n".$code." );\n" : '';
return $code ? " \$this->normalizedIds = [\n".$code." ];\n" : '';
}

/**
Expand All @@ -1104,7 +1104,7 @@ private function addSyntheticIds()
}
}

return $code ? " \$this->syntheticIds = array(\n{$code} );\n" : '';
return $code ? " \$this->syntheticIds = [\n{$code} ];\n" : '';
}

/**
Expand All @@ -1130,7 +1130,7 @@ private function addRemovedIds()
$code .= ' '.$this->doExport($id)." => true,\n";
}

$code = "array(\n{$code} )";
$code = "[\n{$code} ]";
}

return <<<EOF
Expand Down Expand Up @@ -1159,7 +1159,7 @@ private function addMethodMap()
}
}

return $code ? " \$this->methodMap = array(\n{$code} );\n" : '';
return $code ? " \$this->methodMap = [\n{$code} ];\n" : '';
}

/**
Expand All @@ -1178,7 +1178,7 @@ private function addFileMap()
}
}

return $code ? " \$this->fileMap = array(\n{$code} );\n" : '';
return $code ? " \$this->fileMap = [\n{$code} ];\n" : '';
}

/**
Expand Down Expand Up @@ -1210,9 +1210,9 @@ private function addPrivateServices()
return '';
}

$out = " \$this->privates = array(\n";
$out = " \$this->privates = [\n";
$out .= $code;
$out .= " );\n";
$out .= " ];\n";

return $out;
}
Expand All @@ -1225,10 +1225,10 @@ private function addPrivateServices()
private function addAliases()
{
if (!$aliases = $this->container->getAliases()) {
return $this->container->isCompiled() ? "\n \$this->aliases = array();\n" : '';
return $this->container->isCompiled() ? "\n \$this->aliases = [];\n" : '';
}

$code = " \$this->aliases = array(\n";
$code = " \$this->aliases = [\n";
ksort($aliases);
foreach ($aliases as $alias => $id) {
$id = $this->container->normalizeId($id);
Expand All @@ -1238,7 +1238,7 @@ private function addAliases()
$code .= ' '.$this->doExport($alias).' => '.$this->doExport($id).",\n";
}

return $code." );\n";
return $code." ];\n";
}

private function addInlineRequires()
Expand Down Expand Up @@ -1295,15 +1295,16 @@ private function addDefaultParametersMethod()
$normalizedParams[] = sprintf(' %s => %s,', $this->export($lcKey), $this->export($key));
}
$export = $this->exportParameters([$value]);
$export = explode('0 => ', substr(rtrim($export, " )\n"), 7, -1), 2);
$export = explode('0 => ', substr(rtrim($export, " ]\n"), 2, -1), 2);

if (preg_match("/\\\$this->(?:getEnv\('(?:\w++:)*+\w++'\)|targetDirs\[\d++\])/", $export[1])) {
$dynamicPhp[$key] = sprintf('%scase %s: $value = %s; break;', $export[0], $this->export($key), $export[1]);
} else {
$php[] = sprintf('%s%s => %s,', $export[0], $this->export($key), $export[1]);
}
}
$parameters = sprintf("array(\n%s\n%s)", implode("\n", $php), str_repeat(' ', 8));

$parameters = sprintf("[\n%s\n%s]", implode("\n", $php), str_repeat(' ', 8));

$code = '';
if ($this->container->isCompiled()) {
Expand Down Expand Up @@ -1379,14 +1380,14 @@ public function getParameterBag()
EOF;
$getDynamicParameter = sprintf($getDynamicParameter, implode("\n", $dynamicPhp));
} else {
$loadedDynamicParameters = 'array()';
$loadedDynamicParameters = '[]';
$getDynamicParameter = str_repeat(' ', 8).'throw new InvalidArgumentException(sprintf(\'The dynamic parameter "%s" must be defined.\', $name));';
}

$code .= <<<EOF

private \$loadedDynamicParameters = {$loadedDynamicParameters};
private \$dynamicParameters = array();
private \$dynamicParameters = [];

/*{$this->docStar}
* Computes a dynamic parameter.
Expand All @@ -1405,7 +1406,7 @@ private function getDynamicParameter(\$name)

EOF;

$code .= ' private $normalizedParameterNames = '.($normalizedParams ? sprintf("array(\n%s\n );", implode("\n", $normalizedParams)) : 'array();')."\n";
$code .= ' private $normalizedParameterNames = '.($normalizedParams ? sprintf("[\n%s\n ];", implode("\n", $normalizedParams)) : '[];')."\n";
$code .= <<<'EOF'

private function normalizeParameterName($name)
Expand Down Expand Up @@ -1478,7 +1479,7 @@ private function exportParameters(array $parameters, $path = '', $indent = 12)
$php[] = sprintf('%s%s => %s,', str_repeat(' ', $indent), $this->export($key), $value);
}

return sprintf("array(\n%s\n%s)", implode("\n", $php), str_repeat(' ', $indent - 4));
return sprintf("[\n%s\n%s]", implode("\n", $php), str_repeat(' ', $indent - 4));
}

/**
Expand Down Expand Up @@ -1599,7 +1600,7 @@ private function dumpValue($value, $interpolate = true)
$code[] = sprintf('%s => %s', $this->dumpValue($k, $interpolate), $this->dumpValue($v, $interpolate));
}

return sprintf('array(%s)', implode(', ', $code));
return sprintf('[%s]', implode(', ', $code));
} elseif ($value instanceof ArgumentInterface) {
$scope = [$this->definitionVariables, $this->referenceVariables];
$this->definitionVariables = $this->referenceVariables = null;
Expand Down Expand Up @@ -1691,7 +1692,7 @@ private function dumpValue($value, $interpolate = true)
return sprintf('(%s)->%s(%s)', $class, $factory[1], implode(', ', $arguments));
}

return sprintf("\\call_user_func(array(%s, '%s')%s)", $class, $factory[1], \count($arguments) > 0 ? ', '.implode(', ', $arguments) : '');
return sprintf("\\call_user_func([%s, '%s']%s)", $class, $factory[1], \count($arguments) > 0 ? ', '.implode(', ', $arguments) : '');
}

if ($factory[0] instanceof Reference) {
Expand Down
< C24 tr data-hunk="0ac1f0f8adb82340b2b7fd4720ad1354004adb7e2c612573b283c56af3515831" class="show-top-border">
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

class Bar implements BarInterface
{
public function __construct($quz = null, \NonExistent $nonExistent = null, BarInterface $decorated = null, array $foo = array())
public function __construct($quz = null, \NonExistent $nonExistent = null, BarInterface $decorated = null, array $foo = [])
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ public function __construct($container)

public static function getSubscribedServices()
{
return array(
return [
__CLASS__,
'?'.CustomDefinition::class,
'bar' => CustomDefinition::class,
'baz' => '?'.CustomDefinition::class,
);
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
return function (ContainerConfigurator $c) {
$s = $c->services();
$s->set(BarService::class)
->args(array(inline('FooClass')));
->args([inline('FooClass')]);
};
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
->set('foo')
->parent(BarService::class)
->decorate('bar', 'b', 1)
->args(array(ref('b')))
->args([ref('b')])
->class('Class2')
->file('file.php')
->parent('bar')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
->private()
->autoconfigure()
->autowire()
->tag('t', array('a' => 'b'))
->tag('t', ['a' => 'b'])
->bind(Foo::class, ref('bar'))
->private();

$s->set(Foo::class)->args(array(ref('bar')))->public();
$s->set(Foo::class)->args([ref('bar')])->public();
$s->set('bar', Foo::class)->call('setFoo')->autoconfigure(false);
};
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
$s = $c->services();
$s->instanceof(Prototype\Foo::class)
->property('p', 0)
->call('setFoo', array(ref('foo')))
->tag('tag', array('k' => 'v'))
->call('setFoo', [ref('foo')])
->tag('tag', ['k' => 'v'])
->share(false)
->lazy()
->configurator('c')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
->exclude('../Prototype/{OtherDir,BadClasses}')
->factory('f')
->deprecate('%service_id%')
->args(array(0))
->args(array(1))
->args([0])
->args([1])
->autoconfigure(false)
->tag('foo')
->parent('foo');
Expand Down
Loading
0