Conditions | 22 |
Paths | 39 |
Total Lines | 51 |
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 |
||
26 | public function guessType($class, $property, ModelManagerInterface $modelManager) |
||
27 | { |
||
28 | if (!$ret = $this->getParentMetadataForProperty($class, $property, $modelManager)) { |
||
|
|||
29 | return new TypeGuess('text', [], Guess::LOW_CONFIDENCE); |
||
30 | } |
||
31 | |||
32 | list($metadata, $propertyName, $parentAssociationMappings) = $ret; |
||
33 | |||
34 | if ($metadata->hasAssociation($propertyName)) { |
||
35 | $mapping = $metadata->fieldMappings[$propertyName]; |
||
36 | |||
37 | switch ($mapping['type']) { |
||
38 | case ClassMetadataInfo::ONE: |
||
39 | return new TypeGuess('mongo_one', [], Guess::HIGH_CONFIDENCE); |
||
40 | |||
41 | case ClassMetadataInfo::MANY: |
||
42 | return new TypeGuess('mongo_many', [], Guess::HIGH_CONFIDENCE); |
||
43 | } |
||
44 | } |
||
45 | |||
46 | switch ($metadata->getTypeOfField($propertyName)) { |
||
47 | case 'collection': |
||
48 | case 'hash': |
||
49 | case 'array': |
||
50 | return new TypeGuess('array', [], Guess::HIGH_CONFIDENCE); |
||
51 | case 'boolean': |
||
52 | return new TypeGuess('boolean', [], Guess::HIGH_CONFIDENCE); |
||
53 | case 'datetime': |
||
54 | case 'vardatetime': |
||
55 | case 'datetimetz': |
||
56 | case 'timestamp': |
||
57 | return new TypeGuess('datetime', [], Guess::HIGH_CONFIDENCE); |
||
58 | case 'date': |
||
59 | return new TypeGuess('date', [], Guess::HIGH_CONFIDENCE); |
||
60 | case 'decimal': |
||
61 | case 'float': |
||
62 | return new TypeGuess('number', [], Guess::MEDIUM_CONFIDENCE); |
||
63 | case 'integer': |
||
64 | case 'bigint': |
||
65 | case 'smallint': |
||
66 | return new TypeGuess('integer', [], Guess::MEDIUM_CONFIDENCE); |
||
67 | case 'string': |
||
68 | return new TypeGuess('text', [], Guess::MEDIUM_CONFIDENCE); |
||
69 | case 'text': |
||
70 | return new TypeGuess('textarea', [], Guess::MEDIUM_CONFIDENCE); |
||
71 | case 'time': |
||
72 | return new TypeGuess('time', [], Guess::HIGH_CONFIDENCE); |
||
73 | default: |
||
74 | return new TypeGuess('text', [], Guess::LOW_CONFIDENCE); |
||
75 | } |
||
76 | } |
||
77 | } |
||
78 |
This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.
Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.