Conditions | 10 |
Paths | 11 |
Total Lines | 56 |
Code Lines | 35 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 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, ClassMetadataInterface $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->className(), |
||
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->className(), |
||
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->className(), |
||
66 | $fieldName |
||
67 | ); |
||
68 | } |
||
69 | |||
70 | $propertyMetadata = new PropertyMetadata($classMetadata->className(), $fieldName); |
||
71 | |||
72 | $propertyMetadata->addMetadata('namespace', 'valueobject'); |
||
73 | $propertyMetadata->addMetadata('type', $valueObjectType); |
||
74 | |||
75 | $classMetadata->addPropertyMetadata($propertyMetadata); |
||
76 | } else { |
||
77 | throw MappingException::inField( |
||
78 | 'The cubiche:valueobject configuration is only for field tags that is not an id', |
||
79 | $classMetadata->className(), |
||
80 | $fieldName |
||
81 | ); |
||
82 | } |
||
83 | } |
||
84 | } |
||
85 | } |
||
86 |