Skip to content

Commit 92de11e

Browse files
Merge pull request #39 from stephanediondev/refactoring
Refactoring
2 parents 604a662 + 2661129 commit 92de11e

File tree

67 files changed

+665
-629
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+665
-629
lines changed

src/Command/GenerateFaviconsCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
3535
return Command::SUCCESS;
3636
}
3737

38-
private function generateFavicon($color, $size): void
38+
private function generateFavicon(string $color, int $size): void
3939
{
4040
$file = __DIR__.'/../../public/favicon-'.$color.'-'.$size.'.png';
4141

src/Controller/ElasticsearchIndexController.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -341,11 +341,11 @@ public function create(Request $request): Response
341341
if ($form->isSubmitted() && $form->isValid()) {
342342
try {
343343
$json = [];
344-
if ($index->getSettings()) {
345-
$json['settings'] = $index->getSettings();
344+
if ($index->getSettingsJson()) {
345+
$json['settings'] = json_decode($index->getSettingsJson(), true);
346346
}
347-
if ($index->getMappings()) {
348-
$json['mappings'] = $index->getMappings();
347+
if ($index->getMappingsJson()) {
348+
$json['mappings'] = json_decode($index->getMappingsJson(), true);
349349
}
350350
$callRequest = new CallRequestModel();
351351
$callRequest->setMethod('PUT');
@@ -406,8 +406,8 @@ public function update(Request $request, string $index): Response
406406

407407
if ($form->isSubmitted() && $form->isValid()) {
408408
try {
409-
if ($index->getMappings()) {
410-
$json = $index->getMappings();
409+
if ($index->getMappingsJson()) {
410+
$json = json_decode($index->getMappingsJson(), true);
411411
$callRequest = new CallRequestModel();
412412
$callRequest->setMethod('PUT');
413413
$callRequest->setPath('/'.$index->getName().'/_mapping');

src/Exception/CallException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
class CallException extends RuntimeException
88
{
9-
public function __construct($message)
9+
public function __construct(string $message)
1010
{
1111
parent::__construct($message);
1212
}

src/Exception/ConnectionException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
class ConnectionException extends RuntimeException
88
{
9-
public function __construct($message)
9+
public function __construct(string $message)
1010
{
1111
parent::__construct($message);
1212
}

src/Form/EventListener/MappingsSettingsAliasesSubscriber.php

Lines changed: 0 additions & 64 deletions
This file was deleted.

src/Form/EventListener/MetadataSubscriber.php

Lines changed: 0 additions & 42 deletions
This file was deleted.

src/Form/Type/ElasticsearchComponentTemplateType.php

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33

44
namespace App\Form\Type;
55

6-
use App\Form\EventListener\MappingsSettingsAliasesSubscriber;
7-
use App\Form\EventListener\MetadataSubscriber;
86
use App\Manager\ElasticsearchComponentTemplateManager;
97
use App\Model\CallRequestModel;
108
use App\Model\ElasticsearchComponentTemplateModel;
@@ -43,10 +41,10 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
4341
$fields[] = 'name';
4442
}
4543
$fields[] = 'version';
46-
$fields[] = 'settings';
47-
$fields[] = 'mappings';
48-
$fields[] = 'aliases';
49-
$fields[] = 'metadata';
44+
$fields[] = 'settings_json';
45+
$fields[] = 'mappings_json';
46+
$fields[] = 'aliases_json';
47+
$fields[] = 'metadata_json';
5048

5149
foreach ($fields as $field) {
5250
switch ($field) {
@@ -76,8 +74,8 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
7674
'help_html' => true,
7775
]);
7876
break;
79-
case 'settings':
80-
$builder->add('settings', TextareaType::class, [
77+
case 'settings_json':
78+
$builder->add('settings_json', TextareaType::class, [
8179
'label' => 'settings',
8280
'required' => false,
8381
'constraints' => [
@@ -87,8 +85,8 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
8785
'help_html' => true,
8886
]);
8987
break;
90-
case 'mappings':
91-
$builder->add('mappings', TextareaType::class, [
88+
case 'mappings_json':
89+
$builder->add('mappings_json', TextareaType::class, [
9290
'label' => 'mappings',
9391
'required' => false,
9492
'constraints' => [
@@ -101,8 +99,8 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
10199
'help_html' => true,
102100
]);
103101
break;
104-
case 'aliases':
105-
$builder->add('aliases', TextareaType::class, [
102+
case 'aliases_json':
103+
$builder->add('aliases_json', TextareaType::class, [
106104
'label' => 'aliases',
107105
'required' => false,
108106
'constraints' => [
@@ -112,8 +110,8 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
112110
'help_html' => true,
113111
]);
114112
break;
115-
case 'metadata':
116-
$builder->add('metadata', TextareaType::class, [
113+
case 'metadata_json':
114+
$builder->add('metadata_json', TextareaType::class, [
117115
'label' => 'metadata',
118116
'required' => false,
119117
'constraints' => [
@@ -141,9 +139,6 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
141139
}
142140
}
143141
});
144-
145-
$builder->addEventSubscriber(new MappingsSettingsAliasesSubscriber());
146-
$builder->addEventSubscriber(new MetadataSubscriber());
147142
}
148143

149144
public function configureOptions(OptionsResolver $resolver): void

src/Form/Type/ElasticsearchIlmPolicyType.php

Lines changed: 12 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
3838
if ('create' == $options['context']) {
3939
$fields[] = 'name';
4040
}
41-
$fields[] = 'hot';
42-
$fields[] = 'warm';
43-
$fields[] = 'cold';
44-
$fields[] = 'delete';
41+
$fields[] = 'hot_json';
42+
$fields[] = 'warm_json';
43+
$fields[] = 'cold_json';
44+
$fields[] = 'delete_json';
4545

4646
foreach ($fields as $field) {
4747
switch ($field) {
@@ -56,8 +56,8 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
5656
'help_html' => true,
5757
]);
5858
break;
59-
case 'hot':
60-
$builder->add('hot', TextareaType::class, [
59+
case 'hot_json':
60+
$builder->add('hot_json', TextareaType::class, [
6161
'label' => 'hot',
6262
'required' => false,
6363
'constraints' => [
@@ -67,8 +67,8 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
6767
'help_html' => true,
6868
]);
6969
break;
70-
case 'warm':
71-
$builder->add('warm', TextareaType::class, [
70+
case 'warm_json':
71+
$builder->add('warm_json', TextareaType::class, [
7272
'label' => 'warm',
7373
'required' => false,
7474
'constraints' => [
@@ -81,8 +81,8 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
8181
'help_html' => true,
8282
]);
8383
break;
84-
case 'cold':
85-
$builder->add('cold', TextareaType::class, [
84+
case 'cold_json':
85+
$builder->add('cold_json', TextareaType::class, [
8686
'label' => 'cold',
8787
'required' => false,
8888
'constraints' => [
@@ -92,8 +92,8 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
9292
'help_html' => true,
9393
]);
9494
break;
95-
case 'delete':
96-
$builder->add('delete', TextareaType::class, [
95+
case 'delete_json':
96+
$builder->add('delete_json', TextareaType::class, [
9797
'label' => 'delete',
9898
'required' => false,
9999
'constraints' => [
@@ -106,34 +106,6 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
106106
}
107107
}
108108

109-
$builder->addEventListener(FormEvents::POST_SET_DATA, function (FormEvent $event) {
110-
$form = $event->getForm();
111-
112-
if ($form->has('hot') && $form->get('hot')->getData()) {
113-
$fieldOptions = $form->get('hot')->getConfig()->getOptions();
114-
$fieldOptions['data'] = json_encode($form->get('hot')->getData(), JSON_PRETTY_PRINT);
115-
$form->add('hot', TextareaType::class, $fieldOptions);
116-
}
117-
118-
if ($form->has('warm') && $form->get('warm')->getData()) {
119-
$fieldOptions = $form->get('warm')->getConfig()->getOptions();
120-
$fieldOptions['data'] = json_encode($form->get('warm')->getData(), JSON_PRETTY_PRINT);
121-
$form->add('warm', TextareaType::class, $fieldOptions);
122-
}
123-
124-
if ($form->has('cold') && $form->get('cold')->getData()) {
125-
$fieldOptions = $form->get('cold')->getConfig()->getOptions();
126-
$fieldOptions['data'] = json_encode($form->get('cold')->getData(), JSON_PRETTY_PRINT);
127-
$form->add('cold', TextareaType::class, $fieldOptions);
128-
}
129-
130-
if ($form->has('delete') && $form->get('delete')->getData()) {
131-
$fieldOptions = $form->get('delete')->getConfig()->getOptions();
132-
$fieldOptions['data'] = json_encode($form->get('delete')->getData(), JSON_PRETTY_PRINT);
133-
$form->add('delete', TextareaType::class, $fieldOptions);
134-
}
135-
});
136-
137109
$builder->addEventListener(FormEvents::POST_SUBMIT, function (FormEvent $event) use ($options) {
138110
$form = $event->getForm();
139111
$data = $event->getData();
@@ -149,26 +121,6 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
149121
}
150122
}
151123
}
152-
153-
if ($form->has('hot') && $form->get('hot')->getData()) {
154-
$data->setHot(json_decode($form->get('hot')->getData(), true));
155-
$event->setData($data);
156-
}
157-
158-
if ($form->has('warm') && $form->get('warm')->getData()) {
159-
$data->setWarm(json_decode($form->get('warm')->getData(), true));
160-
$event->setData($data);
161-
}
162-
163-
if ($form->has('cold') && $form->get('cold')->getData()) {
164-
$data->setCold(json_decode($form->get('cold')->getData(), true));
165-
$event->setData($data);
166-
}
167-
168-
if ($form->has('delete') && $form->get('delete')->getData()) {
169-
$data->setDelete(json_decode($form->get('delete')->getData(), true));
170-
$event->setData($data);
171-
}
172124
});
173125
}
174126

0 commit comments

Comments
 (0)