Completed
Branch v1.x-dev (5c2708)
by Benjamin
04:14
created

AddSkills   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
eloc 32
c 1
b 0
f 0
dl 0
loc 49
ccs 0
cts 27
cp 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configureOptions() 0 8 1
A buildForm() 0 33 5
1
<?php
2
3
namespace Obblm\Core\Form\Team;
4
5
use Obblm\Core\Contracts\RuleHelperInterface;
6
use Obblm\Core\Entity\PlayerVersion;
7
use Obblm\Core\Form\Player\AddSkillType;
8
use Symfony\Component\Form\AbstractType;
9
use Symfony\Component\Form\Extension\Core\Type\CollectionType;
10
use Symfony\Component\Form\FormBuilderInterface;
11
use Symfony\Component\Form\FormEvent;
12
use Symfony\Component\Form\FormEvents;
13
use Symfony\Component\OptionsResolver\OptionsResolver;
14
15
class AddSkills extends AbstractType
16
{
17
    public function buildForm(FormBuilderInterface $builder, array $options)
18
    {
19
        /** @var RuleHelperInterface $helper */
20
        $helper = $options['helper'];
21
        $builder->addEventListener(FormEvents::POST_SET_DATA, function (FormEvent $event) use ($helper, $builder) {
0 ignored issues
show
Unused Code introduced by
The import $builder is not used and could be removed.

This check looks for imports that have been defined, but are not used in the scope.

Loading history...
22
            /** @var PlayerVersion $version */
23
            $version = $event->getData();
24
            $form = $event->getForm();
25
            if (!$version->isHiredStarPlayer() && !$version->getPlayer()->isStarPlayer()) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $version->getPlayer()->isStarPlayer() of type boolean|null is loosely compared to false; this is ambiguous if the boolean can be false. You might want to explicitly use !== null instead.

If an expression can have both false, and null as possible values. It is generally a good practice to always use strict comparison to clearly distinguish between those two values.

$a = canBeFalseAndNull();

// Instead of
if ( ! $a) { }

// Better use one of the explicit versions:
if ($a !== null) { }
if ($a !== false) { }
if ($a !== null && $a !== false) { }
Loading history...
26
                $context = ['single'];
27
                if ($version->getTeamVersion()->getTeam()->getCreationOption("skills_allowed.double")) {
28
                    $context[] = 'double';
29
                }
30
                if ($version->getTeamVersion()->getTeam()->getCreationOption("skills_allowed.characteristics")) {
31
                    $context[] = 'av_up';
32
                    $context[] = 'm_up';
33
                    $context[] = 'ag_up';
34
                    $context[] = 'st_up';
35
                }
36
37
                $form->add('additionalSkills', CollectionType::class, [
38
                    'entry_type' => AddSkillType::class,
39
                    'allow_add' => true,
40
                    'allow_delete' => true,
41
                    'prototype' => true,
42
                    'mapped' => true,
43
                    'entry_options' => [
44
                        'helper' => $helper,
45
                        'version' => $version,
46
                        'group_by' => 'typeName',
47
                        'choice_label' => 'name',
48
                        'choice_translation_domain' => $helper->getKey(),
49
                        'context' => $context
50
                    ]
51
                ]);
52
            }
53
        });
54
    }
55
56
    public function configureOptions(OptionsResolver $resolver)
57
    {
58
        $resolver->setDefaults([
59
            'translation_domain' => 'obblm',
60
            'data_class' => PlayerVersion::class,
61
            'helper' => null
62
        ]);
63
        $resolver->setAllowedTypes('helper', [RuleHelperInterface::class]);
64
    }
65
}
66