Skip to content

Commit 346db57

Browse files
committed
Changed private static array-properties to const
1 parent da918f6 commit 346db57

File tree

8 files changed

+26
-26
lines changed

8 files changed

+26
-26
lines changed

Extension/Core/DataTransformer/DateIntervalToArrayTransformer.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class DateIntervalToArrayTransformer implements DataTransformerInterface
3030
public const SECONDS = 'seconds';
3131
public const INVERT = 'invert';
3232

33-
private static $availableFields = [
33+
private const AVAILABLE_FIELDS = [
3434
self::YEARS => 'y',
3535
self::MONTHS => 'm',
3636
self::DAYS => 'd',
@@ -85,7 +85,7 @@ public function transform($dateInterval)
8585
throw new UnexpectedTypeException($dateInterval, \DateInterval::class);
8686
}
8787
$result = [];
88-
foreach (self::$availableFields as $field => $char) {
88+
foreach (self::AVAILABLE_FIELDS as $field => $char) {
8989
$result[$field] = $dateInterval->format('%'.($this->pad ? strtoupper($char) : $char));
9090
}
9191
if (\in_array('weeks', $this->fields, true)) {
@@ -134,7 +134,7 @@ public function reverseTransform($value)
134134
if (isset($value['invert']) && !\is_bool($value['invert'])) {
135135
throw new TransformationFailedException('The value of "invert" must be boolean.');
136136
}
137-
foreach (self::$availableFields as $field => $char) {
137+
foreach (self::AVAILABLE_FIELDS as $field => $char) {
138138
if ('invert' !== $field && isset($value[$field]) && !ctype_digit((string) $value[$field])) {
139139
throw new TransformationFailedException(sprintf('This amount of "%s" is invalid.', $field));
140140
}

Extension/Core/Type/DateIntervalType.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class DateIntervalType extends AbstractType
3737
'minutes',
3838
'seconds',
3939
];
40-
private static $widgets = [
40+
private const WIDGETS = [
4141
'text' => TextType::class,
4242
'integer' => IntegerType::class,
4343
'choice' => ChoiceType::class,
@@ -112,7 +112,7 @@ public function buildForm(FormBuilderInterface $builder, array $options)
112112
$childOptions['choices'] = $options[$part];
113113
$childOptions['placeholder'] = $options['placeholder'][$part];
114114
}
115-
$childForm = $builder->create($part, self::$widgets[$options['widget']], $childOptions);
115+
$childForm = $builder->create($part, self::WIDGETS[$options['widget']], $childOptions);
116116
if ('integer' === $options['widget']) {
117117
$childForm->addModelTransformer(
118118
new ReversedTransformer(

Extension/Core/Type/DateTimeType.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class DateTimeType extends AbstractType
4040
*/
4141
public const HTML5_FORMAT = "yyyy-MM-dd'T'HH:mm:ss";
4242

43-
private static $acceptedFormats = [
43+
private const ACCEPTED_FORMATS = [
4444
\IntlDateFormatter::FULL,
4545
\IntlDateFormatter::LONG,
4646
\IntlDateFormatter::MEDIUM,
@@ -71,7 +71,7 @@ public function buildForm(FormBuilderInterface $builder, array $options)
7171
$calendar = \IntlDateFormatter::GREGORIAN;
7272
$pattern = \is_string($options['format']) ? $options['format'] : null;
7373

74-
if (!\in_array($dateFormat, self::$acceptedFormats, true)) {
74+
if (!\in_array($dateFormat, self::ACCEPTED_FORMATS, true)) {
7575
throw new InvalidOptionsException('The "date_format" option must be one of the IntlDateFormatter constants (FULL, LONG, MEDIUM, SHORT) or a string representing a custom format.');
7676
}
7777

Extension/Core/Type/DateType.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,14 @@ class DateType extends AbstractType
3131
public const DEFAULT_FORMAT = \IntlDateFormatter::MEDIUM;
3232
public const HTML5_FORMAT = 'yyyy-MM-dd';
3333

34-
private static $acceptedFormats = [
34+
private const ACCEPTED_FORMATS = [
3535
\IntlDateFormatter::FULL,
3636
\IntlDateFormatter::LONG,
3737
\IntlDateFormatter::MEDIUM,
3838
\IntlDateFormatter::SHORT,
3939
];
4040

41-
private static $widgets = [
41+
private const WIDGETS = [
4242
'text' => 'Symfony\Component\Form\Extension\Core\Type\TextType',
4343
'choice' => 'Symfony\Component\Form\Extension\Core\Type\ChoiceType',
4444
];
@@ -53,7 +53,7 @@ public function buildForm(FormBuilderInterface $builder, array $options)
5353
$calendar = \IntlDateFormatter::GREGORIAN;
5454
$pattern = \is_string($options['format']) ? $options['format'] : '';
5555

56-
if (!\in_array($dateFormat, self::$acceptedFormats, true)) {
56+
if (!\in_array($dateFormat, self::ACCEPTED_FORMATS, true)) {
5757
throw new InvalidOptionsException('The "format" option must be one of the IntlDateFormatter constants (FULL, LONG, MEDIUM, SHORT) or a string representing a custom format.');
5858
}
5959

@@ -155,9 +155,9 @@ class_exists(\IntlTimeZone::class, false) ? \IntlTimeZone::createDefault() : nul
155155
}
156156

157157
$builder
158-
->add('year', self::$widgets[$options['widget']], $yearOptions)
159-
->add('month', self::$widgets[$options['widget']], $monthOptions)
160-
->add('day', self::$widgets[$options['widget']], $dayOptions)
158+
->add('year', self::WIDGETS[$options['widget']], $yearOptions)
159+
->add('month', self::WIDGETS[$options['widget']], $monthOptions)
160+
->add('day', self::WIDGETS[$options['widget']], $dayOptions)
161161
->addViewTransformer(new DateTimeToArrayTransformer(
162162
$options['model_timezone'], $options['view_timezone'], ['year', 'month', 'day']
163163
))

Extension/Core/Type/FileType.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class FileType extends AbstractType
2828
public const KIB_BYTES = 1024;
2929
public const MIB_BYTES = 1048576;
3030

31-
private static $suffixes = [
31+
private const SUFFIXES = [
3232
1 => 'bytes',
3333
self::KIB_BYTES => 'KiB',
3434
self::MIB_BYTES => 'MiB',
@@ -244,7 +244,7 @@ private function factorizeSizes(int $size, $limit)
244244
$sizeAsString = (string) round($size / $coef, 2);
245245
}
246246

247-
return [$limitAsString, self::$suffixes[$coef]];
247+
return [$limitAsString, self::SUFFIXES[$coef]];
248248
}
249249

250250
/**

Extension/Core/Type/TimeType.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
class TimeType extends AbstractType
3030
{
31-
private static $widgets = [
31+
private const WIDGETS = [
3232
'text' => 'Symfony\Component\Form\Extension\Core\Type\TextType',
3333
'choice' => 'Symfony\Component\Form\Extension\Core\Type\ChoiceType',
3434
];
@@ -169,15 +169,15 @@ public function buildForm(FormBuilderInterface $builder, array $options)
169169
}
170170
}
171171

172-
$builder->add('hour', self::$widgets[$options['widget']], $hourOptions);
172+
$builder->add('hour', self::WIDGETS[$options['widget']], $hourOptions);
173173

174174
if ($options['with_minutes']) {
175175
if ($emptyData instanceof \Closure) {
176176
$minuteOptions['empty_data'] = $lazyEmptyData('minute');
177177
} elseif (isset($emptyData['minute'])) {
178178
$minuteOptions['empty_data'] = $emptyData['minute'];
179179
}
180-
$builder->add('minute', self::$widgets[$options['widget']], $minuteOptions);
180+
$builder->add('minute', self::WIDGETS[$options['widget']], $minuteOptions);
181181
}
182182

183183
if ($options['with_seconds']) {
@@ -186,7 +186,7 @@ public function buildForm(FormBuilderInterface $builder, array $options)
186186
} elseif (isset($emptyData['second'])) {
187187
$secondOptions['empty_data'] = $emptyData['second'];
188188
}
189-
$builder->add('second', self::$widgets[$options['widget']], $secondOptions);
189+
$builder->add('second', self::WIDGETS[$options['widget']], $secondOptions);
190190
}
191191

192192
$builder->addViewTransformer(new DateTimeToArrayTransformer($options['model_timezone'], $options['view_timezone'], $parts, 'text' === $options['widget'], $options['reference_date']));

Extension/Core/Type/WeekType.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
class WeekType extends AbstractType
2525
{
26-
private static $widgets = [
26+
private const WIDGETS = [
2727
'text' => IntegerType::class,
2828
'choice' => ChoiceType::class,
2929
];
@@ -78,8 +78,8 @@ public function buildForm(FormBuilderInterface $builder, array $options)
7878
}
7979
}
8080

81-
$builder->add('year', self::$widgets[$options['widget']], $yearOptions);
82-
$builder->add('week', self::$widgets[$options['widget']], $weekOptions);
81+
$builder->add('year', self::WIDGETS[$options['widget']], $yearOptions);
82+
$builder->add('week', self::WIDGETS[$options['widget']], $weekOptions);
8383
}
8484
}
8585

NativeRequestHandler.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class NativeRequestHandler implements RequestHandlerInterface
2626
/**
2727
* The allowed keys of the $_FILES array.
2828
*/
29-
private static $fileKeys = [
29+
private const FILE_KEYS = [
3030
'error',
3131
'name',
3232
'size',
@@ -201,12 +201,12 @@ private static function fixPhpFilesArray($data)
201201
$keys = array_keys($data);
202202
sort($keys);
203203

204-
if (self::$fileKeys !== $keys || !isset($data['name']) || !\is_array($data['name'])) {
204+
if (self::FILE_KEYS !== $keys || !isset($data['name']) || !\is_array($data['name'])) {
205205
return $data;
206206
}
207207

208208
$files = $data;
209-
foreach (self::$fileKeys as $k) {
209+
foreach (self::FILE_KEYS as $k) {
210210
unset($files[$k]);
211211
}
212212

@@ -237,7 +237,7 @@ private static function stripEmptyFiles($data)
237237
$keys = array_keys($data);
238238
sort($keys);
239239

240-
if (self::$fileKeys === $keys) {
240+
if (self::FILE_KEYS === $keys) {
241241
if (\UPLOAD_ERR_NO_FILE === $data['error']) {
242242
return null;
243243
}

0 commit comments

Comments
 (0)