| Conditions | 10 |
| Paths | 11 |
| Total Lines | 54 |
| Code Lines | 34 |
| 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 |
||
| 29 | protected function addMetadataFor(\SimpleXMLElement $xmlRoot, MergeableClassMetadata $classMetadata) |
||
| 30 | { |
||
| 31 | foreach ($xmlRoot->xpath('//cubiche:valueobject') as $item) { |
||
| 32 | // get the field tag |
||
| 33 | $field = $item->xpath('..')[0]; |
||
| 34 | $fieldMapping = $this->getMappingAttributes($field); |
||
| 35 | $fieldName = $fieldMapping['name']; |
||
| 36 | |||
| 37 | $itemMapping = $this->getMappingAttributes($item); |
||
| 38 | foreach ($item->attributes() as $key => $value) { |
||
| 39 | $itemMapping[$key] = (string) $value; |
||
| 40 | } |
||
| 41 | |||
| 42 | if (!isset($itemMapping['type'])) { |
||
| 43 | throw MappingException::inField( |
||
| 44 | 'The cubiche:valueobject definition should have a "type" value', |
||
| 45 | $classMetadata->name, |
||
| 46 | $fieldName |
||
| 47 | ); |
||
| 48 | } |
||
| 49 | |||
| 50 | $valueObjectType = $itemMapping['type']; |
||
| 51 | if ($field->getName() == 'field') { |
||
| 52 | if (isset($fieldMapping['id']) && $fieldMapping['id'] !== false) { |
||
| 53 | throw MappingException::inField( |
||
| 54 | 'The cubiche:valueobject configuration is only for field tags that is not an id', |
||
| 55 | $classMetadata->name, |
||
| 56 | $fieldName |
||
| 57 | ); |
||
| 58 | } |
||
| 59 | |||
| 60 | if (!isset($fieldMapping['type']) || |
||
| 61 | (isset($fieldMapping['type']) && $fieldMapping['type'] !== 'CubicheType') |
||
| 62 | ) { |
||
| 63 | throw MappingException::inField( |
||
| 64 | 'The cubiche:valueobject parent should have a "type" value equal to CubicheType', |
||
| 65 | $classMetadata->name, |
||
| 66 | $fieldName |
||
| 67 | ); |
||
| 68 | } |
||
| 69 | |||
| 70 | $propertyMetadata = new PropertyMetadata($classMetadata->name, $fieldName, 'valueobject'); |
||
| 71 | $propertyMetadata->setType($valueObjectType); |
||
| 72 | |||
| 73 | $classMetadata->addPropertyMetadata($propertyMetadata); |
||
| 74 | } else { |
||
| 75 | throw MappingException::inField( |
||
| 76 | 'The cubiche:valueobject configuration is only for field tags that is not an id', |
||
| 77 | $classMetadata->name, |
||
| 78 | $fieldName |
||
| 79 | ); |
||
| 80 | } |
||
| 81 | } |
||
| 82 | } |
||
| 83 | } |
||
| 84 |