| Conditions | 14 |
| Paths | 103 |
| Total Lines | 63 |
| Code Lines | 38 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 33 | public function loadMetadataForClass($className) |
||
| 34 | { |
||
| 35 | try { |
||
| 36 | $hasMetadata = false; |
||
| 37 | $reflectionClass = new \ReflectionClass($className); |
||
| 38 | |||
| 39 | foreach ($this->reader->getClassAnnotations($reflectionClass) as $annotation) { |
||
| 40 | if ($annotation instanceof AggregateRoot) { |
||
| 41 | $hasMetadata = true; |
||
| 42 | } elseif ($annotation instanceof Entity) { |
||
| 43 | $hasMetadata = true; |
||
| 44 | } |
||
| 45 | } |
||
| 46 | |||
| 47 | if ($hasMetadata) { |
||
| 48 | $classMetadata = new ClassMetadata($className); |
||
| 49 | foreach ($classMetadata->reflection()->getProperties() as $propertyReflection) { |
||
| 50 | foreach ($this->reader->getPropertyAnnotations($propertyReflection) as $annotation) { |
||
| 51 | if ($annotation instanceof Field) { |
||
| 52 | $propertyMetadata = new PropertyMetadata( |
||
| 53 | $classMetadata->className(), |
||
| 54 | $propertyReflection->getName() |
||
| 55 | ); |
||
| 56 | |||
| 57 | $propertyMetadata->addMetadata('identifier', $annotation->id); |
||
| 58 | if (!empty($annotation->name)) { |
||
| 59 | $propertyMetadata->addMetadata('name', $annotation->name); |
||
| 60 | } |
||
| 61 | |||
| 62 | if (!empty($annotation->type)) { |
||
| 63 | $propertyMetadata->addMetadata('type', $annotation->type); |
||
| 64 | if (!empty($annotation->type)) { |
||
| 65 | $propertyMetadata->addMetadata('of', $annotation->of); |
||
| 66 | } |
||
| 67 | } |
||
| 68 | |||
| 69 | $classMetadata->addPropertyMetadata($propertyMetadata); |
||
| 70 | } elseif ($annotation instanceof Id) { |
||
| 71 | $propertyMetadata = new PropertyMetadata( |
||
| 72 | $classMetadata->className(), |
||
| 73 | $propertyReflection->getName() |
||
| 74 | ); |
||
| 75 | |||
| 76 | $propertyMetadata->addMetadata('identifier', true); |
||
| 77 | $propertyMetadata->addMetadata('name', '_id'); |
||
| 78 | |||
| 79 | if (!empty($annotation->type)) { |
||
| 80 | $propertyMetadata->addMetadata('type', $annotation->type); |
||
| 81 | } |
||
| 82 | |||
| 83 | $classMetadata->addPropertyMetadata($propertyMetadata); |
||
| 84 | } |
||
| 85 | } |
||
| 86 | } |
||
| 87 | |||
| 88 | return $classMetadata; |
||
| 89 | } |
||
| 90 | |||
| 91 | return; |
||
| 92 | } catch (\ReflectionException $e) { |
||
| 93 | throw MappingException::classNotFound($className); |
||
| 94 | } |
||
| 95 | } |
||
| 96 | } |
||
| 97 |