Completed
Push — 3.x ( 3e834f...38b337 )
by Grégoire
03:36
created

src/Form/Extension/ChoiceTypeExtension.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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\AdminBundle\Form\Extension;
15
16
use Symfony\Component\Form\AbstractTypeExtension;
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
/**
24
 * @final since sonata-project/admin-bundle 3.52
25
 *
26
 * @author Amine Zaghdoudi <[email protected]>
27
 */
28
class ChoiceTypeExtension extends AbstractTypeExtension
29
{
30
    /**
31
     * NEXT_MAJOR: Remove method, when bumping requirements to SF 2.7+.
32
     *
33
     * {@inheritdoc}
34
     */
35
    public function setDefaultOptions(OptionsResolverInterface $resolver)
36
    {
37
        $this->configureOptions($resolver);
0 ignored issues
show
$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...
38
    }
39
40
    public function configureOptions(OptionsResolver $resolver)
41
    {
42
        $optionalOptions = ['sortable'];
43
44
        $resolver->setDefined($optionalOptions);
45
    }
46
47
    public function buildView(FormView $view, FormInterface $form, array $options)
48
    {
49
        $view->vars['sortable'] = \array_key_exists('sortable', $options) && $options['sortable'];
50
    }
51
52
    public function getExtendedType()
53
    {
54
        return ChoiceType::class;
55
    }
56
57
    public static function getExtendedTypes()
58
    {
59
        return [ChoiceType::class];
60
    }
61
}
62