From 937ba6385e6823c183daf2230b1447dbbbedfcec Mon Sep 17 00:00:00 2001 From: Adam Prager Date: Sun, 31 Mar 2013 00:47:24 +0100 Subject: [PATCH] fixed code duplication issue --- lib/Doctrine/ORM/Tools/EntityGenerator.php | 44 +++++++++++++--------- 1 file changed, 26 insertions(+), 18 deletions(-) diff --git a/lib/Doctrine/ORM/Tools/EntityGenerator.php b/lib/Doctrine/ORM/Tools/EntityGenerator.php index 6aad04fb6..948a4e689 100644 --- a/lib/Doctrine/ORM/Tools/EntityGenerator.php +++ b/lib/Doctrine/ORM/Tools/EntityGenerator.php @@ -710,15 +710,9 @@ public function __construct() } // check traits for existing property - if (class_exists($metadata->name)) { - $reflClass = new \ReflectionClass($metadata->name); - - if (method_exists($reflClass, 'getTraits')) { - foreach ($reflClass->getTraits() as $trait) { - if ($trait->hasProperty($property)) { - return true; - } - } + foreach ($this->getTraits($metadata) as $trait) { + if ($trait->hasProperty($property)) { + return true; } } @@ -746,15 +740,9 @@ public function __construct() } // check traits for existing method - if (class_exists($metadata->name)) { - $reflClass = new \ReflectionClass($metadata->name); - - if (method_exists($reflClass, 'getTraits')) { - foreach ($reflClass->getTraits() as $trait) { - if ($trait->hasMethod($method)) { - return true; - } - } + foreach ($this->getTraits($metadata) as $trait) { + if ($trait->hasMethod($method)) { + return true; } } @@ -764,6 +752,26 @@ public function __construct() ); } + /** + * @param ClassMetadataInfo $metadata + * + * @return array + */ + protected function getTraits(ClassMetadataInfo $metadata) + { + if ($metadata->reflClass != null || class_exists($metadata->name)) { + $reflClass = $metadata->reflClass == null + ? new \ReflectionClass($metadata->name) + : $metadata->reflClass; + + if (method_exists($reflClass, 'getTraits')) { + return $reflClass->getTraits(); + } + } + + return array(); + } + /** * @param ClassMetadataInfo $metadata *