minor #15506 Unpack nested array instead of using temp var (dosten)

This PR was squashed before being merged into the 3.0-dev branch (closes #15506).

Discussion
----------

Unpack nested array instead of using temp var

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| License       | MIT

Since php 5.5 we can [unpack nested arrays with `list()`](http://php.net/manual/en/control-structures.foreach.php#control-structures.foreach.list) to avoid temp vars.

Commits
-------

20e9ed6 Unpack nested array instead of using temp var
This commit is contained in:
Fabien Potencier 2015-08-11 23:01:43 +02:00
commit bb4dc7da7f
7 changed files with 8 additions and 19 deletions

View File

@ -159,8 +159,7 @@ class RegisterEventListenersAndSubscribersPassTest extends \PHPUnit_Framework_Te
private function getServiceOrder(ContainerBuilder $container, $method) private function getServiceOrder(ContainerBuilder $container, $method)
{ {
$order = array(); $order = array();
foreach ($container->getDefinition('doctrine.dbal.default_connection.event_manager')->getMethodCalls() as $call) { foreach ($container->getDefinition('doctrine.dbal.default_connection.event_manager')->getMethodCalls() as list($name, $arguments)) {
list($name, $arguments) = $call;
if ($method !== $name) { if ($method !== $name) {
continue; continue;
} }

View File

@ -12,7 +12,6 @@
namespace Symfony\Bundle\SecurityBundle\Tests\DependencyInjection; namespace Symfony\Bundle\SecurityBundle\Tests\DependencyInjection;
use Symfony\Component\DependencyInjection\Reference; use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\DependencyInjection\Parameter;
use Symfony\Bundle\SecurityBundle\SecurityBundle; use Symfony\Bundle\SecurityBundle\SecurityBundle;
use Symfony\Bundle\SecurityBundle\DependencyInjection\SecurityExtension; use Symfony\Bundle\SecurityBundle\DependencyInjection\SecurityExtension;
use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\ContainerBuilder;
@ -134,8 +133,7 @@ abstract class CompleteConfigurationTest extends \PHPUnit_Framework_TestCase
} }
$matcherIds = array(); $matcherIds = array();
foreach ($rules as $rule) { foreach ($rules as list($matcherId, $attributes, $channel)) {
list($matcherId, $attributes, $channel) = $rule;
$requestMatcher = $container->getDefinition($matcherId); $requestMatcher = $container->getDefinition($matcherId);
$this->assertFalse(isset($matcherIds[$matcherId])); $this->assertFalse(isset($matcherIds[$matcherId]));

View File

@ -45,8 +45,7 @@ class Psr4ClassLoader
{ {
$class = ltrim($class, '\\'); $class = ltrim($class, '\\');
foreach ($this->prefixes as $current) { foreach ($this->prefixes as list($currentPrefix, $currentBaseDir)) {
list($currentPrefix, $currentBaseDir) = $current;
if (0 === strpos($class, $currentPrefix)) { if (0 === strpos($class, $currentPrefix)) {
$classWithoutPrefix = substr($class, strlen($currentPrefix)); $classWithoutPrefix = substr($class, strlen($currentPrefix));
$file = $currentBaseDir.str_replace('\\', DIRECTORY_SEPARATOR, $classWithoutPrefix).'.php'; $file = $currentBaseDir.str_replace('\\', DIRECTORY_SEPARATOR, $classWithoutPrefix).'.php';

View File

@ -330,9 +330,7 @@ class ArrayNode extends BaseNode implements PrototypeNodeInterface
*/ */
protected function remapXml($value) protected function remapXml($value)
{ {
foreach ($this->xmlRemappings as $transformation) { foreach ($this->xmlRemappings as list($singular, $plural)) {
list($singular, $plural) = $transformation;
if (!isset($value[$singular])) { if (!isset($value[$singular])) {
continue; continue;
} }

View File

@ -35,8 +35,7 @@ class DecoratorServicePass implements CompilerPassInterface
$definitions->insert(array($id, $definition), array($decorated[2], --$order)); $definitions->insert(array($id, $definition), array($decorated[2], --$order));
} }
foreach ($definitions as $arr) { foreach ($definitions as list($id, $definition)) {
list($id, $definition) = $arr;
list($inner, $renamedId) = $definition->getDecoratedService(); list($inner, $renamedId) = $definition->getDecoratedService();
$definition->setDecoratedService(null); $definition->setDecoratedService(null);

View File

@ -295,9 +295,7 @@ class XmlFileLoader extends FileLoader
// resolve definitions // resolve definitions
krsort($definitions); krsort($definitions);
foreach ($definitions as $id => $def) { foreach ($definitions as $id => list($domElement, $file, $wild)) {
list($domElement, $file, $wild) = $def;
// anonymous services are always private // anonymous services are always private
// we could not use the constant false here, because of XML parsing // we could not use the constant false here, because of XML parsing
$domElement->setAttribute('public', 'false'); $domElement->setAttribute('public', 'false');

View File

@ -80,8 +80,7 @@ class ContainerAwareEventDispatcher extends EventDispatcher
$this->lazyLoad($eventName); $this->lazyLoad($eventName);
if (isset($this->listenerIds[$eventName])) { if (isset($this->listenerIds[$eventName])) {
foreach ($this->listenerIds[$eventName] as $i => $args) { foreach ($this->listenerIds[$eventName] as $i => list($serviceId, $method, $priority)) {
list($serviceId, $method, $priority) = $args;
$key = $serviceId.'.'.$method; $key = $serviceId.'.'.$method;
if (isset($this->listeners[$eventName][$key]) && $listener === array($this->listeners[$eventName][$key], $method)) { if (isset($this->listeners[$eventName][$key]) && $listener === array($this->listeners[$eventName][$key], $method)) {
unset($this->listeners[$eventName][$key]); unset($this->listeners[$eventName][$key]);
@ -183,8 +182,7 @@ class ContainerAwareEventDispatcher extends EventDispatcher
protected function lazyLoad($eventName) protected function lazyLoad($eventName)
{ {
if (isset($this->listenerIds[$eventName])) { if (isset($this->listenerIds[$eventName])) {
foreach ($this->listenerIds[$eventName] as $args) { foreach ($this->listenerIds[$eventName] as list($serviceId, $method, $priority)) {
list($serviceId, $method, $priority) = $args;
$listener = $this->container->get($serviceId); $listener = $this->container->get($serviceId);
$key = $serviceId.'.'.$method; $key = $serviceId.'.'.$method;