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 all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
16 changes: 8 additions & 8 deletions .php_cs.dist
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,26 @@ if (!file_exists(__DIR__.'/src')) {
}

return PhpCsFixer\Config::create()
->setRules(array(
->setRules([
'@Symfony' => true,
'@Symfony:risky' => true,
'@PHPUnit48Migration:risky' => true,
'php_unit_no_expectation_annotation' => false, // part of `PHPUnitXYMigration:risky` ruleset, to be enabled when PHPUnit 4.x support will be dropped, as we don't want to rewrite exceptions handling twice
'array_syntax' => array('syntax' => 'short'),
'array_syntax' => ['syntax' => 'short'],
'fopen_flags' => false,
'ordered_imports' => true,
'protected_to_private' => false,
// Part of @Symfony:risky in PHP-CS-Fixer 2.13.0. To be removed from the config file once upgrading
'native_function_invocation' => array('include' => array('@compiler_optimized'), 'scope' => 'namespaced'),
'native_function_invocation' => ['include' => ['@compiler_optimized'], 'scope' => 'namespaced'],
// Part of future @Symfony ruleset in PHP-CS-Fixer To be removed from the config file once upgrading
'phpdoc_types_order' => array('null_adjustment' => 'always_last', 'sort_algorithm' => 'none'),
))
'phpdoc_types_order' => ['null_adjustment' => 'always_last', 'sort_algorithm' => 'none'],
])
->setRiskyAllowed(true)
->setFinder(
PhpCsFixer\Finder::create()
->in(__DIR__.'/src')
->append(array(__FILE__))
->exclude(array(
->append([__FILE__])
->exclude([
// directories containing files with content that is autogenerated by `var_export`, which breaks CS in output code
'Symfony/Component/DependencyInjection/Tests/Fixtures',
'Symfony/Component/Routing/Tests/Fixtures/dumper',
Expand All @@ -38,7 +38,7 @@ return PhpCsFixer\Config::create()
'Symfony/Bundle/FrameworkBundle/Resources/views/Form',
// explicit trigger_error tests
'Symfony/Bridge/PhpUnit/Tests/DeprecationErrorHandler/',
))
])
// Support for older PHPunit version
->notPath('Symfony/Bridge/PhpUnit/SymfonyTestsListener.php')
// file content autogenerated by `var_export`
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Bridge/Doctrine/ContainerAwareEventManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ class ContainerAwareEventManager extends EventManager
*
* <event> => <listeners>
*/
private $listeners = array();
private $initialized = array();
private $listeners = [];
private $initialized = [];
private $container;

public function __construct(ContainerInterface $container)
Expand Down
28 changes: 14 additions & 14 deletions src/Symfony/Bridge/Doctrine/DataCollector/DoctrineDataCollector.php
10000
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class DoctrineDataCollector extends DataCollector
/**
* @var DebugStack[]
*/
private $loggers = array();
private $loggers = [];

public function __construct(ManagerRegistry $registry)
{
Expand All @@ -58,24 +58,24 @@ public function addLogger($name, DebugStack $logger)
*/
public function collect(Request $request, Response $response, \Exception $exception = null)
{
$queries = array();
$queries = [];
foreach ($this->loggers as $name => $logger) {
$queries[$name] = $this->sanitizeQueries($name, $logger->queries);
}

$this->data = array(
$this->data = [
'queries' => $queries,
'connections' => $this->connections,
'managers' => $this->managers,
);
];
}

public function reset()
{
$this->data = array();
$this->data = [];

foreach ($this->loggers as $logger) {
$logger->queries = array();
$logger->queries = [];
$logger->currentQuery = 0;
}
}
Expand Down Expand Up @@ -133,10 +133,10 @@ private function sanitizeQuery($connectionName, $query)
{
$query['explainable'] = true;
if (null === $query['params']) {
$query['params'] = array();
$query['params'] = [];
}
if (!\is_array($query['params'])) {
$query['params'] = array($query['params']);
$query['params'] = [$query['params']];
}
foreach ($query['params'] as $j => $param) {
if (isset($query['types'][$j])) {
Expand Down Expand Up @@ -184,26 +184,26 @@ private function sanitizeParam($var)
$className = \get_class($var);

return method_exists($var, '__toString') ?
array(sprintf('Object(%s): "%s"', $className, $var->__toString()), false) :
array(sprintf('Object(%s)', $className), false);
[sprintf('Object(%s): "%s"', $className, $var->__toString()), false] :
[sprintf('Object(%s)', $className), false];
}

if (\is_array($var)) {
$a = array();
$a = [];
$original = true;
foreach ($var as $k => $v) {
list($value, $orig) = $this->sanitizeParam($v);
$original = $original && $orig;
$a[$k] = $value;
}

return array($a, $original);
return [$a, $original];
}

if (\is_resource($var)) {
return array(sprintf('Resource(%s)', get_resource_type($var)), false);
return [sprintf('Resource(%s)', get_resource_type($var)), false];
}

return array($var, true);
return [$var, true];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ abstract class AbstractDoctrineExtension extends Extension
/**
* Used inside metadata driver method to simplify aggregation of data.
*/
protected $aliasMap = array();
protected $aliasMap = [];

/**
* Used inside metadata driver method to simplify aggregation of data.
*/
protected $drivers = array();
protected $drivers = [];

/**
* @param array $objectManager A configured object manager
Expand All @@ -46,10 +46,10 @@ protected function loadMappingInformation(array $objectManager, ContainerBuilder
// automatically register bundle mappings
foreach (array_keys($container->getParameter('kernel.bundles')) as $bundle) {
if (!isset($objectManager['mappings'][$bundle])) {
$objectManager['mappings'][$bundle] = array(
$objectManager['mappings'][$bundle] = [
'mapping' => true,
'is_bundle' => true,
);
];
}
}
}
Expand All @@ -59,11 +59,11 @@ protected function loadMappingInformation(array $objectManager, ContainerBuilder
continue;
}

$mappingConfig = array_replace(array(
$mappingConfig = array_replace([
'dir' => false,
'type' => false,
'prefix' => false,
), (array) $mappingConfig);
], (array) $mappingConfig);

$mappingConfig['dir'] = $container->getParameterBag()->resolveValue($mappingConfig['dir']);
// a bundle configuration is detected by realizing that the specified dir is not absolute and existing
Expand Down Expand Up @@ -153,7 +153,7 @@ protected function getMappingDriverBundleConfigDefaults(array $bundleConfig, \Re
}

if (!$bundleConfig['dir']) {
if (\in_array($bundleConfig['type'], array('annotation', 'staticphp'))) {
if (\in_array($bundleConfig['type'], ['annotation', 'staticphp'])) {
$bundleConfig['dir'] = $bundleDir.'/'.$this->getMappingObjectDefaultName();
} else {
$bundleConfig['dir'] = $bundleDir.'/'.$this->getMappingResourceConfigDirectory();
Expand Down Expand Up @@ -197,25 +197,25 @@ protected function registerMappingDrivers($objectManager, ContainerBuilder $cont
}
$mappingDriverDef->setArguments($args);
} elseif ('annotation' == $driverType) {
$mappingDriverDef = new Definition('%'.$this->getObjectManagerElementName('metadata.'.$driverType.'.class%'), array(
$mappingDriverDef = new Definition('%'.$this->getObjectManagerElementName('metadata.'.$driverType.'.class%'), [
new Reference($this->getObjectManagerElementName('metadata.annotation_reader')),
array_values($driverPaths),
));
]);
} else {
$mappingDriverDef = new Definition('%'.$this->getObjectManagerElementName('metadata.'.$driverType.'.class%'), array(
$mappingDriverDef = new Definition('%'.$this->getObjectManagerElementName('metadata.'.$driverType.'.class%'), [
array_values($driverPaths),
));
]);
}
$mappingDriverDef->setPublic(false);
if (false !== strpos($mappingDriverDef->getClass(), 'yml') || false !== strpos($mappingDriverDef->getClass(), 'xml')) {
$mappingDriverDef->setArguments(array(array_flip($driverPaths)));
$mappingDriverDef->addMethodCall('setGlobalBasename', array('mapping'));
$mappingDriverDef->setArguments([array_flip($driverPaths)]);
$mappingDriverDef->addMethodCall('setGlobalBasename', ['mapping']);
}

$container->setDefinition($mappingService, $mappingDriverDef);

foreach ($driverPaths as $prefix => $driverPath) {
$chainDriverDef->addMethodCall('addDriver', array(new Reference($mappingService), $prefix));
$chainDriverDef->addMethodCall('addDriver', [new Reference($mappingService), $prefix]);
}
}

Expand All @@ -240,7 +240,7 @@ protected function assertValidMappingConfiguration(array $mappingConfig, $object
throw new \InvalidArgumentException(sprintf('Specified non-existing directory "%s" as Doctrine mapping source.', $mappingConfig['dir']));
}

if (!\in_array($mappingConfig['type'], array('xml', 'yml', 'annotation', 'php', 'staticphp'))) {
if (!\in_array($mappingConfig['type'], ['xml', 'yml', 'annotation', 'php', 'staticphp'])) {
throw new \InvalidArgumentException(sprintf('Can only configure "xml", "yml", "annotation", "php" or '.
'"staticphp" through the DoctrineBundle. Use your own bundle to configure other metadata drivers. '.
'You can register them by adding a new driver to the '.
Expand Down Expand Up @@ -326,11 +326,11 @@ protected function loadCacheDriver($cacheName, $objectManagerName, array $cacheD
$cacheDef = new Definition($memcacheClass);
$memcacheInstance = new Definition($memcacheInstanceClass);
$memcacheInstance->setPrivate(true);
$memcacheInstance->addMethodCall('connect', array(
$memcacheInstance->addMethodCall('connect', [
$memcacheHost, $memcachePort,
));
]);
$container->setDefinition($this->getObjectManagerElementName(sprintf('%s_memcache_instance', $objectManagerName)), $memcacheInstance);
$cacheDef->addMethodCall('setMemcache', array(new Reference($this->getObjectManagerElementName(sprintf('%s_memcache_instance', $objectManagerName)))));
$cacheDef->addMethodCall('setMemcache', [new Reference($this->getObjectManagerElementName(sprintf('%s_memcache_instance', $objectManagerName)))]);
break;
case 'memcached':
$memcachedClass = !empty($cacheDriver['class']) ? $cacheDriver['class'] : '%'.$this->getObjectManagerElementName('cache.memcached.class').'%';
Expand All @@ -340,11 +340,11 @@ protected function loadCacheDriver($cacheName, $objectManagerName, array $cacheD
$cacheDef = new Definition($memcachedClass);
$memcachedInstance = new Definition($memcachedInstanceClass);
$memcachedInstance->setPrivate(true);
$memcachedInstance->addMethodCall('addServer', array(
$memcachedInstance->addMethodCall('addServer', [
$memcachedHost, $memcachedPort,
));
]);
$container->setDefinition($this->getObjectManagerElementName(sprintf('%s_memcached_instance', $objectManagerName)), $memcachedInstance);
$cacheDef->addMethodCall('setMemcached', array(new Reference($this->getObjectManagerElementName(sprintf('%s_memcached_instance', $objectManagerName)))));
$cacheDef->addMethodCall('setMemcached', [new Reference($this->getObjectManagerElementName(sprintf('%s_memcached_instance', $objectManagerName)))]);
break;
case 'redis':
$redisClass = !empty($cacheDriver['class']) ? $cacheDriver['class'] : '%'.$this->getObjectManagerElementName('cache.redis.class').'%';
Expand All @@ -354,11 +354,11 @@ protected function loadCacheDriver($cacheName, $objectManagerName, array $cacheD
$cacheDef = new Definition($redisClass);
$redisInstance = new Definition($redisInstanceClass);
$redisInstance->setPrivate(true);
$redisInstance->addMethodCall('connect', array(
$redisInstance->addMethodCall('connect', [
$redisHost, $redisPort,
));
]);
$container->setDefinition($this->getObjectManagerElementName(sprintf('%s_redis_instance', $objectManagerName)), $redisInstance);
$cacheDef->addMethodCall('setRedis', array(new Reference($this->getObjectManagerElementName(sprintf('%s_redis_instance', $objectManagerName)))));
$cacheDef->addMethodCall('setRedis', [new Reference($this->getObjectManagerElementName(sprintf('%s_redis_instance', $objectManagerName)))]);
break;
case 'apc':
case 'apcu':
Expand Down Expand Up @@ -387,7 +387,7 @@ protected function loadCacheDriver($cacheName, $objectManagerName, array $cacheD
$cacheDriver['namespace'] = $namespace;
}

$cacheDef->addMethodCall('setNamespace', array($cacheDriver['namespace']));
$cacheDef->addMethodCall('setNamespace', [$cacheDriver['namespace']]);

$container->setDefinition($cacheDriverServiceId, $cacheDef);

Expand All @@ -410,10 +410,10 @@ protected function fixManagersAutoMappings(array $managerConfigs, array $bundles
continue 2;
}
}
$managerConfigs[$autoMappedManager]['mappings'][$bundle] = array(
$managerConfigs[$autoMappedManager]['mappings'][$bundle] = [
'mapping' => true,
'is_bundle' => true,
);
];
}
$managerConfigs[$autoMappedManager]['auto_mapping'] = false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,13 @@ private function addTaggedSubscribers(ContainerBuilder $container)

foreach ($taggedSubscribers as $taggedSubscriber) {
list($id, $tag) = $taggedSubscriber;
$connections = isset($tag['connection']) ? array($tag['connection']) : array_keys($this->connections);
$connections = isset($tag['connection']) ? [$tag['connection']] : array_keys($this->connections);
foreach ($connections as $con) {
if (!isset($this->connections[$con])) {
throw new RuntimeException(sprintf('The Doctrine connection "%s" referenced in service "%s" does not exist. Available connections names: %s', $con, $id, implode(', ', array_keys($this->connections))));
}

$this->getEventManagerDef($container, $con)->addMethodCall('addEventSubscriber', array(new Reference($id)));
$this->getEventManagerDef($container, $con)->addMethodCall('addEventSubscriber', [new Reference($id)]);
}
}
}
Expand All @@ -88,7 +88,7 @@ private function addTaggedListeners(ContainerBuilder $container)
throw new InvalidArgumentException(sprintf('Doctrine event listener "%s" must specify the "event" attribute.', $id));
}

$connections = isset($tag['connection']) ? array($tag['connection']) : array_keys($this->connections);
$connections = isset($tag['connection']) ? [$tag['connection']] : array_keys($this->connections);
foreach ($connections as $con) {
if (!isset($this->connections[$con])) {
throw new RuntimeException(sprintf('The Doctrine connection "%s" referenced in service "%s" does not exist. Available connections names: %s', $con, $id, implode(', ', array_keys($this->connections))));
Expand All @@ -99,7 +99,7 @@ private function addTaggedListeners(ContainerBuilder $container)
}

// we add one call per event per service so we have the correct order
$this->getEventManagerDef($container, $con)->addMethodCall('addEventListener', array(array($tag['event']), $lazy ? $id : new Reference($id)));
$this->getEventManagerDef($container, $con)->addMethodCall('addEventListener', [[$tag['event']], $lazy ? $id : new Reference($id)]);
}
}
}
Expand Down Expand Up @@ -130,12 +130,12 @@ private function getEventManagerDef(ContainerBuilder $container, $name)
*/
private function findAndSortTags($tagName, ContainerBuilder $container)
{
$sortedTags = array();
$sortedTags = [];

foreach ($container->findTaggedServiceIds($tagName, true) as $serviceId => $tags) {
foreach ($tags as $attributes) {
$priority = isset($attributes['priority']) ? $attributes['priority'] : 0;
$sortedTags[$priority][] = array($serviceId, $attributes);
$sortedTags[$priority][] = [$serviceId, $attributes];
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ abstract class RegisterMappingsPass implements CompilerPassInterface
/**
* List of potential container parameters that hold the object manager name
* to register the mappings with the correct metadata driver, for example
* array('acme.manager', 'doctrine.default_entity_manager').
* ['acme.manager', 'doctrine.default_entity_manager'].
*
* @var string[]
*/
Expand Down Expand Up @@ -117,7 +117,7 @@ abstract class RegisterMappingsPass implements CompilerPassInterface
* register alias
* @param string[] $aliasMap Map of alias to namespace
*/
public function __construct($driver, array $namespaces, array $managerParameters, $driverPattern, $enabledParameter = false, $configurationPattern = '', $registerAliasMethodName = '', array $aliasMap = array())
public function __construct($driver, array $namespaces, array $managerParameters, $driverPattern, $enabledParameter = false, $configurationPattern = '', $registerAliasMethodName = '', array $aliasMap = [])
{
$this->driver = $driver;
$this->namespaces = $namespaces;
Expand Down Expand Up @@ -146,7 +146,7 @@ public function process(ContainerBuilder $container)
// Definition for a Doctrine\Common\Persistence\Mapping\Driver\MappingDriverChain
$chainDriverDef = $container->getDefinition($chainDriverDefService);
foreach ($this->namespaces as $namespace) {
$chainDriverDef->addMethodCall('addDriver', array($mappingDriverDef, $namespace));
$chainDriverDef->addMethodCall('addDriver', [$mappingDriverDef, $namespace]);
}

if (!\count($this->aliasMap)) {
Expand All @@ -157,7 +157,7 @@ public function process(ContainerBuilder $container)
// Definition of the Doctrine\...\Configuration class specific to the Doctrine flavour.
$configurationServiceDefinition = $container->getDefinition($configurationServiceName);
foreach ($this->aliasMap as $alias => $namespace) {
$configurationServiceDefinition->addMethodCall($this->registerAliasMethodName, array($alias, $namespace));
$configurationServiceDefinition->addMethodCall($this->registerAliasMethodName, [$alias, $namespace]);
}
}

Expand Down
Loading
0