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