Completed
Push — master ( 265a2d...f9e310 )
by jerome
02:58
created

MinecraftServerType::buildForm()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 30
Code Lines 23

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 30
rs 8.8571
cc 1
eloc 23
nc 1
nop 2
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\GameServer\MinecraftServerBundle\Form;
13
14
use DP\Core\GameBundle\Entity\GameRepository;
15
use Symfony\Component\Form\FormBuilderInterface;
16
use Symfony\Component\Form\AbstractType;
17
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
18
19
class MinecraftServerType extends AbstractType
20
{
21
    /**
22
     * {@inheritdoc}
23
     */
24
    public function buildForm(FormBuilderInterface $builder, array $options)
25
    {
26
        $minecraft = $builder->getData();
27
28
        $builder
29
            ->add('name', 'text', ['label' => 'game.name'])
30
            ->add('machine', 'dedipanel_machine_entity')
31
            ->add('port', 'integer', ['label' => 'game.port'])
32
            ->add('game', 'entity', [
33
                'label' => 'game.selectGame',
34
                'class' => 'DPGameBundle:Game',
35
                'query_builder' => function(GameRepository $repo) {
36
                    return $repo->getQBAvailableMinecraftGames();
37
                },
38
            ])
39
            ->add('dir', 'text', ['label' => 'game.dir'])
40
            ->add('queryPort', 'integer', ['label' => 'minecraft.queryPort'])
41
            ->add('rconPort', 'integer', ['label' => 'minecraft.rcon.port'])
42
            ->add('rconPassword', 'text', ['label' => 'game.rcon.password'])
43
            ->add('maxplayers', 'integer', ['label' => 'game.maxplayers'])
44
            ->add('minHeap', 'integer', ['label' => 'minecraft.minHeap'])
45
            ->add('maxHeap', 'integer', ['label' => 'minecraft.maxHeap'])
46
            ->add('core', 'dedipanel_core_assignment', ['machine' => $minecraft->getMachine()])
47
            ->add('alreadyInstalled', 'dictionary', [
48
                'name'     => 'yes_no',
49
                'label'    => 'game.isAlreadyInstalled',
50
                'expanded' => true,
51
            ])
52
        ;
53
    }
54
55
    /**
56
     * {@inheritdoc}
57
     */
58 View Code Duplication
    public function setDefaultOptions(OptionsResolverInterface $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...
59
    {
60
        $resolver
61
            ->setDefaults([
62
                'remove_on_create'  => ['core'],
63
                'remove_on_update'  => ['alreadyInstalled'],
64
                'disable_on_update' => ['machine', 'game', 'dir'],
65
            ])
66
        ;
67
    }
68
69
    /**
70
     * {@inheritdoc}
71
     */
72
    public function getName()
73
    {
74
        return 'dedipanel_minecraft';
75
    }
76
}
77