| Conditions | 20 |
| Paths | 36 |
| Total Lines | 49 |
| Code Lines | 36 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 |
||
| 33 | public function guessFieldType(FieldContext $fieldContext) |
||
| 34 | { |
||
| 35 | if (!$this->isFieldContainerSupported($fieldContext)) { |
||
| 36 | return; |
||
| 37 | } |
||
| 38 | |||
| 39 | /** @var Type $fieldContainer */ |
||
| 40 | $fieldContainer = $fieldContext->getContainer(); |
||
| 41 | $model = $fieldContainer->getModel(); |
||
| 42 | |||
| 43 | if (null === $metadata = $this->getMetadata($model)) { |
||
| 44 | return; |
||
| 45 | } |
||
| 46 | |||
| 47 | $field = $fieldContext->getField(); |
||
| 48 | |||
| 49 | $property = $field->getProperty() ?: $field->getName(); |
||
| 50 | |||
| 51 | if ($metadata->hasAssociation($property)) { |
||
| 52 | return $this->guessAssociation($metadata, $field, $fieldContext->getSchema()); |
||
| 53 | } |
||
| 54 | |||
| 55 | switch ($metadata->getTypeOfField($property)) { |
||
| 56 | case DoctrineType::TARRAY: |
||
| 57 | case DoctrineType::JSON_ARRAY: |
||
| 58 | return $this->wrapRequired($metadata, $property, '[String]', Guess::LOW_CONFIDENCE); |
||
| 59 | case DoctrineType::BOOLEAN: |
||
| 60 | return new TypeGuess('Boolean', Guess::HIGH_CONFIDENCE); |
||
| 61 | case DoctrineType::DATETIME: |
||
| 62 | case DoctrineType::DATETIMETZ: |
||
| 63 | case 'vardatetime': |
||
| 64 | case DoctrineType::DATE: |
||
| 65 | case DoctrineType::TIME: |
||
| 66 | return $this->wrapRequired($metadata, $property, 'String', Guess::MEDIUM_CONFIDENCE); |
||
| 67 | case DoctrineType::DECIMAL: |
||
| 68 | case DoctrineType::FLOAT: |
||
| 69 | return $this->wrapRequired($metadata, $property, 'Number', Guess::MEDIUM_CONFIDENCE); |
||
| 70 | case DoctrineType::INTEGER: |
||
| 71 | case DoctrineType::BIGINT: |
||
| 72 | case DoctrineType::SMALLINT: |
||
| 73 | return $this->wrapRequired($metadata, $property, 'Int', Guess::MEDIUM_CONFIDENCE); |
||
| 74 | case DoctrineType::STRING: |
||
| 75 | return $this->wrapRequired($metadata, $property, 'String', Guess::MEDIUM_CONFIDENCE); |
||
| 76 | case DoctrineType::TEXT: |
||
| 77 | return $this->wrapRequired($metadata, $property, 'String', Guess::MEDIUM_CONFIDENCE); |
||
| 78 | default: |
||
| 79 | return $this->wrapRequired($metadata, $property, 'String', Guess::LOW_CONFIDENCE); |
||
| 80 | } |
||
| 81 | } |
||
| 82 | |||
| 193 |