Conditions | 28 |
Paths | 49 |
Total Lines | 67 |
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 |
||
41 | public function guessType($class, $property, ModelManagerInterface $modelManager) |
||
42 | { |
||
43 | if (!$ret = $this->getParentMetadataForProperty($class, $property, $modelManager)) { |
||
44 | return new TypeGuess('text', [], Guess::LOW_CONFIDENCE); |
||
45 | } |
||
46 | |||
47 | list($metadata, $propertyName, $parentAssociationMappings) = $ret; |
||
|
|||
48 | |||
49 | if ($metadata->hasAssociation($propertyName)) { |
||
50 | $mapping = $metadata->getAssociationMapping($propertyName); |
||
51 | |||
52 | switch ($mapping['type']) { |
||
53 | case ClassMetadata::ONE_TO_MANY: |
||
54 | // NEXT_MAJOR: return new TypeGuess(TemplateRegistry::TYPE_ONE_TO_MANY, [], Guess::HIGH_CONFIDENCE) |
||
55 | return new TypeGuess('orm_one_to_many', [], Guess::HIGH_CONFIDENCE); |
||
56 | |||
57 | case ClassMetadata::MANY_TO_MANY: |
||
58 | // NEXT_MAJOR: return new TypeGuess(TemplateRegistry::TYPE_MANY_TO_MANY, [], Guess::HIGH_CONFIDENCE) |
||
59 | return new TypeGuess('orm_many_to_many', [], Guess::HIGH_CONFIDENCE); |
||
60 | |||
61 | case ClassMetadata::MANY_TO_ONE: |
||
62 | // NEXT_MAJOR: return new TypeGuess(TemplateRegistry::TYPE_MANY_TO_ONE, [], Guess::HIGH_CONFIDENCE) |
||
63 | return new TypeGuess('orm_many_to_one', [], Guess::HIGH_CONFIDENCE); |
||
64 | |||
65 | case ClassMetadata::ONE_TO_ONE: |
||
66 | // NEXT_MAJOR: return new TypeGuess(TemplateRegistry::TYPE_ONE_TO_ONE, [], Guess::HIGH_CONFIDENCE) |
||
67 | return new TypeGuess('orm_one_to_one', [], Guess::HIGH_CONFIDENCE); |
||
68 | } |
||
69 | } |
||
70 | |||
71 | switch ($metadata->getTypeOfField($propertyName)) { |
||
72 | case 'array': |
||
73 | case 'simple_array': |
||
74 | case 'json': |
||
75 | case 'json_array': |
||
76 | return new TypeGuess(TemplateRegistry::TYPE_ARRAY, [], Guess::HIGH_CONFIDENCE); |
||
77 | case 'boolean': |
||
78 | return new TypeGuess(TemplateRegistry::TYPE_BOOLEAN, [], Guess::HIGH_CONFIDENCE); |
||
79 | case 'datetime': |
||
80 | case 'datetime_immutable': |
||
81 | case 'vardatetime': |
||
82 | case 'datetimetz': |
||
83 | case 'datetimetz_immutable': |
||
84 | return new TypeGuess(TemplateRegistry::TYPE_DATETIME, [], Guess::HIGH_CONFIDENCE); |
||
85 | case 'date': |
||
86 | case 'date_immutable': |
||
87 | return new TypeGuess(TemplateRegistry::TYPE_DATE, [], Guess::HIGH_CONFIDENCE); |
||
88 | case 'decimal': |
||
89 | case 'float': |
||
90 | // NEXT_MAJOR: return new TypeGuess(TemplateRegistry::TYPE_FLOAT, [], Guess::LOW_CONFIDENCE) |
||
91 | return new TypeGuess('number', [], Guess::MEDIUM_CONFIDENCE); |
||
92 | case 'integer': |
||
93 | case 'bigint': |
||
94 | case 'smallint': |
||
95 | return new TypeGuess(TemplateRegistry::TYPE_INTEGER, [], Guess::MEDIUM_CONFIDENCE); |
||
96 | case 'string': |
||
97 | return new TypeGuess(TemplateRegistry::TYPE_TEXT, [], Guess::MEDIUM_CONFIDENCE); |
||
98 | case 'text': |
||
99 | return new TypeGuess(TemplateRegistry::TYPE_TEXTAREA, [], Guess::MEDIUM_CONFIDENCE); |
||
100 | case 'time': |
||
101 | case 'time_immutable': |
||
102 | return new TypeGuess(TemplateRegistry::TYPE_TIME, [], Guess::HIGH_CONFIDENCE); |
||
103 | default: |
||
104 | // NEXT_MAJOR: return new TypeGuess(TemplateRegistry::TYPE_STRING, [], Guess::LOW_CONFIDENCE) |
||
105 | return new TypeGuess(TemplateRegistry::TYPE_TEXT, [], Guess::LOW_CONFIDENCE); |
||
106 | } |
||
107 | } |
||
108 | } |
||
109 |
This checks looks for assignemnts to variables using the
list(...)
function, where not all assigned variables are subsequently used.Consider the following code example.
Only the variables
$a
and$c
are used. There was no need to assign$b
.Instead, the list call could have been.