RestEntityType   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 46
Duplicated Lines 26.09 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 0 Features 1
Metric Value
wmc 5
c 3
b 0
f 1
lcom 1
cbo 4
dl 12
loc 46
ccs 16
cts 16
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A buildForm() 0 5 1
A configureOptions() 12 12 2
A getName() 0 4 1

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 Pgs\RestfonyBundle\Form\Type;
4
5
use Symfony\Component\Form\AbstractType;
6
use Symfony\Component\Form\FormBuilderInterface;
7
use Symfony\Component\OptionsResolver\OptionsResolver;
8
use Symfony\Component\OptionsResolver\Options;
9
use Doctrine\Common\Persistence\ObjectManager;
10
use Pgs\RestfonyBundle\Form\DataTransformer\RestEntityTransformer;
11
12
class RestEntityType extends AbstractType
13
{
14
    /** @var ObjectManager */
15
    private $objectManager;
16
17
    /**
18
     * @param ObjectManager $objectManager
19
     */
20 2
    public function __construct(ObjectManager $objectManager)
21
    {
22 2
        $this->objectManager = $objectManager;
23 2
    }
24
25
    /**
26
     * @inheritdoc
27
     */
28 1
    public function buildForm(FormBuilderInterface $builder, array $options)
29
    {
30 1
        $transformer = new RestEntityTransformer($this->objectManager, $options['entityName']);
31 1
        $builder->addModelTransformer($transformer);
32 1
    }
33
34
    /**
35
     * @inheritdoc
36
     */
37 1 View Code Duplication
    public function configureOptions(OptionsResolver $resolver)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
38
    {
39 1
        $resolver->setRequired(['entityName']);
40
41 1
        if ($resolver instanceof OptionsResolver) {
42 1
            $resolver->setAllowedTypes('entityName', ['string']);
43 1
            $resolver->setDefined(['entityName']);
44 1
            $resolver->setDefault('invalid_message', function (Options $options) {
45 1
                return 'This value is not valid. Unable to find ' . $options['entityName'] . ' in the database.';
46 1
            });
47
        }
48 1
    }
49
50
    /**
51
     * @inheritdoc
52
     */
53
    public function getName()
54
    {
55
        return 'entity';
56
    }
57
}
58