Skip to content

Commit

Permalink
fixed CS on generated container files
Browse files Browse the repository at this point in the history
  • Loading branch information
fabpot committed Jan 16, 2019
1 parent ea1c2fd commit fc292f9
Show file tree
Hide file tree
Showing 56 changed files with 522 additions and 521 deletions.
55 changes: 28 additions & 27 deletions 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
2 changes: 1 addition & 1 deletion Tests/Fixtures/Bar.php
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
4 changes: 2 additions & 2 deletions Tests/Fixtures/TestServiceSubscriber.php
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,
);
];
}
}
2 changes: 1 addition & 1 deletion Tests/Fixtures/config/basic.php
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')]);
};
2 changes: 1 addition & 1 deletion Tests/Fixtures/config/child.php
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
4 changes: 2 additions & 2 deletions Tests/Fixtures/config/defaults.php
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);
};
4 changes: 2 additions & 2 deletions Tests/Fixtures/config/instanceof.php
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
4 changes: 2 additions & 2 deletions Tests/Fixtures/config/prototype.php
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 comments on commit fc292f9

Please sign in to comment.