Skip to content

Commit

Permalink
minor symfony#38858 Use short array deconstruction syntax (derrabus)
Browse files Browse the repository at this point in the history
This PR was merged into the 4.4 branch.

Discussion
----------

Use short array deconstruction syntax

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | no
| New feature?  | no
| Deprecations? | no
| Tickets       | N/A
| License       | MIT
| Doc PR        | N/A

Now that the support for the 3.4 branch is coming to an end, I think we should consider banning a relic from old php 5 times from our codebase: The old array deconstructor `list()`. Right now, both deconstructors `list()` and `[]` are being used, with `list()` being the more common one.

The changes in this PR were done with PHP CS Fixer and I can easily redo them later if we decide that the time of this PR hasn't come yet. 😃

Commits
-------

659decf Use short array deconstruction syntax.
  • Loading branch information
derrabus committed Oct 28, 2020
2 parents 051cf5f + 659decf commit 2fb61a4
Show file tree
Hide file tree
Showing 106 changed files with 215 additions and 214 deletions.
1 change: 1 addition & 0 deletions .php_cs.dist
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ return PhpCsFixer\Config::create()
'protected_to_private' => false,
'native_constant_invocation' => true,
'combine_nested_dirname' => true,
'list_syntax' => ['syntax' => 'short'],
])
->setRiskyAllowed(true)
->setFinder(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ private function sanitizeQuery(string $connectionName, array $query): array
}
}

list($query['params'][$j], $explainable, $runnable) = $this->sanitizeParam($param, $e);
[$query['params'][$j], $explainable, $runnable] = $this->sanitizeParam($param, $e);
if (!$explainable) {
$query['explainable'] = false;
}
Expand Down Expand Up @@ -231,7 +231,7 @@ private function sanitizeParam($var, ?\Throwable $error): array
$a = [];
$explainable = $runnable = true;
foreach ($var as $k => $v) {
list($value, $e, $r) = $this->sanitizeParam($v, null);
[$value, $e, $r] = $this->sanitizeParam($v, null);
$explainable = $explainable && $e;
$runnable = $runnable && $r;
$a[$k] = $value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ private function addTaggedSubscribers(ContainerBuilder $container)
$taggedSubscribers = $this->findAndSortTags($subscriberTag, $container);

foreach ($taggedSubscribers as $taggedSubscriber) {
list($id, $tag) = $taggedSubscriber;
[$id, $tag] = $taggedSubscriber;
$connections = isset($tag['connection']) ? [$tag['connection']] : array_keys($this->connections);
foreach ($connections as $con) {
if (!isset($this->connections[$con])) {
Expand All @@ -84,7 +84,7 @@ private function addTaggedListeners(ContainerBuilder $container)
$listenerRefs = [];

foreach ($taggedListeners as $taggedListener) {
list($id, $tag) = $taggedListener;
[$id, $tag] = $taggedListener;
if (!isset($tag['event'])) {
throw new InvalidArgumentException(sprintf('Doctrine event listener "%s" must specify the "event" attribute.', $id));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function guessType($class, $property)
return new TypeGuess('Symfony\Component\Form\Extension\Core\Type\TextType', [], Guess::LOW_CONFIDENCE);
}

list($metadata, $name) = $ret;
[$metadata, $name] = $ret;

if ($metadata->hasAssociation($property)) {
$multiple = $metadata->isCollectionValuedAssociation($property);
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Bridge/Monolog/Tests/LoggerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public function testGetLogsWithDebugProcessor2()

$logger->info('test');
$this->assertCount(1, $logger->getLogs());
list($record) = $logger->getLogs();
[$record] = $logger->getLogs();

$this->assertEquals('test', $record['message']);
$this->assertEquals(Logger::INFO, $record['priority']);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class WebProcessorTest extends TestCase
{
public function testUsesRequestServerData()
{
list($event, $server) = $this->createRequestEvent();
[$event, $server] = $this->createRequestEvent();

$processor = new WebProcessor();
$processor->onKernelRequest($event);
Expand All @@ -39,7 +39,7 @@ public function testUsesRequestServerData()
public function testUseRequestClientIp()
{
Request::setTrustedProxies(['192.168.0.1'], Request::HEADER_X_FORWARDED_ALL);
list($event, $server) = $this->createRequestEvent(['X_FORWARDED_FOR' => '192.168.0.2']);
[$event, $server] = $this->createRequestEvent(['X_FORWARDED_FOR' => '192.168.0.2']);

$processor = new WebProcessor();
$processor->onKernelRequest($event);
Expand All @@ -61,7 +61,7 @@ public function testCanBeConstructedWithExtraFields()
$this->markTestSkipped('WebProcessor of the installed Monolog version does not support $extraFields parameter');
}

list($event, $server) = $this->createRequestEvent();
[$event, $server] = $this->createRequestEvent();

$processor = new WebProcessor(['url', 'referrer']);
$processor->onKernelRequest($event);
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Bridge/Twig/Command/DebugCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ private function displayPathsText(SymfonyStyle $io, string $name)
$shortnames[] = str_replace('\\', '/', $file->getRelativePathname());
}

list($namespace, $shortname) = $this->parseTemplateName($name);
[$namespace, $shortname] = $this->parseTemplateName($name);
$alternatives = $this->findAlternatives($shortname, $shortnames);
if (FilesystemLoader::MAIN_NAMESPACE !== $namespace) {
$alternatives = array_map(function ($shortname) use ($namespace) {
Expand Down Expand Up @@ -482,7 +482,7 @@ private function error(SymfonyStyle $io, string $message, array $alternatives =

private function findTemplateFiles(string $name): array
{
list($namespace, $shortname) = $this->parseTemplateName($name);
[$namespace, $shortname] = $this->parseTemplateName($name);

$files = [];
foreach ($this->getFilesystemLoaders() as $loader) {
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Bridge/Twig/Extension/CodeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function abbrClass($class)
public function abbrMethod($method)
{
if (false !== strpos($method, '::')) {
list($class, $method) = explode('::', $method, 2);
[$class, $method] = explode('::', $method, 2);
$result = sprintf('%s::%s()', $this->abbrClass($class), $method);
} elseif ('Closure' === $method) {
$result = sprintf('<abbr title="%s">%1$s</abbr>', $method);
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Bridge/Twig/Node/TransNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function compile(Compiler $compiler)
$defaults = $this->getNode('vars');
$vars = null;
}
list($msg, $defaults) = $this->compileString($this->getNode('body'), $defaults, (bool) $vars);
[$msg, $defaults] = $this->compileString($this->getNode('body'), $defaults, (bool) $vars);

$compiler
->write('echo $this->env->getExtension(\'Symfony\Bridge\Twig\Extension\TranslationExtension\')->trans(')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function parse($controller)
}

$originalController = $controller;
list($bundleName, $controller, $action) = $parts;
[$bundleName, $controller, $action] = $parts;
$controller = str_replace('/', '\\', $controller);

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,7 @@ private function registerProfilerConfiguration(array $config, ContainerBuilder $
$container->setParameter('profiler_listener.only_master_requests', $config['only_master_requests']);

// Choose storage class based on the DSN
list($class) = explode(':', $config['dsn'], 2);
[$class] = explode(':', $config['dsn'], 2);
if ('file' !== $class) {
throw new \LogicException(sprintf('Driver "%s" is not supported for the profiler.', $class));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public function abbrClass($class)
public function abbrMethod($method)
{
if (false !== strpos($method, '::')) {
list($class, $method) = explode('::', $method, 2);
[$class, $method] = explode('::', $method, 2);
$result = sprintf('%s::%s()', $this->abbrClass($class), $method);
} elseif ('Closure' === $method) {
$result = sprintf('<abbr title="%s">%1$s</abbr>', $method);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public function showFlashAction(Request $request)
$session = $request->getSession();

if ($session->getFlashBag()->has('notice')) {
list($output) = $session->getFlashBag()->get('notice');
[$output] = $session->getFlashBag()->get('notice');
} else {
$output = 'No flash was set.';
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ protected function initialize()
$this->addResourceFiles();
}
foreach ($this->resources as $key => $params) {
list($format, $resource, $locale, $domain) = $params;
[$format, $resource, $locale, $domain] = $params;
parent::addResource($format, $resource, $locale, $domain);
}
$this->resources = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ private function createFirewalls(array $config, ContainerBuilder $container)

$configId = 'security.firewall.map.config.'.$name;

list($matcher, $listeners, $exceptionListener, $logoutListener) = $this->createFirewall($container, $name, $firewall, $authenticationProviders, $providerIds, $configId);
[$matcher, $listeners, $exceptionListener, $logoutListener] = $this->createFirewall($container, $name, $firewall, $authenticationProviders, $providerIds, $configId);

$contextId = 'security.firewall.map.context.'.$name;
$context = new ChildDefinition($firewall['stateless'] || empty($firewall['anonymous']['lazy']) ? 'security.firewall.context' : 'security.firewall.lazy_context');
Expand Down Expand Up @@ -397,7 +397,7 @@ private function createFirewall(ContainerBuilder $container, string $id, array $
$configuredEntryPoint = isset($firewall['entry_point']) ? $firewall['entry_point'] : null;

// Authentication listeners
list($authListeners, $defaultEntryPoint) = $this->createAuthenticationListeners($container, $id, $firewall, $authenticationProviders, $defaultProvider, $providerIds, $configuredEntryPoint, $contextListenerId);
[$authListeners, $defaultEntryPoint] = $this->createAuthenticationListeners($container, $id, $firewall, $authenticationProviders, $defaultProvider, $providerIds, $configuredEntryPoint, $contextListenerId);

$config->replaceArgument(7, $configuredEntryPoint ?: $defaultEntryPoint);

Expand Down Expand Up @@ -479,7 +479,7 @@ private function createAuthenticationListeners(ContainerBuilder $container, stri
throw new InvalidConfigurationException(sprintf('Not configuring explicitly the provider for the "%s" listener on "%s" firewall is ambiguous as there is more than one registered provider.', $key, $id));
}

list($provider, $listenerId, $defaultEntryPoint) = $factory->create($container, $id, $firewall[$key], $userProvider, $defaultEntryPoint);
[$provider, $listenerId, $defaultEntryPoint] = $factory->create($container, $id, $firewall[$key], $userProvider, $defaultEntryPoint);

$listeners[] = new Reference($listenerId);
$authenticationProviders[] = $provider;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ public function testAccess()
}

$matcherIds = [];
foreach ($rules as list($matcherId, $attributes, $channel)) {
foreach ($rules as [$matcherId, $attributes, $channel]) {
$requestMatcher = $container->getDefinition($matcherId);

$this->assertArrayNotHasKey($matcherId, $matcherIds);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class AbstractFactoryTest extends TestCase
{
public function testCreate()
{
list($container, $authProviderId, $listenerId, $entryPointId) = $this->callFactory('foo', [
[$container, $authProviderId, $listenerId, $entryPointId] = $this->callFactory('foo', [
'use_forward' => true,
'failure_path' => '/foo',
'success_handler' => 'custom_success_handler',
Expand Down Expand Up @@ -61,7 +61,7 @@ public function testDefaultFailureHandler($serviceId, $defaultHandlerInjection)
$options['failure_handler'] = $serviceId;
}

list($container) = $this->callFactory('foo', $options, 'user_provider', 'entry_point');
[$container] = $this->callFactory('foo', $options, 'user_provider', 'entry_point');

$definition = $container->getDefinition('abstract_listener.foo');
$arguments = $definition->getArguments();
Expand Down Expand Up @@ -99,7 +99,7 @@ public function testDefaultSuccessHandler($serviceId, $defaultHandlerInjection)
$options['success_handler'] = $serviceId;
}

list($container) = $this->callFactory('foo', $options, 'user_provider', 'entry_point');
[$container] = $this->callFactory('foo', $options, 'user_provider', 'entry_point');

$definition = $container->getDefinition('abstract_listener.foo');
$arguments = $definition->getArguments();
Expand Down Expand Up @@ -150,7 +150,7 @@ protected function callFactory($id, $config, $userProviderId, $defaultEntryPoint
$container->register('custom_success_handler');
$container->register('custom_failure_handler');

list($authProviderId, $listenerId, $entryPointId) = $factory->create($container, $id, $config, $userProviderId, $defaultEntryPointId);
[$authProviderId, $listenerId, $entryPointId] = $factory->create($container, $id, $config, $userProviderId, $defaultEntryPointId);

return [$container, $authProviderId, $listenerId, $entryPointId];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public function testBasicCreate()
'authenticators' => ['authenticator123'],
'entry_point' => null,
];
list($container, $entryPointId) = $this->executeCreate($config, null);
[$container, $entryPointId] = $this->executeCreate($config, null);
$this->assertEquals('authenticator123', $entryPointId);

$providerDefinition = $container->getDefinition('security.authentication.provider.guard.my_firewall');
Expand All @@ -126,7 +126,7 @@ public function testExistingDefaultEntryPointUsed()
'authenticators' => ['authenticator123'],
'entry_point' => null,
];
list(, $entryPointId) = $this->executeCreate($config, 'some_default_entry_point');
[, $entryPointId] = $this->executeCreate($config, 'some_default_entry_point');
$this->assertEquals('some_default_entry_point', $entryPointId);
}

Expand Down Expand Up @@ -159,7 +159,7 @@ public function testCreateWithEntryPoint()
'authenticators' => ['authenticator123', 'authenticatorABC'],
'entry_point' => 'authenticatorABC',
];
list(, $entryPointId) = $this->executeCreate($config, null);
[, $entryPointId] = $this->executeCreate($config, null);
$this->assertEquals('authenticatorABC', $entryPointId);
}

Expand All @@ -172,7 +172,7 @@ private function executeCreate(array $config, $defaultEntryPointId)
$userProviderId = 'my_user_provider';

$factory = new GuardAuthenticationFactory();
list(, , $entryPointId) = $factory->create($container, $id, $config, $userProviderId, $defaultEntryPointId);
[, , $entryPointId] = $factory->create($container, $id, $config, $userProviderId, $defaultEntryPointId);

return [$container, $entryPointId];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public function getNames(Profile $profile)
continue;
}

list($name, $template) = $arguments;
[$name, $template] = $arguments;

if (!$this->profiler->has($name) || !$profile->hasCollector($name)) {
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$server = new WebServer($this->pidFileDirectory);
if ($filter = $input->getOption('filter')) {
if ($server->isRunning($input->getOption('pidfile'))) {
list($host, $port) = explode(':', $address = $server->getAddress($input->getOption('pidfile')));
[$host, $port] = explode(':', $address = $server->getAddress($input->getOption('pidfile')));
if ('address' === $filter) {
$output->write($address);
} elseif ('host' === $filter) {
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/BrowserKit/Cookie.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public static function fromString($cookie, $url = null)
throw new \InvalidArgumentException(sprintf('The cookie string "%s" is not valid.', $parts[0]));
}

list($name, $value) = explode('=', array_shift($parts), 2);
[$name, $value] = explode('=', array_shift($parts), 2);

$values = [
'name' => trim($name),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public function save(CacheItemInterface $item): bool
$this->keys[$key] = $id = \count($this->values);
$this->data[$key] = $this->values[$id] = $item->get();
$this->warmUp($this->data);
list($this->keys, $this->values) = eval(substr(file_get_contents($this->file), 6));
[$this->keys, $this->values] = eval(substr(file_get_contents($this->file), 6));
}, $this, PhpArrayAdapter::class))();

return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function set($key, $value, $ttl = null): bool
(\Closure::bind(function () use ($key, $value) {
$this->data[$key] = $value;
$this->warmUp($this->data);
list($this->keys, $this->values) = eval(substr(file_get_contents($this->file), 6));
[$this->keys, $this->values] = eval(substr(file_get_contents($this->file), 6));
}, $this, PhpArrayCache::class))();

return true;
Expand All @@ -38,7 +38,7 @@ public function setMultiple($values, $ttl = null): bool
$this->data[$key] = $value;
}
$this->warmUp($this->data);
list($this->keys, $this->values) = eval(substr(file_get_contents($this->file), 6));
[$this->keys, $this->values] = eval(substr(file_get_contents($this->file), 6));
}, $this, PhpArrayCache::class))();

return true;
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Cache/Traits/MemcachedTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public static function createConnection($servers, array $options = [])
}
$params = preg_replace_callback('#^memcached:(//)?(?:([^@]*+)@)?#', function ($m) use (&$username, &$password) {
if (!empty($m[2])) {
list($username, $password) = explode(':', $m[2], 2) + [1 => null];
[$username, $password] = explode(':', $m[2], 2) + [1 => null];
}

return 'file:'.($m[1] ?? '');
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Cache/Traits/PhpArrayTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ private function initialize()
if (2 !== \count($values) || !isset($values[0], $values[1])) {
$this->keys = $this->values = [];
} else {
list($this->keys, $this->values) = $values;
[$this->keys, $this->values] = $values;
}
}
}
2 changes: 1 addition & 1 deletion src/Symfony/Component/Cache/Traits/RedisTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ private function pipeline(\Closure $generator, $redis = null): \Generator
foreach ($connections as $h => $c) {
$connections[$h] = $c[0]->exec();
}
foreach ($results as $k => list($h, $c)) {
foreach ($results as $k => [$h, $c]) {
$results[$k] = $connections[$h][$c];
}
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Config/Definition/ArrayNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ protected function normalizeValue($value)
*/
protected function remapXml($value)
{
foreach ($this->xmlRemappings as list($singular, $plural)) {
foreach ($this->xmlRemappings as [$singular, $plural]) {
if (!isset($value[$singular])) {
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ private function writeNode(NodeInterface $node, int $depth = 0, bool $root = fal
});

if (\count($remapping)) {
list($singular) = current($remapping);
[$singular] = current($remapping);
$rootName = $singular;
}
}
Expand Down
Loading

0 comments on commit 2fb61a4

Please sign in to comment.