Skip to content

Commit

Permalink
fixed CS
Browse files Browse the repository at this point in the history
  • Loading branch information
fabpot committed Jan 16, 2019
1 parent 2a898a2 commit 7aa47f7
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 48 deletions.
4 changes: 2 additions & 2 deletions ContainerBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,7 @@ private function doGet($id, $invalidBehavior = ContainerInterface::EXCEPTION_ON_
* the parameters passed to the container constructor to have precedence
* over the loaded ones.
*
* $container = new ContainerBuilder(new ParameterBag(array('foo' => 'bar')));
* $container = new ContainerBuilder(new ParameterBag(['foo' => 'bar']));
* $loader = new LoaderXXX($container);
* $loader->load('resource_name');
* $container->register('foo', 'stdClass');
Expand Down Expand Up @@ -1243,7 +1243,7 @@ private function doResolveServices($value, array &$inlineServices = [], $isConst
*
* Example:
*
* $container->register('foo')->addTag('my.tag', array('hello' => 'world'));
* $container->register('foo')->addTag('my.tag', ['hello' => 'world']);
*
* $serviceIds = $container->findTaggedServiceIds('my.tag');
* foreach ($serviceIds as $serviceId => $tags) {
Expand Down
45 changes: 23 additions & 22 deletions Dumper/PhpDumper.php
Original file line number Diff line number Diff line change
Expand Up @@ -223,11 +223,11 @@ public function dump(array $options = [])
}
if ($ids = array_keys($ids)) {
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 @@ -266,11 +266,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 @@ -913,12 +913,12 @@ private function startClass(string $class, string $baseClass, string $baseClassW
class $class extends $baseClass
{
private \$parameters;
private \$targetDirs = array();
private \$targetDirs = [];
/*{$this->docStar}
* @internal but protected for BC on cache:clear
*/
protected \$privates = array();
protected \$privates = [];
public function __construct()
{
Expand All @@ -936,7 +936,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 @@ -956,7 +956,7 @@ public function __construct()
if ($this->container->getParameterBag()->all()) {
$code .= " \$this->parameters = \$this->getDefaultParameters();\n\n";
}
$code .= " \$this->services = \$this->privates = array();\n";
$code .= " \$this->services = \$this->privates = [];\n";

$code .= $this->addSyntheticIds();
$code .= $this->addMethodMap();
Expand All @@ -968,7 +968,7 @@ public function __construct()
public function reset()
{
\$this->privates = array();
\$this->privates = [];
parent::reset();
}
Expand Down Expand Up @@ -1036,7 +1036,7 @@ private function addSyntheticIds(): string
}
}

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

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

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

return <<<EOF
Expand All @@ -1087,7 +1087,7 @@ private function addMethodMap(): string
}
}

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

private function addFileMap(): string
Expand All @@ -1101,16 +1101,16 @@ private function addFileMap(): string
}
}

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

private function addAliases(): string
{
if (!$aliases = $this->container->getAliases()) {
return "\n \$this->aliases = array();\n";
return "\n \$this->aliases = [];\n";
}

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

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

private function addInlineRequires(): string
Expand Down Expand Up @@ -1168,15 +1168,16 @@ private function addDefaultParametersMethod(): string
throw new InvalidArgumentException(sprintf('Parameter name cannot use env parameters: %s.', $resolvedKey));
}
$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 = <<<'EOF'
Expand Down Expand Up @@ -1246,14 +1247,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 Down Expand Up @@ -1310,7 +1311,7 @@ private function exportParameters(array $parameters, string $path = '', int $ind
$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));
}

private function endClass(): string
Expand Down Expand Up @@ -1404,7 +1405,7 @@ private function dumpValue($value, bool $interpolate = true): string
$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
2 changes: 1 addition & 1 deletion Tests/Fixtures/includes/autowiring_classes.php
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ interface DecoratorInterface

class Decorated implements DecoratorInterface
{
public function __construct($quz = null, \NonExistent $nonExistent = null, DecoratorInterface $decorated = null, array $foo = array())
public function __construct($quz = null, \NonExistent $nonExistent = null, DecoratorInterface $decorated = null, array $foo = [])
{
}
}
Expand Down
46 changes: 23 additions & 23 deletions Tests/Fixtures/php/services9_as_files.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Array
(
[Container%s/removed-ids.php] => <?php

return array(
return [
'Psr\\Container\\ContainerInterface' => true,
'Symfony\\Component\\DependencyInjection\\ContainerInterface' => true,
'configurator_service' => true,
Expand All @@ -14,7 +14,7 @@ return array(
'inlined' => true,
'new_factory' => true,
'tagged_iterator_foo' => true,
);
];

[Container%s/getBAR2Service.php] => <?php

Expand Down Expand Up @@ -179,11 +179,11 @@ use Symfony\Component\DependencyInjection\Exception\RuntimeException;

$a = ($this->services['foo.baz'] ?? $this->load('getFoo_BazService.php'));

$this->services['foo'] = $instance = \Bar\FooClass::getInstance('foo', $a, array('bar' => 'foo is bar', 'foobar' => 'bar'), true, $this);
$this->services['foo'] = $instance = \Bar\FooClass::getInstance('foo', $a, ['bar' => 'foo is bar', 'foobar' => 'bar'], true, $this);

$instance->foo = 'bar';
$instance->moo = $a;
$instance->qux = array('bar' => 'foo is bar', 'foobar' => 'bar');
$instance->qux = ['bar' => 'foo is bar', 'foobar' => 'bar'];
$instance->setBar(($this->services['bar'] ?? $this->getBarService()));
$instance->initialize();
sc_configure($instance);
Expand Down Expand Up @@ -383,14 +383,14 @@ class ProjectServiceContainer extends Container
private $buildParameters;
private $containerDir;
private $parameters;
private $targetDirs = array();
private $targetDirs = [];

/**
* @internal but protected for BC on cache:clear
*/
protected $privates = array();
protected $privates = [];

public function __construct(array $buildParameters = array(), $containerDir = __DIR__)
public function __construct(array $buildParameters = [], $containerDir = __DIR__)
{
$dir = $this->targetDirs[0] = \dirname($containerDir);
for ($i = 1; $i <= 5; ++$i) {
Expand All @@ -400,14 +400,14 @@ class ProjectServiceContainer extends Container
$this->containerDir = $containerDir;
$this->parameters = $this->getDefaultParameters();

$this->services = $this->privates = array();
$this->syntheticIds = array(
$this->services = $this->privates = [];
$this->syntheticIds = [
'request' => true,
);
$this->methodMap = array(
];
$this->methodMap = [
'bar' => 'getBarService',
);
$this->fileMap = array(
];
$this->fileMap = [
'BAR' => 'getBAR2Service.php',
'BAR2' => 'getBAR22Service.php',
'bar2' => 'getBar23Service.php',
Expand All @@ -431,17 +431,17 @@ class ProjectServiceContainer extends Container
'runtime_error' => 'getRuntimeErrorService.php',
'service_from_static_method' => 'getServiceFromStaticMethodService.php',
'tagged_iterator' => 'getTaggedIteratorService.php',
);
$this->aliases = array(
];
$this->aliases = [
'alias_for_alias' => 'foo',
'alias_for_foo' => 'foo',
'decorated' => 'decorator_service_with_name',
);
];
}

public function reset()
{
$this->privates = array();
$this->privates = [];
parent::reset();
}

Expand Down Expand Up @@ -529,8 +529,8 @@ class ProjectServiceContainer extends Container
return $this->parameterBag;
}

private $loadedDynamicParameters = array();
private $dynamicParameters = array();
private $loadedDynamicParameters = [];
private $dynamicParameters = [];

/**
* Computes a dynamic parameter.
Expand All @@ -553,11 +553,11 @@ class ProjectServiceContainer extends Container
*/
protected function getDefaultParameters()
{
return array(
return [
'baz_class' => 'BazClass',
'foo_class' => 'Bar\\FooClass',
'foo' => 'bar',
);
];
}
}

Expand All @@ -577,10 +577,10 @@ if (!\class_exists(ProjectServiceContainer::class, false)) {
\class_alias(\Container%s\ProjectServiceContainer::class, ProjectServiceContainer::class, false);
}

return new \Container%s\ProjectServiceContainer(array(
return new \Container%s\ProjectServiceContainer([
'container.build_hash' => '%s',
'container.build_id' => '%s',
'container.build_time' => %d,
), __DIR__.\DIRECTORY_SEPARATOR.'Container%s');
], __DIR__.\DIRECTORY_SEPARATOR.'Container%s');

)

0 comments on commit 7aa47f7

Please sign in to comment.