Ver código fonte

Cleaned up unused code, variables and private methods for Tree

Jonathan Ingram 13 anos atrás
pai
commit
4a8020ec24

+ 2 - 2
lib/Gedmo/Tree/Entity/Repository/AbstractTreeRepository.php

@@ -22,8 +22,8 @@ abstract class AbstractTreeRepository extends EntityRepository
     {
         parent::__construct($em, $class);
         $treeListener = null;
-        foreach ($em->getEventManager()->getListeners() as $event => $listeners) {
-            foreach ($listeners as $hash => $listener) {
+        foreach ($em->getEventManager()->getListeners() as $listeners) {
+            foreach ($listeners as $listener) {
                 if ($listener instanceof \Gedmo\Tree\TreeListener) {
                     $treeListener = $listener;
                     break;

+ 0 - 2
lib/Gedmo/Tree/Entity/Repository/ClosureTreeRepository.php

@@ -232,7 +232,6 @@ class ClosureTreeRepository extends AbstractTreeRepository
         }
         $config = $this->listener->getConfiguration($this->_em, $meta->name);
         $pk = $meta->getSingleIdentifierFieldName();
-        $nodeId = $wrapped->getIdentifier();
         $parent = $wrapped->getPropertyValue($config['parent']);
 
         $dql = "SELECT node FROM {$config['useObjectClass']} node";
@@ -244,7 +243,6 @@ class ClosureTreeRepository extends AbstractTreeRepository
         $this->_em->getConnection()->beginTransaction();
         try {
             foreach ($nodesToReparent as $nodeToReparent) {
-                $id = $meta->getReflectionProperty($pk)->getValue($nodeToReparent);
                 $meta->getReflectionProperty($config['parent'])->setValue($nodeToReparent, $parent);
 
                 $dql = "UPDATE {$config['useObjectClass']} node";

+ 0 - 2
lib/Gedmo/Tree/Entity/Repository/NestedTreeRepository.php

@@ -545,7 +545,6 @@ class NestedTreeRepository extends AbstractTreeRepository
         $result = false;
         $meta = $this->getClassMetadata();
         if ($node instanceof $meta->name) {
-            $config = $this->listener->getConfiguration($this->_em, $meta->name);
             $nextSiblings = $this->getNextSiblings($node);
             if ($numSiblings = count($nextSiblings)) {
                 $result = true;
@@ -579,7 +578,6 @@ class NestedTreeRepository extends AbstractTreeRepository
         $result = false;
         $meta = $this->getClassMetadata();
         if ($node instanceof $meta->name) {
-            $config = $this->listener->getConfiguration($this->_em, $meta->name);
             $prevSiblings = array_reverse($this->getPrevSiblings($node));
             if ($numSiblings = count($prevSiblings)) {
                 $result = true;

+ 5 - 52
lib/Gedmo/Tree/Mapping/Driver/Annotation.php

@@ -123,7 +123,7 @@ class Annotation implements AnnotationDriverInterface
                 continue;
             }
             // left
-            if ($left = $this->reader->getPropertyAnnotation($property, self::LEFT)) {
+            if ($this->reader->getPropertyAnnotation($property, self::LEFT)) {
                 $field = $property->getName();
                 if (!$meta->hasField($field)) {
                     throw new InvalidMappingException("Unable to find 'left' - [{$field}] as mapped property in entity - {$meta->name}");
@@ -134,7 +134,7 @@ class Annotation implements AnnotationDriverInterface
                 $config['left'] = $field;
             }
             // right
-            if ($right = $this->reader->getPropertyAnnotation($property, self::RIGHT)) {
+            if ($this->reader->getPropertyAnnotation($property, self::RIGHT)) {
                 $field = $property->getName();
                 if (!$meta->hasField($field)) {
                     throw new InvalidMappingException("Unable to find 'right' - [{$field}] as mapped property in entity - {$meta->name}");
@@ -145,7 +145,7 @@ class Annotation implements AnnotationDriverInterface
                 $config['right'] = $field;
             }
             // ancestor/parent
-            if ($parent = $this->reader->getPropertyAnnotation($property, self::PARENT)) {
+            if ($this->reader->getPropertyAnnotation($property, self::PARENT)) {
                 $field = $property->getName();
                 if (!$meta->isSingleValuedAssociation($field)) {
                     throw new InvalidMappingException("Unable to find ancestor/parent child relation through ancestor field - [{$field}] in class - {$meta->name}");
@@ -153,7 +153,7 @@ class Annotation implements AnnotationDriverInterface
                 $config['parent'] = $field;
             }
             // root
-            if ($root = $this->reader->getPropertyAnnotation($property, self::ROOT)) {
+            if ($this->reader->getPropertyAnnotation($property, self::ROOT)) {
                 $field = $property->getName();
                 if (!$meta->hasField($field)) {
                     throw new InvalidMappingException("Unable to find 'root' - [{$field}] as mapped property in entity - {$meta->name}");
@@ -164,7 +164,7 @@ class Annotation implements AnnotationDriverInterface
                 $config['root'] = $field;
             }
             // level
-            if ($parent = $this->reader->getPropertyAnnotation($property, self::LEVEL)) {
+            if ($this->reader->getPropertyAnnotation($property, self::LEVEL)) {
                 $field = $property->getName();
                 if (!$meta->hasField($field)) {
                     throw new InvalidMappingException("Unable to find 'level' - [{$field}] as mapped property in entity - {$meta->name}");
@@ -202,53 +202,6 @@ class Annotation implements AnnotationDriverInterface
         return $mapping && in_array($mapping['type'], $this->validTypes);
     }
 
-    /**
-     * Validates metadata for nested type tree
-     *
-     * @param object $meta
-     * @param array $config
-     * @throws InvalidMappingException
-     * @return void
-     */
-    private function validateNestedTreeMetadata($meta, array $config)
-    {
-        $missingFields = array();
-        if (!isset($config['parent'])) {
-            $missingFields[] = 'ancestor';
-        }
-        if (!isset($config['left'])) {
-            $missingFields[] = 'left';
-        }
-        if (!isset($config['right'])) {
-            $missingFields[] = 'right';
-        }
-        if ($missingFields) {
-            throw new InvalidMappingException("Missing properties: " . implode(', ', $missingFields) . " in class - {$meta->name}");
-        }
-    }
-
-    /**
-     * Validates metadata for closure type tree
-     *
-     * @param object $meta
-     * @param array $config
-     * @throws InvalidMappingException
-     * @return void
-     */
-    private function validateClosureTreeMetadata($meta, array $config)
-    {
-        $missingFields = array();
-        if (!isset($config['parent'])) {
-            $missingFields[] = 'ancestor';
-        }
-        if (!isset($config['closure'])) {
-            $missingFields[] = 'closure class';
-        }
-        if ($missingFields) {
-            throw new InvalidMappingException("Missing properties: " . implode(', ', $missingFields) . " in class - {$meta->name}");
-        }
-    }
-
     /**
      * Passes in the mapping read by original driver
      *

+ 0 - 47
lib/Gedmo/Tree/Mapping/Driver/Xml.php

@@ -141,51 +141,4 @@ class Xml extends BaseXml
         $mapping = $meta->getFieldMapping($field);
         return $mapping && in_array($mapping['type'], $this->validTypes);
     }
-
-    /**
-     * Validates metadata for nested type tree
-     *
-     * @param object $meta
-     * @param array $config
-     * @throws InvalidMappingException
-     * @return void
-     */
-    private function validateNestedTreeMetadata($meta, array $config)
-    {
-        $missingFields = array();
-        if (!isset($config['parent'])) {
-            $missingFields[] = 'ancestor';
-        }
-        if (!isset($config['left'])) {
-            $missingFields[] = 'left';
-        }
-        if (!isset($config['right'])) {
-            $missingFields[] = 'right';
-        }
-        if ($missingFields) {
-            throw new InvalidMappingException("Missing properties: " . implode(', ', $missingFields) . " in class - {$meta->name}");
-        }
-    }
-
-    /**
-     * Validates metadata for closure type tree
-     *
-     * @param object $meta
-     * @param array $config
-     * @throws InvalidMappingException
-     * @return void
-     */
-    private function validateClosureTreeMetadata($meta, array $config)
-    {
-        $missingFields = array();
-        if (!isset($config['parent'])) {
-            $missingFields[] = 'ancestor';
-        }
-        if (!isset($config['closure'])) {
-            $missingFields[] = 'closure class';
-        }
-        if ($missingFields) {
-            throw new InvalidMappingException("Missing properties: " . implode(', ', $missingFields) . " in class - {$meta->name}");
-        }
-    }
 }

+ 0 - 47
lib/Gedmo/Tree/Mapping/Driver/Yaml.php

@@ -144,51 +144,4 @@ class Yaml extends File implements Driver
         $mapping = $meta->getFieldMapping($field);
         return $mapping && in_array($mapping['type'], $this->validTypes);
     }
-
-    /**
-     * Validates metadata for nested type tree
-     *
-     * @param object $meta
-     * @param array $config
-     * @throws InvalidMappingException
-     * @return void
-     */
-    private function validateNestedTreeMetadata($meta, array $config)
-    {
-        $missingFields = array();
-        if (!isset($config['parent'])) {
-            $missingFields[] = 'ancestor';
-        }
-        if (!isset($config['left'])) {
-            $missingFields[] = 'left';
-        }
-        if (!isset($config['right'])) {
-            $missingFields[] = 'right';
-        }
-        if ($missingFields) {
-            throw new InvalidMappingException("Missing properties: " . implode(', ', $missingFields) . " in class - {$meta->name}");
-        }
-    }
-
-    /**
-     * Validates metadata for closure type tree
-     *
-     * @param object $meta
-     * @param array $config
-     * @throws InvalidMappingException
-     * @return void
-     */
-    private function validateClosureTreeMetadata($meta, array $config)
-    {
-        $missingFields = array();
-        if (!isset($config['parent'])) {
-            $missingFields[] = 'ancestor';
-        }
-        if (!isset($config['closure'])) {
-            $missingFields[] = 'closure class';
-        }
-        if ($missingFields) {
-            throw new InvalidMappingException("Missing properties: " . implode(', ', $missingFields) . " in class - {$meta->name}");
-        }
-    }
 }

+ 1 - 1
lib/Gedmo/Tree/Strategy/ORM/Closure.php

@@ -270,7 +270,7 @@ class Closure implements Strategy
             }
         }
         if ($parent) {
-            $parentId = $this->extractIdentifier($em, $parent);
+            $this->extractIdentifier($em, $parent);
             $query = "SELECT c1.ancestor, c2.descendant, (c1.depth + c2.depth + 1) AS depth";
             $query .= " FROM {$table} c1, {$table} c2";
             $query .= " WHERE c1.descendant = :parentId";

+ 3 - 4
lib/Gedmo/Tree/TreeListener.php

@@ -139,7 +139,7 @@ class TreeListener extends MappedEventSubscriber
         $object = $ea->getObject();
         $meta = $om->getClassMetadata(get_class($object));
 
-        if ($config = $this->getConfiguration($om, $meta->name)) {
+        if ($this->getConfiguration($om, $meta->name)) {
             $this->getStrategy($om, $meta->name)->processPreRemove($om, $object);
         }
     }
@@ -157,7 +157,7 @@ class TreeListener extends MappedEventSubscriber
         $object = $ea->getObject();
         $meta = $om->getClassMetadata(get_class($object));
 
-        if ($config = $this->getConfiguration($om, $meta->name)) {
+        if ($this->getConfiguration($om, $meta->name)) {
             $this->getStrategy($om, $meta->name)->processPrePersist($om, $object);
         }
     }
@@ -176,7 +176,7 @@ class TreeListener extends MappedEventSubscriber
         $object = $ea->getObject();
         $meta = $om->getClassMetadata(get_class($object));
 
-        if ($config = $this->getConfiguration($om, $meta->name)) {
+        if ($this->getConfiguration($om, $meta->name)) {
             $this->getStrategy($om, $meta->name)->processPostPersist($om, $object);
         }
     }
@@ -194,7 +194,6 @@ class TreeListener extends MappedEventSubscriber
         $meta = $eventArgs->getClassMetadata();
         $this->loadMetadataForObjectClass($om, $meta);
         if (isset($this->configurations[$meta->name]) && $this->configurations[$meta->name]) {
-            $config = $this->configurations[$meta->name];
             $this->getStrategy($om, $meta->name)->processMetadataLoad($om, $meta);
         }
     }