Conditions | 10 |
Paths | 11 |
Total Lines | 57 |
Code Lines | 35 |
Lines | 16 |
Ratio | 28.07 % |
Changes | 3 | ||
Bugs | 1 | 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 |
||
41 | protected function addMetadataForEnum(\SimpleXMLElement $xmlRoot, ClassMetadataInterface $classMetadata) |
||
42 | { |
||
43 | foreach ($xmlRoot->xpath('//cubiche:enum') as $item) { |
||
44 | // get the field tag |
||
45 | $field = $item->xpath('..')[0]; |
||
46 | $fieldMapping = $this->getMappingAttributes($field); |
||
47 | $fieldName = $fieldMapping['name']; |
||
48 | |||
49 | $itemMapping = $this->getMappingAttributes($item); |
||
50 | foreach ($item->attributes() as $key => $value) { |
||
51 | $itemMapping[$key] = (string) $value; |
||
52 | } |
||
53 | |||
54 | if (!isset($itemMapping['type'])) { |
||
55 | throw MappingException::inField( |
||
56 | 'The cubiche:enum definition should have a "type" value', |
||
57 | $classMetadata->className(), |
||
58 | $fieldName |
||
59 | ); |
||
60 | } |
||
61 | |||
62 | $enumType = $itemMapping['type']; |
||
63 | |||
64 | if ($field->getName() == 'field') { |
||
65 | View Code Duplication | if (isset($fieldMapping['id']) && $fieldMapping['id'] !== false) { |
|
|
|||
66 | throw MappingException::inField( |
||
67 | 'The cubiche:enum configuration is only for field tags that is not an id', |
||
68 | $classMetadata->className(), |
||
69 | $fieldName |
||
70 | ); |
||
71 | } |
||
72 | |||
73 | View Code Duplication | if (!isset($fieldMapping['type']) || |
|
74 | (isset($fieldMapping['type']) && $fieldMapping['type'] !== 'CubicheType') |
||
75 | ) { |
||
76 | throw MappingException::inField( |
||
77 | 'The cubiche:enum parent should have a "type" value equal to CubicheType', |
||
78 | $classMetadata->className(), |
||
79 | $fieldName |
||
80 | ); |
||
81 | } |
||
82 | |||
83 | $propertyMetadata = new PropertyMetadata($classMetadata->className(), $fieldName); |
||
84 | |||
85 | $propertyMetadata->addMetadata('namespace', 'enum'); |
||
86 | $propertyMetadata->addMetadata('type', $enumType); |
||
87 | |||
88 | $classMetadata->addPropertyMetadata($propertyMetadata); |
||
89 | } else { |
||
90 | throw MappingException::inField( |
||
91 | 'The cubiche:enum configuration is only for id fields', |
||
92 | $classMetadata->className(), |
||
93 | $fieldName |
||
94 | ); |
||
95 | } |
||
96 | } |
||
97 | } |
||
98 | |||
143 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.