ChoiceFieldMaskType   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 8
lcom 0
cbo 3
dl 0
loc 62
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A setDefaultOptions() 0 4 1
A configureOptions() 0 6 1
A getParent() 0 4 1
A buildView() 0 14 3
A getName() 0 4 1
A getBlockPrefix() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Sonata Project package.
7
 *
8
 * (c) Thomas Rabaix <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Sonata\DoctrinePHPCRAdminBundle\Form\Type;
15
16
use Symfony\Component\Form\AbstractType;
17
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
18
use Symfony\Component\Form\FormInterface;
19
use Symfony\Component\Form\FormView;
20
use Symfony\Component\OptionsResolver\OptionsResolver;
21
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
22
23
class ChoiceFieldMaskType extends AbstractType
24
{
25
    /**
26
     * {@inheritdoc}
27
     */
28
    public function buildView(FormView $view, FormInterface $form, array $options): void
29
    {
30
        $allFieldNames = [];
31
        foreach ($options['map'] as $value => $fieldNames) {
32
            foreach ($fieldNames as $fieldName) {
33
                $allFieldNames[$fieldName] = $fieldName;
34
            }
35
        }
36
        $allFieldNames = array_values($allFieldNames);
37
38
        $view->vars['all_fields'] = $allFieldNames;
39
        $view->vars['map'] = $options['map'];
40
        parent::buildView($view, $form, $options);
41
    }
42
43
    /**
44
     * NEXT_MAJOR: remove this method.
45
     */
46
    public function setDefaultOptions(OptionsResolverInterface $resolver): void
47
    {
48
        $this->configureOptions($resolver);
0 ignored issues
show
Documentation introduced by
$resolver is of type object<Symfony\Component...tionsResolverInterface>, but the function expects a object<Symfony\Component...solver\OptionsResolver>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
49
    }
50
51
    /**
52
     * {@inheritdoc}
53
     */
54
    public function configureOptions(OptionsResolver $resolver): void
55
    {
56
        $resolver->setDefaults([
57
            'map' => [],
58
        ]);
59
    }
60
61
    /**
62
     * {@inheritdoc}
63
     */
64
    public function getParent()
65
    {
66
        return ChoiceType::class;
67
    }
68
69
    /**
70
     * NEXT_MAJOR: remove this method.
71
     */
72
    public function getName()
73
    {
74
        return $this->getBlockPrefix();
75
    }
76
77
    /**
78
     * {@inheritdoc}
79
     */
80
    public function getBlockPrefix()
81
    {
82
        return 'choice_field_mask';
83
    }
84
}
85