RestCollectionType   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 48
Duplicated Lines 25 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 90%

Importance

Changes 3
Bugs 0 Features 1
Metric Value
wmc 5
c 3
b 0
f 1
lcom 1
cbo 5
dl 12
loc 48
ccs 18
cts 20
cp 0.9
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A buildForm() 0 7 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\RestCollectionTransformer;
11
use Pgs\RestfonyBundle\Form\DataTransformer\ArrayToStringTransformer;
12
13
class RestCollectionType extends AbstractType
14
{
15
    /** @var ObjectManager */
16
    private $objectManager;
17
18
    /**
19
     * @param ObjectManager $objectManager
20
     */
21 2
    public function __construct(ObjectManager $objectManager)
22
    {
23 2
        $this->objectManager = $objectManager;
24 2
    }
25
26
    /**
27
     * @inheritdoc
28
     */
29 1
    public function buildForm(FormBuilderInterface $builder, array $options)
30
    {
31 1
        $transformer = new RestCollectionTransformer($this->objectManager, $options['entityName']);
32 1
        $viewTransformer = new ArrayToStringTransformer();
33 1
        $builder->addModelTransformer($transformer);
34 1
        $builder->addViewTransformer($viewTransformer);
35 1
    }
36
37
    /**
38
     * @inheritdoc
39
     */
40 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...
41
    {
42 1
        $resolver->setRequired(['entityName']);
43
44 1
        if ($resolver instanceof OptionsResolver) {
45 1
            $resolver->setAllowedTypes('entityName', ['string']);
46 1
            $resolver->setDefined(['entityName']);
47 1
            $resolver->setDefault('invalid_message', function (Options $options) {
48 1
                return 'This value is not valid. Unable to find ' . $options['entityName'] . ' in the database.';
49 1
            });
50
        }
51 1
    }
52
53
    /**
54
     * @inheritdoc
55
     */
56
    public function getName()
57
    {
58
        return 'collection';
59
    }
60
}
61