| Conditions | 18 |
| Paths | 27 |
| Total Lines | 48 |
| Code Lines | 33 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 1 | Features | 1 |
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 |
||
| 53 | public function guessType($class, $property, ModelManagerInterface $modelManager) |
||
| 54 | { |
||
| 55 | if (!$metadata = $this->getMetadata($class)) { |
||
| 56 | return new TypeGuess('text', array(), Guess::LOW_CONFIDENCE); |
||
| 57 | } |
||
| 58 | |||
| 59 | if ($metadata->hasAssociation($property)) { |
||
| 60 | $mapping = $metadata->mappings[$property]; |
||
| 61 | |||
| 62 | switch ($mapping['type']) { |
||
| 63 | case ClassMetadata::MANY_TO_MANY: |
||
| 64 | case 'referrers': |
||
| 65 | return new TypeGuess('doctrine_phpcr_many_to_many', array(), Guess::HIGH_CONFIDENCE); |
||
| 66 | |||
| 67 | case ClassMetadata::MANY_TO_ONE: |
||
| 68 | case 'parent': |
||
| 69 | return new TypeGuess('doctrine_phpcr_many_to_one', array(), Guess::HIGH_CONFIDENCE); |
||
| 70 | |||
| 71 | case 'children': |
||
| 72 | return new TypeGuess('doctrine_phpcr_one_to_many', array(), Guess::HIGH_CONFIDENCE); |
||
| 73 | |||
| 74 | case 'child': |
||
| 75 | return new TypeGuess('doctrine_phpcr_one_to_one', array(), Guess::HIGH_CONFIDENCE); |
||
| 76 | } |
||
| 77 | } |
||
| 78 | |||
| 79 | // TODO: missing multivalue support |
||
| 80 | switch ($metadata->getTypeOfField($property)) { |
||
| 81 | case 'boolean': |
||
| 82 | return new TypeGuess('boolean', array(), Guess::HIGH_CONFIDENCE); |
||
| 83 | case 'date': |
||
| 84 | return new TypeGuess('date', array(), Guess::HIGH_CONFIDENCE); |
||
| 85 | |||
| 86 | case 'decimal': |
||
| 87 | case 'double': |
||
| 88 | return new TypeGuess('number', array(), Guess::MEDIUM_CONFIDENCE); |
||
| 89 | case 'integer': |
||
| 90 | case 'long': |
||
| 91 | return new TypeGuess('integer', array(), Guess::MEDIUM_CONFIDENCE); |
||
| 92 | case 'string': |
||
| 93 | return new TypeGuess('string', array(), Guess::HIGH_CONFIDENCE); |
||
| 94 | case 'binary': |
||
| 95 | case 'uri': |
||
| 96 | return new TypeGuess('string', array(), Guess::MEDIUM_CONFIDENCE); |
||
| 97 | } |
||
| 98 | |||
| 99 | return new TypeGuess('text', array(), Guess::LOW_CONFIDENCE); |
||
| 100 | } |
||
| 101 | |||
| 125 |