Passed
Push — master ( f5fadc...72d313 )
by Christian
02:28
created

BatchTimeType::buildForm()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 10
nc 1
nop 2
dl 0
loc 14
rs 9.9332
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * (c) Christian Gripp <[email protected]>
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
namespace Core23\Form\Type;
13
14
use Symfony\Component\Form\AbstractType;
15
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
16
use Symfony\Component\Form\FormBuilderInterface;
17
use Symfony\Component\OptionsResolver\OptionsResolver;
18
19
final class BatchTimeType extends AbstractType
20
{
21
    /**
22
     * @var string
23
     */
24
    private $class;
25
26
    /**
27
     * @param string $class
28
     */
29
    public function __construct(string $class)
30
    {
31
        $this->class = $class;
32
    }
33
34
    /**
35
     * {@inheritdoc}
36
     */
37
    public function buildForm(FormBuilderInterface $builder, array $options): void
38
    {
39
        $required = $builder->getForm()->isRequired();
40
41
        $builder
42
            ->add('day', ChoiceType::class, [
43
                'label'                     => 'form.input_batch_time_day',
44
                'choices'                   => range(0, 2),
45
                'choice_translation_domain' => false,
46
                'required'                  => $required,
47
            ])
48
            ->add('time', TimePickerType::class, [
49
                'label'    => 'form.input_batch_time_time',
50
                'required' => $required,
51
            ]);
52
    }
53
54
    /**
55
     * {@inheritdoc}
56
     */
57
    public function getBlockPrefix()
58
    {
59
        return 'batch_time';
60
    }
61
62
    /**
63
     * {@inheritdoc}
64
     */
65
    public function configureOptions(OptionsResolver $resolver): void
66
    {
67
        $resolver->setDefaults([
68
            'data_class' => $this->class,
69
        ]);
70
    }
71
}
72