ScheduleChoiceType::configureOptions()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 6
nc 1
nop 1
dl 0
loc 9
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Setono\SyliusSchedulerPlugin\Form\Type;
6
7
use Setono\SyliusSchedulerPlugin\Doctrine\ORM\ScheduleRepositoryInterface;
8
use Symfony\Bridge\Doctrine\Form\DataTransformer\CollectionToArrayTransformer;
9
use Symfony\Component\Form\AbstractType;
10
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
11
use Symfony\Component\Form\FormBuilderInterface;
12
use Symfony\Component\OptionsResolver\Options;
13
use Symfony\Component\OptionsResolver\OptionsResolver;
14
15
final class ScheduleChoiceType extends AbstractType
16
{
17
    /**
18
     * @var ScheduleRepositoryInterface
19
     */
20
    private $scheduleRepository;
21
22
    /**
23
     * @param ScheduleRepositoryInterface $scheduleRepository
24
     */
25
    public function __construct(ScheduleRepositoryInterface $scheduleRepository)
26
    {
27
        $this->scheduleRepository = $scheduleRepository;
28
    }
29
30
    /**
31
     * {@inheritdoc}
32
     */
33
    public function buildForm(FormBuilderInterface $builder, array $options): void
34
    {
35
        if ($options['multiple']) {
36
            $builder->addModelTransformer(new CollectionToArrayTransformer());
37
        }
38
    }
39
40
    /**
41
     * {@inheritdoc}
42
     */
43
    public function configureOptions(OptionsResolver $resolver): void
44
    {
45
        $resolver->setDefaults([
46
            'choices' => function (Options $options): array {
0 ignored issues
show
Unused Code introduced by
The parameter $options is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

46
            'choices' => function (/** @scrutinizer ignore-unused */ Options $options): array {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
47
                return $this->scheduleRepository->findAll();
48
            },
49
            'choice_value' => 'code',
50
            'choice_label' => 'name',
51
            'choice_translation_domain' => false,
52
        ]);
53
    }
54
55
    /**
56
     * {@inheritdoc}
57
     */
58
    public function getParent(): string
59
    {
60
        return ChoiceType::class;
61
    }
62
63
    /**
64
     * {@inheritdoc}
65
     */
66
    public function getBlockPrefix(): string
67
    {
68
        return 'setono_sylius_scheduler_schedule_choice';
69
    }
70
}
71