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 1 commit
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
  •  
  •  
  •  
Prev Previous commit
Hunk-level array short syntax
  • Loading branch information
ostrolucky committed Dec 16, 2018
commit 32efbc4cd9a390777b469749929af6ae17758963
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);
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 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
10 changes: 5 additions & 5 deletions src/Symfony/Bridge/Doctrine/Form/DoctrineOrmTypeGuesser.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class DoctrineOrmTypeGuesser implements FormTypeGuesserInterface
{
protected $registry;

private $cache = array();
private $cache = [];

public function __construct(ManagerRegistry $registry)
{
Expand All @@ -39,7 +39,7 @@ public function __construct(ManagerRegistry $registry)
public function guessType($class, $property)
{
if (!$ret = $this->getMetadata($class)) {
return new TypeGuess('Symfony\Component\Form\Extension\Core\Type\TextType', array(), Guess::LOW_CONFIDENCE);
return new TypeGuess('Symfony\Component\Form\Extension\Core\Type\TextType', [], Guess::LOW_CONFIDENCE);
}

list($metadata, $name) = $ret;
Expand Down Expand Up @@ -133,7 +133,7 @@ public function guessMaxLength($class, $property)
return new ValueGuess($mapping['length'], Guess::HIGH_CONFIDENCE);
}

if (\in_array($ret[0]->getTypeOfField($property), array(Type::DECIMAL, Type::FLOAT))) {
if (\in_array($ret[0]->getTypeOfField($property), [Type::DECIMAL, Type::FLOAT])) {
return new ValueGuess(null, Guess::MEDIUM_CONFIDENCE);
}
}
Expand All @@ -146,7 +146,7 @@ public function guessPattern($class, $property)
{
$ret = $this->getMetadata($class);
if ($ret && isset($ret[0]->fieldMappings[$property]) && !$ret[0]->hasAssociation($property)) {
if (\in_array($ret[0]->getTypeOfField($property), array(Type::DECIMAL, Type::FLOAT))) {
if (\in_array($ret[0]->getTypeOfField($property), [Type::DECIMAL, Type::FLOAT])) {
return new ValueGuess(null, Guess::MEDIUM_CONFIDENCE);
}
}
Expand All @@ -164,7 +164,7 @@ protected function getMetadata($class)
$this->cache[$class] = null;
foreach ($this->registry->getManagers() as $name => $em) {
try {
return $this->cache[$class] = array($em->getClassMetadata($class), $name);
return $this->cache[$class] = [$em->getClassMetadata($class), $name];
} catch (MappingException $e) {
// not an entity or mapped super class
} catch (LegacyMappingException $e) {
Expand Down
8 changes: 4 additions & 4 deletions src/Symfony/Bridge/Doctrine/Form/Type/EntityType.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function configureOptions(OptionsResolver $resolver)
};

$resolver->setNormalizer('query_builder', $queryBuilderNormalizer);
$resolver->setAllowedTypes('query_builder', array('null', 'callable', 'Doctrine\ORM\QueryBuilder'));
$resolver->setAllowedTypes('query_builder', ['null', 'callable', 'Doctrine\ORM\QueryBuilder']);
}

/**
Expand Down Expand Up @@ -78,10 +78,10 @@ public function getBlockPrefix()
*/
public function getQueryBuilderPartsForCachingHash($queryBuilder)
{
return array(
return [
$queryBuilder->getQuery()->getSQL(),
array_map(array($this, 'parameterToArray'), $queryBuilder->getParameters()->toArray()),
);
array_map([$this, 'parameterToArray'], $queryBuilder->getParameters()->toArray()),
];
}

/**
Expand Down
Loading
0