Permalink
Browse files

fixed code duplication issue

  • Loading branch information...
1 parent 9797177 commit 937ba6385e6823c183daf2230b1447dbbbedfcec @Padam87 committed Mar 30, 2013
Showing with 26 additions and 18 deletions.
  1. +26 −18 lib/Doctrine/ORM/Tools/EntityGenerator.php
@@ -710,15 +710,9 @@ protected function hasProperty($property, ClassMetadataInfo $metadata)
}
// 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 @@ protected function hasMethod($method, ClassMetadataInfo $metadata)
}
// 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;
}
}
@@ -767,6 +755,26 @@ protected function hasMethod($method, ClassMetadataInfo $metadata)
/**
* @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
+ *
* @return bool
*/
protected function hasNamespace(ClassMetadataInfo $metadata)

0 comments on commit 937ba63

Please sign in to comment.