From 8714d7924e65c26e15f93cb5ff745807a533d1be Mon Sep 17 00:00:00 2001 From: Bernhard Schussek Date: Thu, 2 Feb 2012 13:58:41 +0100 Subject: [PATCH] [Form] Simplified code in MergeCollectionListener --- .../EventListener/MergeCollectionListener.php | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/Symfony/Component/Form/Extension/Core/EventListener/MergeCollectionListener.php b/src/Symfony/Component/Form/Extension/Core/EventListener/MergeCollectionListener.php index 2586f677ac..8249a81d2f 100644 --- a/src/Symfony/Component/Form/Extension/Core/EventListener/MergeCollectionListener.php +++ b/src/Symfony/Component/Form/Extension/Core/EventListener/MergeCollectionListener.php @@ -98,28 +98,26 @@ class MergeCollectionListener implements EventSubscriberInterface // Check if the parent has matching methods to add/remove items if ($this->useAccessors && is_object($parentData)) { $reflClass = new \ReflectionClass($parentData); + $addMethodNeeded = $this->allowAdd && !$this->addMethod; + $removeMethodNeeded = $this->allowDelete && !$this->removeMethod; // Any of the two methods is required, but not yet known - if (($this->allowAdd && !$this->addMethod) || ($this->allowDelete && !$this->removeMethod)) { - $plural = ucfirst($form->getName()); - $singulars = (array) FormUtil::singularify($plural); + if ($addMethodNeeded || $removeMethodNeeded) { + $singulars = (array) FormUtil::singularify(ucfirst($form->getName())); foreach ($singulars as $singular) { // Try to find adder, but don't override preconfigured one - if ($this->allowAdd && !$this->addMethod) { + if ($addMethodNeeded) { $addMethod = $this->checkMethod($reflClass, 'add' . $singular); } // Try to find remover, but don't override preconfigured one - if ($this->allowDelete && !$this->removeMethod) { + if ($removeMethodNeeded) { $removeMethod = $this->checkMethod($reflClass, 'remove' . $singular); } - $addMethodFound = !$this->allowAdd || $addMethod || $this->addMethod; - $removeMethodFound = !$this->allowDelete || $removeMethod || $this->removeMethod; - // Found all that we need. Abort search. - if ($addMethodFound && $removeMethodFound) { + if ((!$addMethodNeeded || $addMethod) && (!$removeMethodNeeded || $removeMethod)) { break; }