These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | /* |
||
4 | * This file is part of the Sylius package. |
||
5 | * |
||
6 | * (c) Paweł Jędrzejewski |
||
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 | declare(strict_types=1); |
||
13 | |||
14 | namespace Sylius\Bundle\ChannelBundle\Form\Type; |
||
15 | |||
16 | use Sylius\Component\Resource\Repository\RepositoryInterface; |
||
17 | use Symfony\Bridge\Doctrine\Form\DataTransformer\CollectionToArrayTransformer; |
||
18 | use Symfony\Component\Form\AbstractType; |
||
19 | use Symfony\Component\Form\Extension\Core\Type\ChoiceType; |
||
20 | use Symfony\Component\Form\FormBuilderInterface; |
||
21 | use Symfony\Component\OptionsResolver\Options; |
||
22 | use Symfony\Component\OptionsResolver\OptionsResolver; |
||
23 | |||
24 | final class ChannelChoiceType extends AbstractType |
||
25 | { |
||
26 | /** |
||
27 | * @var RepositoryInterface |
||
28 | */ |
||
29 | private $channelRepository; |
||
30 | |||
31 | /** |
||
32 | * @param RepositoryInterface $channelRepository |
||
33 | */ |
||
34 | public function __construct(RepositoryInterface $channelRepository) |
||
35 | { |
||
36 | $this->channelRepository = $channelRepository; |
||
37 | } |
||
38 | |||
39 | /** |
||
40 | * {@inheritdoc} |
||
41 | */ |
||
42 | public function buildForm(FormBuilderInterface $builder, array $options): void |
||
43 | { |
||
44 | if ($options['multiple']) { |
||
45 | $builder->addModelTransformer(new CollectionToArrayTransformer()); |
||
46 | } |
||
47 | } |
||
48 | |||
49 | /** |
||
50 | * {@inheritdoc} |
||
51 | */ |
||
52 | public function configureOptions(OptionsResolver $resolver): void |
||
53 | { |
||
54 | $resolver->setDefaults([ |
||
55 | 'choices' => function (Options $options): array { |
||
0 ignored issues
–
show
|
|||
56 | return $this->channelRepository->findAll(); |
||
57 | }, |
||
58 | 'choice_value' => 'code', |
||
59 | 'choice_label' => 'name', |
||
60 | 'choice_translation_domain' => false, |
||
61 | ]); |
||
62 | } |
||
63 | |||
64 | /** |
||
65 | * {@inheritdoc} |
||
66 | */ |
||
67 | public function getParent(): string |
||
68 | { |
||
69 | return ChoiceType::class; |
||
70 | } |
||
71 | |||
72 | /** |
||
73 | * {@inheritdoc} |
||
74 | */ |
||
75 | public function getBlockPrefix(): string |
||
76 | { |
||
77 | return 'sylius_channel_choice'; |
||
78 | } |
||
79 | } |
||
80 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.