Skip to content

Commit 6ddc375

Browse files
committed
refactor: fix param types
1 parent cb5b303 commit 6ddc375

File tree

5 files changed

+16
-12
lines changed

5 files changed

+16
-12
lines changed

system/HTTP/Files/FileCollection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ protected function createFileObject(array $array)
187187
$array['tmp_name'] ?? null,
188188
$array['name'] ?? null,
189189
$array['type'] ?? null,
190-
$array['size'] ?? null,
190+
($array['size'] ?? null) === null ? null : (int) $array['size'],
191191
$array['error'] ?? null,
192192
$array['full_path'] ?? null
193193
);

system/Helpers/number_helper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ function format_number(float $num, int $precision = 1, ?string $locale = null, a
144144

145145
// Try to format it per the locale
146146
if ($type === NumberFormatter::CURRENCY) {
147-
$formatter->setAttribute(NumberFormatter::FRACTION_DIGITS, $options['fraction']);
147+
$formatter->setAttribute(NumberFormatter::FRACTION_DIGITS, (float) $options['fraction']);
148148
$output = $formatter->formatCurrency($num, $options['currency']);
149149
} else {
150150
// In order to specify a precision, we'll have to modify

system/I18n/TimeTrait.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,7 @@ public function setYear($value)
545545
public function setMonth($value)
546546
{
547547
if (is_numeric($value) && ($value < 1 || $value > 12)) {
548-
throw I18nException::forInvalidMonth($value);
548+
throw I18nException::forInvalidMonth((string) $value);
549549
}
550550

551551
if (is_string($value) && ! is_numeric($value)) {
@@ -567,13 +567,13 @@ public function setMonth($value)
567567
public function setDay($value)
568568
{
569569
if ($value < 1 || $value > 31) {
570-
throw I18nException::forInvalidDay($value);
570+
throw I18nException::forInvalidDay((string) $value);
571571
}
572572

573573
$date = $this->getYear() . '-' . $this->getMonth();
574574
$lastDay = date('t', strtotime($date));
575575
if ($value > $lastDay) {
576-
throw I18nException::forInvalidOverDay($lastDay, $value);
576+
throw I18nException::forInvalidOverDay($lastDay, (string) $value);
577577
}
578578

579579
return $this->setValue('day', $value);
@@ -591,7 +591,7 @@ public function setDay($value)
591591
public function setHour($value)
592592
{
593593
if ($value < 0 || $value > 23) {
594-
throw I18nException::forInvalidHour($value);
594+
throw I18nException::forInvalidHour((string) $value);
595595
}
596596

597597
return $this->setValue('hour', $value);
@@ -609,7 +609,7 @@ public function setHour($value)
609609
public function setMinute($value)
610610
{
611611
if ($value < 0 || $value > 59) {
612-
throw I18nException::forInvalidMinutes($value);
612+
throw I18nException::forInvalidMinutes((string) $value);
613613
}
614614

615615
return $this->setValue('minute', $value);
@@ -627,7 +627,7 @@ public function setMinute($value)
627627
public function setSecond($value)
628628
{
629629
if ($value < 0 || $value > 59) {
630-
throw I18nException::forInvalidSeconds($value);
630+
throw I18nException::forInvalidSeconds((string) $value);
631631
}
632632

633633
return $this->setValue('second', $value);

system/Router/RouteCollection.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1369,14 +1369,14 @@ protected function buildReverseRoute(string $from, array $params): string
13691369
// or maybe $placeholder is not a placeholder, but a regex.
13701370
$pattern = $this->placeholders[$placeholderName] ?? $placeholder;
13711371

1372-
if (! preg_match('#^' . $pattern . '$#u', $params[$index])) {
1372+
if (! preg_match('#^' . $pattern . '$#u', (string) $params[$index])) {
13731373
throw RouterException::forInvalidParameterType();
13741374
}
13751375

13761376
// Ensure that the param we're inserting matches
13771377
// the expected param type.
13781378
$pos = strpos($from, $placeholder);
1379-
$from = substr_replace($from, $params[$index], $pos, strlen($placeholder));
1379+
$from = substr_replace($from, (string) $params[$index], $pos, strlen($placeholder));
13801380
}
13811381

13821382
$from = $this->replaceLocale($from, $locale);

system/View/Filters.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ public static function date($value, string $format): string
4040
$value = strtotime($value);
4141
}
4242

43+
if ($value !== null) {
44+
$value = (int) $value;
45+
}
46+
4347
return date($format, $value);
4448
}
4549

@@ -160,7 +164,7 @@ public static function local_number($value, string $type = 'decimal', int $preci
160164
'duration' => NumberFormatter::DURATION,
161165
];
162166

163-
return format_number($value, $precision, $locale, ['type' => $types[$type]]);
167+
return format_number((float) $value, $precision, $locale, ['type' => $types[$type]]);
164168
}
165169

166170
/**
@@ -181,7 +185,7 @@ public static function local_currency($value, string $currency, ?string $locale
181185
'fraction' => $fraction,
182186
];
183187

184-
return format_number($value, 2, $locale, $options);
188+
return format_number((float) $value, 2, $locale, $options);
185189
}
186190

187191
/**

0 commit comments

Comments
 (0)