GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

TimePickerType::createDpOptions()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 21
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 11
c 1
b 0
f 0
nc 3
nop 1
dl 0
loc 21
rs 9.9
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\TimeType;
16
use Symfony\Component\Form\FormInterface;
17
use Symfony\Component\Form\FormView;
18
use Symfony\Component\OptionsResolver\OptionsResolver;
19
20
final class TimePickerType extends AbstractType
21
{
22
    public function finishView(FormView $view, FormInterface $form, array $options): void
23
    {
24
        $format    = 'HH';
25
26
        if (true === $options['with_minutes']) {
27
            $format .= ':mm';
28
            $options['dp_use_minutes'] = true;
29
        }
30
31
        if (true === $options['with_seconds']) {
32
            $format .= ':ss';
33
            $options['dp_use_seconds'] = true;
34
        }
35
36
        $view->vars['moment_format']         = $format;
37
        $view->vars['datepicker_use_button'] = (bool) $options['datepicker_use_button'];
38
        $view->vars['dp_options']            = self::createDpOptions($options);
39
    }
40
41
    public function configureOptions(OptionsResolver $resolver): void
42
    {
43
        $resolver
44
            ->setDefaults([
45
                'input'                 => 'datetime',
46
                'widget'                => 'single_text',
47
                'datepicker_use_button' => true,
48
                'dp_pick_date'          => false,
49
                'dp_minute_stepping'    => 1,
50
            ])
51
            ->setAllowedTypes('input', 'string')
52
            ->setAllowedTypes('widget', 'string')
53
        ;
54
    }
55
56
    public function getParent(): string
57
    {
58
        return TimeType::class;
59
    }
60
61
    public function getBlockPrefix(): string
62
    {
63
        return 'core23_type_time_picker';
64
    }
65
66
    private static function createDpOptions(array $options): array
67
    {
68
        $dpOptions = [];
69
70
        foreach ($options as $key => $value) {
71
            if (false !== strpos($key, 'dp_')) {
72
                // We remove 'dp_' and camelize the options names
73
                $dpKey = substr($key, 3);
74
                $dpKey = preg_replace_callback(
75
                    '/_([a-z])/',
76
                    static function ($c) {
77
                        return strtoupper($c[1]);
78
                    },
79
                    $dpKey
80
                );
81
82
                $dpOptions[$dpKey] = $value;
83
            }
84
        }
85
86
        return $dpOptions;
87
    }
88
}
89