Completed
Push — master ( fdbeef...265a2d )
by jerome
25:01 queued 21:35
created

TeamspeakServerType::buildForm()   A

Complexity

Conditions 3
Paths 1

Size

Total Lines 57
Code Lines 36

Duplication

Lines 17
Ratio 29.82 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
c 3
b 0
f 0
dl 17
loc 57
rs 9.6818
cc 3
eloc 36
nc 1
nop 2

How to fix   Long Method   

Long Method

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:

1
<?php
2
3
/**
4
 * This file is part of Dedipanel project
5
 *
6
 * (c) 2010-2015 Dedipanel <http://www.dedicated-panel.net>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace DP\VoipServer\TeamspeakServerBundle\Form;
13
14
use Symfony\Component\Form\AbstractType;
15
use Symfony\Component\Form\FormBuilderInterface;
16
use Symfony\Component\Form\FormEvent;
17
use Symfony\Component\Form\FormEvents;
18
19
class TeamspeakServerType extends AbstractType
20
{
21
    public function buildForm(FormBuilderInterface $builder, array $options)
22
    {
23
        $builder
24
            ->add('voice_port', 'number', array('label' => 'voip.voice_port'))
25
            ->add('query_port', 'number', array('label' => 'voip.query_port'))
26
            ->add('filetransfer_port', 'number', array('label' => 'teamspeak.filetransfer_port'))
27
            ->add('licence_file', 'file', array(
28
                'label'    => 'teamspeak.licence',
29
                'required' => false,
30
            ))
31
            ->add('alreadyInstalled', 'choice', array(
32
                'choices'   => array(1 => 'game.yes', 0 => 'game.no'),
33
                'label'     => 'game.isAlreadyInstalled',
34
                'expanded'  => true
35
            ))
36
            ->add('query_password', 'password', array(
37
                'label' => 'voip.query_password',
38
                'required' => true,
39
            ))
40
        ;
41
42
        $builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) {
43
            $form      = $event->getForm();
44
            /** @var DP\VoipServer\TeamspeakServerBundle\Entity\TeamspeakServer $teamspeak */
45
            $teamspeak = $event->getData();
46
47
            $isUpdateForm = ($teamspeak->getId() != null);
48
49
            $form
50
                ->add('machine', 'dedipanel_machine_entity', array(
51
                    'disabled' => $isUpdateForm,
52
                ))
53
                ->add('dir', 'text', array(
54
                    'label' => 'game.dir',
55
                    'disabled' => $isUpdateForm,
56
                ))
57
            ;
58
59 View Code Duplication
            if ($teamspeak->getId() !== null) {
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...
60
                $form->remove('alreadyInstalled');
61
62
                if ($teamspeak->getMachine()->getNbCore() != null) {
63
                    $choices = array_combine(
64
                        range(0, $teamspeak->getMachine()->getNbCore()-1),
65
                        range(1, $teamspeak->getMachine()->getNbCore())
66
                    );
67
68
                    $form->add('core', 'choice', array(
69
                        'label'    => 'game.core',
70
                        'choices'  => $choices,
71
                        'multiple' => true,
72
                        'required' => false,
73
                    ));
74
                }
75
            }
76
        });
77
    }
78
79
    public function getName()
80
    {
81
        return 'dedipanel_teamspeak';
82
    }
83
}
84