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

systemsdk / docker-symfony-api / #74

pending completion
#74

push

DKravtsov
Php 8.2, symfony 6.2, updated RabbitMQ, updated composer dependencies, refactoring.

51 of 51 new or added lines in 44 files covered. (100.0%)

1479 of 2668 relevant lines covered (55.43%)

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

22
use function array_combine;
23
use function array_map;
24

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

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

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

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

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

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

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

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

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

145
    private function addLocalizationFieldsToForm(FormBuilderInterface $builder): void
146
    {
147
        $languages = $this->localization->getLanguages();
×
148
        $locales = $this->localization->getLocales();
×
149
        $builder
×
150
            ->add(
×
151
                'language',
×
152
                Type\ChoiceType::class,
×
153
                [
×
154
                    FormTypeLabelInterface::LABEL => 'Language',
×
155
                    FormTypeLabelInterface::REQUIRED => true,
×
156
                    FormTypeLabelInterface::EMPTY_DATA => LocalizationServiceInterface::DEFAULT_LANGUAGE,
×
157
                    FormTypeLabelInterface::CHOICES => array_combine($languages, $languages),
×
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
     * @return array<string, string>
188
     */
189
    private function getTimeZoneChoices(): array
190
    {
191
        // Initialize output
192
        $choices = [];
×
193
        $iterator = static function (array $timezone) use (&$choices): void {
×
194
            $choices[$timezone['value'] . ' (' . $timezone['offset'] . ')'] = $timezone['identifier'];
×
195
        };
×
196
        array_map($iterator, $this->localization->getFormattedTimezones());
×
197

198
        return $choices;
×
199
    }
200
}
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