| Conditions | 10 |
| Paths | 10 |
| Total Lines | 65 |
| Code Lines | 47 |
| 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 |
||
| 43 | public function guessType($class, $property) |
||
| 44 | { |
||
| 45 | if (!$ret = $this->getMetadata($class)) { |
||
| 46 | return new TypeGuess('text', array(), Guess::LOW_CONFIDENCE); |
||
| 47 | } |
||
| 48 | |||
| 49 | list($metadata, $name) = $ret; |
||
|
|
|||
| 50 | |||
| 51 | if ($metadata->hasAssociation($property)) { |
||
| 52 | $multiple = $metadata->isCollectionValuedAssociation($property); |
||
| 53 | $mapping = $metadata->getFieldMapping($property); |
||
| 54 | |||
| 55 | return new TypeGuess( |
||
| 56 | 'document', |
||
| 57 | array( |
||
| 58 | 'class' => $mapping['targetDocument'], |
||
| 59 | 'multiple' => $multiple, |
||
| 60 | 'expanded' => $multiple |
||
| 61 | ), |
||
| 62 | Guess::HIGH_CONFIDENCE |
||
| 63 | ); |
||
| 64 | } |
||
| 65 | |||
| 66 | $fieldMapping = $metadata->getFieldMapping($property); |
||
| 67 | switch ($fieldMapping['type']) |
||
| 68 | { |
||
| 69 | case 'collection': |
||
| 70 | return new TypeGuess( |
||
| 71 | 'Collection', |
||
| 72 | array(), |
||
| 73 | Guess::MEDIUM_CONFIDENCE |
||
| 74 | ); |
||
| 75 | case 'boolean': |
||
| 76 | return new TypeGuess( |
||
| 77 | 'checkbox', |
||
| 78 | array(), |
||
| 79 | Guess::HIGH_CONFIDENCE |
||
| 80 | ); |
||
| 81 | case 'date': |
||
| 82 | case 'timestamp': |
||
| 83 | return new TypeGuess( |
||
| 84 | 'datetime', |
||
| 85 | array(), |
||
| 86 | Guess::HIGH_CONFIDENCE |
||
| 87 | ); |
||
| 88 | case 'float': |
||
| 89 | return new TypeGuess( |
||
| 90 | 'number', |
||
| 91 | array(), |
||
| 92 | Guess::MEDIUM_CONFIDENCE |
||
| 93 | ); |
||
| 94 | case 'int': |
||
| 95 | return new TypeGuess( |
||
| 96 | 'integer', |
||
| 97 | array(), |
||
| 98 | Guess::MEDIUM_CONFIDENCE |
||
| 99 | ); |
||
| 100 | case 'string': |
||
| 101 | return new TypeGuess( |
||
| 102 | 'text', |
||
| 103 | array(), |
||
| 104 | Guess::MEDIUM_CONFIDENCE |
||
| 105 | ); |
||
| 106 | } |
||
| 107 | } |
||
| 108 | |||
| 187 |
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
$aand$care used. There was no need to assign$b.Instead, the list call could have been.