• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

systemsdk / docker-symfony-api / #82

pending completion
#82

push

DKravtsov
Updated composer dependencies, refactoring.

45 of 45 new or added lines in 12 files covered. (100.0%)

1483 of 2844 relevant lines covered (52.14%)

22.41 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/User/Transport/Form/Type/Console/UserType.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace App\User\Transport\Form\Type\Console;
6

7
use App\General\Domain\Enum\Language;
8
use App\General\Transport\Form\Type\Interfaces\FormTypeLabelInterface;
9
use App\General\Transport\Form\Type\Traits\AddBasicFieldToForm;
10
use App\Tool\Application\Service\LocalizationService;
11
use App\Tool\Domain\Service\Interfaces\LocalizationServiceInterface;
12
use App\User\Application\DTO\User\User as UserDto;
13
use App\User\Application\Resource\UserGroupResource;
14
use App\User\Transport\Form\DataTransformer\UserGroupTransformer;
15
use App\User\Transport\Form\Type\Traits\UserGroupChoices;
16
use Symfony\Component\Form\AbstractType;
17
use Symfony\Component\Form\Extension\Core\Type;
18
use Symfony\Component\Form\FormBuilderInterface;
19
use Symfony\Component\OptionsResolver\Exception\AccessException;
20
use Symfony\Component\OptionsResolver\OptionsResolver;
21
use Throwable;
22

23
use function array_combine;
24
use function array_map;
25

26
/**
27
 * Class UserType
28
 *
29
 * @package App\User
30
 */
31
class UserType extends AbstractType
32
{
33
    use AddBasicFieldToForm;
34
    use UserGroupChoices;
35

36
    /**
37
     * Base form fields
38
     *
39
     * @var array<int, array<int, mixed>>
40
     */
41
    private static array $formFields = [
42
        [
43
            'username',
44
            Type\TextType::class,
45
            [
46
                FormTypeLabelInterface::LABEL => 'Username',
47
                FormTypeLabelInterface::REQUIRED => true,
48
                FormTypeLabelInterface::EMPTY_DATA => '',
49
            ],
50
        ],
51
        [
52
            'firstName',
53
            Type\TextType::class,
54
            [
55
                FormTypeLabelInterface::LABEL => 'First name',
56
                FormTypeLabelInterface::REQUIRED => true,
57
                FormTypeLabelInterface::EMPTY_DATA => '',
58
            ],
59
        ],
60
        [
61
            'lastName',
62
            Type\TextType::class,
63
            [
64
                FormTypeLabelInterface::LABEL => 'Last name',
65
                FormTypeLabelInterface::REQUIRED => true,
66
                FormTypeLabelInterface::EMPTY_DATA => '',
67
            ],
68
        ],
69
        [
70
            'email',
71
            Type\EmailType::class,
72
            [
73
                FormTypeLabelInterface::LABEL => 'Email address',
74
                FormTypeLabelInterface::REQUIRED => true,
75
                FormTypeLabelInterface::EMPTY_DATA => '',
76
            ],
77
        ],
78
        [
79
            'password',
80
            Type\RepeatedType::class,
81
            [
82
                FormTypeLabelInterface::TYPE => Type\PasswordType::class,
83
                FormTypeLabelInterface::REQUIRED => true,
84
                FormTypeLabelInterface::FIRST_NAME => 'password1',
85
                FormTypeLabelInterface::FIRST_OPTIONS => [
86
                    FormTypeLabelInterface::LABEL => 'Password',
87
                ],
88
                FormTypeLabelInterface::SECOND_NAME => 'password2',
89
                FormTypeLabelInterface::SECOND_OPTIONS => [
90
                    FormTypeLabelInterface::LABEL => 'Repeat password',
91
                ],
92
            ],
93
        ],
94
    ];
95

96
    public function __construct(
97
        private readonly UserGroupResource $userGroupResource,
98
        private readonly UserGroupTransformer $userGroupTransformer,
99
        private readonly LocalizationService $localization,
100
    ) {
101
    }
×
102

103
    /**
104
     * {@inheritdoc}
105
     *
106
     * @throws Throwable
107
     */
108
    public function buildForm(FormBuilderInterface $builder, array $options): void
109
    {
110
        parent::buildForm($builder, $options);
×
111

112
        $this->addBasicFieldToForm($builder, self::$formFields);
×
113
        $this->addLocalizationFieldsToForm($builder);
×
114

115
        $builder
×
116
            ->add(
×
117
                'userGroups',
×
118
                Type\ChoiceType::class,
×
119
                [
×
120
                    FormTypeLabelInterface::CHOICES => $this->getUserGroupChoices(),
×
121
                    FormTypeLabelInterface::REQUIRED => true,
×
122
                    FormTypeLabelInterface::EMPTY_DATA => '',
×
123
                    'multiple' => true,
×
124
                ]
×
125
            );
×
126

127
        $builder->get('userGroups')->addModelTransformer($this->userGroupTransformer);
×
128
    }
129

130
    /**
131
     * Configures the options for this type.
132
     *
133
     * @param OptionsResolver $resolver The resolver for the options
134
     *
135
     * @throws AccessException
136
     */
137
    public function configureOptions(OptionsResolver $resolver): void
138
    {
139
        parent::configureOptions($resolver);
×
140

141
        $resolver->setDefaults([
×
142
            'data_class' => UserDto::class,
×
143
        ]);
×
144
    }
145

146
    private function addLocalizationFieldsToForm(FormBuilderInterface $builder): void
147
    {
148
        $locales = $this->localization->getLocales();
×
149
        $builder
×
150
            ->add(
×
151
                'language',
×
152
                Type\EnumType::class,
×
153
                [
×
154
                    FormTypeLabelInterface::CLASS_NAME => Language::class,
×
155
                    FormTypeLabelInterface::LABEL => 'Language',
×
156
                    FormTypeLabelInterface::REQUIRED => true,
×
157
                    FormTypeLabelInterface::EMPTY_DATA => Language::getDefault(),
×
158
                ],
×
159
            );
×
160
        $builder
×
161
            ->add(
×
162
                'locale',
×
163
                Type\ChoiceType::class,
×
164
                [
×
165
                    FormTypeLabelInterface::LABEL => 'Locale',
×
166
                    FormTypeLabelInterface::REQUIRED => true,
×
167
                    FormTypeLabelInterface::EMPTY_DATA => LocalizationServiceInterface::DEFAULT_LOCALE,
×
168
                    FormTypeLabelInterface::CHOICES => array_combine($locales, $locales),
×
169
                ],
×
170
            );
×
171
        $builder
×
172
            ->add(
×
173
                'timezone',
×
174
                Type\ChoiceType::class,
×
175
                [
×
176
                    FormTypeLabelInterface::LABEL => 'Timezone',
×
177
                    FormTypeLabelInterface::REQUIRED => true,
×
178
                    FormTypeLabelInterface::EMPTY_DATA => LocalizationServiceInterface::DEFAULT_TIMEZONE,
×
179
                    FormTypeLabelInterface::CHOICES => $this->getTimeZoneChoices(),
×
180
                ],
×
181
            );
×
182
    }
183

184
    /**
185
     * Method to get choices array for time zones.
186
     *
187
     * @throws Throwable
188
     *
189
     * @return array<string, string>
190
     */
191
    private function getTimeZoneChoices(): array
192
    {
193
        // Initialize output
194
        $choices = [];
×
195
        $iterator = static function (array $timezone) use (&$choices): void {
×
196
            $choices[$timezone['value'] . ' (' . $timezone['offset'] . ')'] = $timezone['identifier'];
×
197
        };
×
198
        array_map($iterator, $this->localization->getFormattedTimezones());
×
199

200
        return $choices;
×
201
    }
202
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc