DoctrineOrmTypeGuesser   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 31
Duplicated Lines 38.71 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 2
dl 12
loc 31
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B guessType() 12 20 5

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace EmanueleMinotto\SimpleArrayBundle\Form;
4
5
use Symfony\Bridge\Doctrine\Form\DoctrineOrmTypeGuesser as BaseDoctrineOrmTypeGuesser;
6
use Symfony\Component\Form\Guess\Guess;
7
use Symfony\Component\Form\Guess\TypeGuess;
8
9
class DoctrineOrmTypeGuesser extends BaseDoctrineOrmTypeGuesser
10
{
11
    /**
12
     * Returns a field guess for a property name of a class.
13
     *
14
     * @param string $class    The fully qualified class name.
15
     * @param string $property The name of the property to guess for.
16
     *
17
     * @return TypeGuess|null A guess for the field's type and options.
18
     */
19
    public function guessType($class, $property)
20
    {
21 View Code Duplication
        if (!$ret = $this->getMetadata($class)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
22
            $type = method_exists('Symfony\Component\Form\AbstractType', 'getBlockPrefix')
23
                ? 'Symfony\Component\Form\Extension\Core\Type\TextType'
24
                : 'text';
25
            return new TypeGuess($type, [], Guess::LOW_CONFIDENCE);
26
        }
27
28
        $metadata = $ret[0];
29
30 View Code Duplication
        if ('simple_array' == $metadata->getTypeOfField($property)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
31
            $type = method_exists('Symfony\Component\Form\AbstractType', 'getBlockPrefix')
32
                ? 'EmanueleMinotto\SimpleArrayBundle\Form\Type\SimpleArrayType'
33
                : 'simple_array';
34
            return new TypeGuess($type, [], Guess::MEDIUM_CONFIDENCE);
35
        }
36
37
        return parent::guessType($class, $property);
38
    }
39
}
40