DoctrineOrmTypeGuesser::guessType()   B
last analyzed

Complexity

Conditions 5
Paths 5

Size

Total Lines 20
Code Lines 13

Duplication

Lines 12
Ratio 60 %

Importance

Changes 0
Metric Value
dl 12
loc 20
rs 8.8571
c 0
b 0
f 0
cc 5
eloc 13
nc 5
nop 2
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