8000 Use short array syntax by ostrolucky · Pull Request #29623 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

Use short array syntax #29623

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

Closed
wants to merge 2 commits into from
Closed
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
  •  
  •  
  •  
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
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
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 @@ -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);
forea 28BE ch ($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 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 @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public function loadValuesForChoices(array $choices, $value = null)
{
// Performance optimization
if (empty($choices)) {
return array();
return [];
}

// Optimize performance for single-field identifiers. We already
Expand All @@ -101,7 +101,7 @@ public function loadValuesForChoices(array $choices, $value = null)

// Attention: This optimization does not check choices for existence
if ($optimize && !$this->choiceList && $this->idReader->isSingleId()) {
$values = array();
$values = [];

// Maintain order and indices of the given objects
foreach ($choices as $i => $object) {
Expand Down Expand Up @@ -129,7 +129,7 @@ public function loadChoicesForValues(array $values, $value = null)
// statements, consequently no test fails when this code is removed.
// https://github.com/symfony/symfony/pull/8981#issuecomment-24230557
if (empty($values)) {
return array();
return [];
}

// Optimize performance in case we have an object loader and
Expand All @@ -138,8 +138,8 @@ public function loadChoicesForValues(array $values, $value = null)

if ($optimize && !$this->choiceList && $this->objectLoader && $this->idReader->isSingleId()) {
$unorderedObjects = $this->objectLoader->getEntitiesByIds($this->idReader->getIdField(), $values);
$objectsById = array();
$objects = array();
$objectsById = [];
$objects = [];

// Maintain order and indices from the given $values
// An alternative approach to the following loop is to add the
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Bridge/Doctrine/Form/ChoiceList/IdReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function __construct(ObjectManager $om, ClassMetadata $classMetadata)
$this->om = $om;
$this->classMetadata = $classMetadata;
$this->singleId = 1 === \count($ids);
$this->intId = $this->singleId && \in_array($idType, array('integer', 'smallint', 'bigint'));
$this->intId = $this->singleId && \in_array($idType, ['integer', 'smallint', 'bigint']);
$this->idField = current($ids);

// single field association are resolved, since the schema column could be an int
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,15 @@ public function getEntitiesByIds($identifier, array $values)
// Guess type
$entity = current($qb->getRootEntities());
$metadata = $qb->getEntityManager()->getClassMetadata($entity);
if (\in_array($metadata->getTypeOfField($identifier), array('integer', 'bigint', 'smallint'))) {
if (\in_array($metadata->getTypeOfField($identifier), ['integer', 'bigint', 'smallint'])) {
$parameterType = Connection::PARAM_INT_ARRAY;

// Filter out non-integer values (e.g. ""). If we don't, some
// databases such as PostgreSQL fail.
$values = array_values(array_filter($values, function ($v) {
return (string) $v === (string) (int) $v || ctype_digit($v);
}));
} elseif (\in_array($metadata->getTypeOfField($identifier), array('uuid', 'guid'))) {
} elseif (\in_array($metadata->getTypeOfField($identifier), ['uuid', 'guid'])) {
$parameterType = Connection::PARAM_STR_ARRAY;

// Like above, but we just filter out empty strings.
Expand All @@ -83,7 +83,7 @@ public function getEntitiesByIds($identifier, array $values)
$parameterType = Connection::PARAM_STR_ARRAY;
}
if (!$values) {
return array();
return [];
}

return $qb->andWhere($where)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class CollectionToArrayTransformer implements DataTransformerInterface
public function transform($collection)
{
if (null === $collection) {
return array();
return [];
}

// For cases when the collection getter returns $collection->toArray()
Expand All @@ -57,7 +57,7 @@ public function transform($collection)
public function reverseTransform($array)
{
if ('' === $array || null === $array) {
$array = array();
$array = [];
} else {
$array = (array) $array;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Bridge/Doctrine/Form/DoctrineOrmExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ public function __construct(ManagerRegistry $registry)

protected function loadTypes()
{
return array(
return [
new EntityType($this->registry),
);
];
}

protected function loadTypeGuesser()
Expand Down
Loading
0