Skip to content

Commit 5ca831b

Browse files
Apply latest Rector changes
1 parent 7cc76b7 commit 5ca831b

File tree

5 files changed

+49
-138
lines changed

5 files changed

+49
-138
lines changed

phpstan-baseline.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -392,8 +392,8 @@
392392
'path' => __DIR__ . '/src/Factory/FieldOptions.php',
393393
];
394394
$ignoreErrors[] = [
395-
'message' => '#^Method Bolt\\\\BoltForms\\\\Factory\\\\FieldType\\:\\:get\\(\\) has parameter \\$field with no type specified\\.$#',
396-
'identifier' => 'missingType.parameter',
395+
'message' => '#^Method Bolt\\\\BoltForms\\\\Factory\\\\FieldType\\:\\:get\\(\\) has parameter \\$field with no value type specified in iterable type array\\.$#',
396+
'identifier' => 'missingType.iterableValue',
397397
'count' => 1,
398398
'path' => __DIR__ . '/src/Factory/FieldType.php',
399399
];
@@ -445,12 +445,6 @@
445445
'count' => 1,
446446
'path' => __DIR__ . '/src/FormBuilder.php',
447447
];
448-
$ignoreErrors[] = [
449-
'message' => '#^Method Bolt\\\\BoltForms\\\\FormBuilder\\:\\:addField\\(\\) has parameter \\$formName with no type specified\\.$#',
450-
'identifier' => 'missingType.parameter',
451-
'count' => 1,
452-
'path' => __DIR__ . '/src/FormBuilder.php',
453-
];
454448
$ignoreErrors[] = [
455449
'message' => '#^Method Bolt\\\\BoltForms\\\\FormBuilder\\:\\:addHoneypot\\(\\) has parameter \\$config with generic class Illuminate\\\\Support\\\\Collection but does not specify its types\\: TKey, TValue$#',
456450
'identifier' => 'missingType.generics',

src/EventSubscriber/ContentTypePersister.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
use Carbon\Carbon;
1313
use DateTimeInterface;
1414
use Doctrine\ORM\EntityManagerInterface;
15-
use http\Exception\RuntimeException;
1615
use Illuminate\Support\Collection;
16+
use RuntimeException;
1717
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
1818
use Symfony\Component\Form\FormInterface;
1919

@@ -77,10 +77,8 @@ private function setContentFields(Content $content, FormInterface $form, PostSub
7777
}
7878

7979
if (is_array($value)) {
80-
$value = implode(', ', array_map(function ($entry) {
81-
// check if $entry is an array and not empty
82-
return (is_array($entry) && count($entry) > 0) ? $entry[0] : '';
83-
}, $value));
80+
// check if $entry is an array and not empty
81+
$value = implode(', ', array_map(fn ($entry): mixed => (is_array($entry) && count($entry) > 0) ? $entry[0] : '', $value));
8482
}
8583

8684
if ($value instanceof DateTimeInterface) {

src/Factory/FieldType.php

Lines changed: 42 additions & 123 deletions
Original file line numberDiff line numberDiff line change
@@ -45,130 +45,49 @@
4545

4646
class FieldType
4747
{
48-
public static function get($field): string
48+
public static function get(array $field): string
4949
{
50-
switch ($field['type']) {
51-
case 'captcha':
52-
$type = CaptchaType::class;
53-
break;
54-
case 'birthday':
55-
$type = BirthdayType::class;
56-
break;
57-
case 'button':
58-
$type = ButtonType::class;
59-
break;
60-
case 'checkbox':
61-
$type = CheckboxType::class;
62-
break;
63-
case 'choice':
64-
$type = ChoiceType::class;
65-
break;
66-
case 'collection':
67-
$type = CollectionType::class;
68-
break;
69-
case 'color':
70-
$type = ColorType::class;
71-
break;
72-
case 'contenttype':
73-
$type = ContenttypeType::class;
74-
break;
75-
case 'country':
76-
$type = CountryType::class;
77-
break;
78-
case 'currency':
79-
$type = CurrencyType::class;
80-
break;
81-
case 'dateinterval':
82-
$type = DateIntervalType::class;
83-
break;
84-
case 'datetime':
85-
$type = DateTimeType::class;
86-
break;
87-
case 'date':
88-
$type = DateType::class;
89-
break;
90-
case 'email':
91-
$type = EmailType::class;
92-
break;
93-
case 'file':
94-
$type = FileType::class;
95-
break;
96-
// case 'form':
97-
// $type = FormType::class;
98-
// break;
99-
case 'hidden':
100-
$type = HiddenType::class;
101-
break;
102-
case 'integer':
103-
$type = IntegerType::class;
104-
break;
105-
case 'language':
106-
$type = LanguageType::class;
107-
break;
108-
case 'locale':
109-
$type = LocaleType::class;
110-
break;
111-
case 'money':
112-
$type = MoneyType::class;
113-
break;
114-
case 'number':
115-
$type = NumberType::class;
116-
break;
117-
case 'password':
118-
$type = PasswordType::class;
119-
break;
120-
case 'percent':
121-
$type = PercentType::class;
122-
break;
123-
case 'radio':
124-
$type = RadioType::class;
125-
break;
126-
case 'range':
127-
$type = RangeType::class;
128-
break;
129-
case 'repeated':
130-
$type = RepeatedType::class;
131-
break;
132-
case 'reset':
133-
$type = ResetType::class;
134-
break;
135-
case 'search':
136-
$type = SearchType::class;
137-
break;
138-
case 'submit':
139-
$type = SubmitType::class;
140-
break;
141-
case 'tel':
142-
$type = TelType::class;
143-
break;
144-
case 'text':
145-
$type = TextType::class;
146-
break;
147-
case 'textarea':
148-
$type = TextareaType::class;
149-
break;
150-
case 'time':
151-
$type = TimeType::class;
152-
break;
153-
case 'timezone':
154-
$type = TimezoneType::class;
155-
break;
156-
case 'url':
157-
$type = UrlType::class;
158-
break;
159-
case 'week':
160-
$type = WeekType::class;
161-
break;
162-
case 'gregwarCaptcha':
163-
$type = GregwarCaptchaType::class;
164-
break;
165-
case 'turnstileCaptcha':
166-
$type = TurnstileType::class;
167-
break;
168-
default:
169-
$type = TextType::class;
170-
break;
171-
}
50+
$type = match ($field['type']) {
51+
'captcha' => CaptchaType::class,
52+
'birthday' => BirthdayType::class,
53+
'button' => ButtonType::class,
54+
'checkbox' => CheckboxType::class,
55+
'choice' => ChoiceType::class,
56+
'collection' => CollectionType::class,
57+
'color' => ColorType::class,
58+
'contenttype' => ContenttypeType::class,
59+
'country' => CountryType::class,
60+
'currency' => CurrencyType::class,
61+
'dateinterval' => DateIntervalType::class,
62+
'datetime' => DateTimeType::class,
63+
'date' => DateType::class,
64+
'email' => EmailType::class,
65+
'file' => FileType::class,
66+
'hidden' => HiddenType::class,
67+
'integer' => IntegerType::class,
68+
'language' => LanguageType::class,
69+
'locale' => LocaleType::class,
70+
'money' => MoneyType::class,
71+
'number' => NumberType::class,
72+
'password' => PasswordType::class,
73+
'percent' => PercentType::class,
74+
'radio' => RadioType::class,
75+
'range' => RangeType::class,
76+
'repeated' => RepeatedType::class,
77+
'reset' => ResetType::class,
78+
'search' => SearchType::class,
79+
'submit' => SubmitType::class,
80+
'tel' => TelType::class,
81+
'text' => TextType::class,
82+
'textarea' => TextareaType::class,
83+
'time' => TimeType::class,
84+
'timezone' => TimezoneType::class,
85+
'url' => UrlType::class,
86+
'week' => WeekType::class,
87+
'gregwarCaptcha' => GregwarCaptchaType::class,
88+
'turnstileCaptcha' => TurnstileType::class,
89+
default => TextType::class,
90+
};
17291

17392
return $type;
17493
}

src/FormBuilder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ private function addField(
140140
string $name,
141141
array $field,
142142
Collection $config,
143-
$formName
143+
string $formName
144144
): void {
145145
// If we're using reCaptcha V3 or V2 invisible, we need to add some attributes to the submit button
146146
// If we're adding a submit button, attach the attributes if we're using reCaptcha v3 or v2 invisible

src/FormHelper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public function get(?string $format, FormInterface $form, $values = []): ?string
1616

1717
return preg_replace_callback(
1818
'/{([\w]+)}/i',
19-
function ($match) use ($form, $values) {
19+
function (array $match) use ($form, $values): string {
2020
if (\array_key_exists($match[1], $form->all())) {
2121
return (string) $form->get($match[1])->getData();
2222
}

0 commit comments

Comments
 (0)