Skip to content

Commit 6ba8b44

Browse files
committed
strict type fixes
1 parent 54887ce commit 6ba8b44

File tree

7 files changed

+10
-9
lines changed

7 files changed

+10
-9
lines changed

examples/custom-control.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public function setValue($value)
5151
public function getValue()
5252
{
5353
return self::validateDate($this)
54-
? (new DateTimeImmutable)->setDate($this->year, $this->month, $this->day)->setTime(0, 0)
54+
? (new DateTimeImmutable)->setDate((int) $this->year, (int) $this->month, (int) $this->day)->setTime(0, 0)
5555
: NULL;
5656
}
5757

@@ -110,7 +110,7 @@ public static function validateDate(Nette\Forms\IControl $control)
110110
return ctype_digit($control->day)
111111
&& ctype_digit($control->month)
112112
&& ctype_digit($control->year)
113-
&& checkdate($control->month, $control->day, $control->year);
113+
&& checkdate((int) $control->month, (int) $control->day, (int) $control->year);
114114
}
115115

116116
}

src/Bridges/FormsLatte/Runtime.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public static function renderFormEnd(Form $form, $withTags = TRUE)
4949
{
5050
$s = '';
5151
if ($form->isMethod('get')) {
52-
foreach (preg_split('#[;&]#', parse_url($form->getElementPrototype()->action, PHP_URL_QUERY), NULL, PREG_SPLIT_NO_EMPTY) as $param) {
52+
foreach (preg_split('#[;&]#', (string) parse_url($form->getElementPrototype()->action, PHP_URL_QUERY), -1, PREG_SPLIT_NO_EMPTY) as $param) {
5353
$parts = explode('=', $param, 2);
5454
$name = urldecode($parts[0]);
5555
if (!isset($form[$name])) {

src/Forms/Controls/CsrfProtection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ public function getControl()
105105
*/
106106
public static function validateCsrf(CsrfProtection $control)
107107
{
108-
$value = $control->getValue();
108+
$value = (string) $control->getValue();
109109
return $control->generateToken(substr($value, 0, 10)) === $value;
110110
}
111111

src/Forms/Controls/TextBase.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ public function setValue($value)
4040
} elseif (!is_scalar($value) && !method_exists($value, '__toString')) {
4141
throw new Nette\InvalidArgumentException(sprintf("Value must be scalar or NULL, %s given in field '%s'.", gettype($value), $this->name));
4242
}
43-
$this->rawValue = $this->value = $value;
43+
$this->value = $value;
44+
$this->rawValue = (string) $value;
4445
return $this;
4546
}
4647

src/Forms/Helpers.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ private static function sanitize($type, $value)
6565
return is_scalar($value) ? Strings::normalizeNewLines($value) : NULL;
6666

6767
} elseif ($type === Form::DATA_LINE) {
68-
return is_scalar($value) ? Strings::trim(strtr($value, "\r\n", ' ')) : NULL;
68+
return is_scalar($value) ? Strings::trim(strtr((string) $value, "\r\n", ' ')) : NULL;
6969

7070
} elseif ($type === Form::DATA_FILE) {
7171
return $value instanceof Nette\Http\FileUpload ? $value : NULL;
@@ -198,7 +198,7 @@ public static function createSelectBox(array $items, array $optionAttrs = NULL,
198198
$res .= $caption->setName('option')->addAttributes($option->attrs);
199199
} else {
200200
$res .= $optionTag . $option->attributes() . '>'
201-
. htmlspecialchars($caption, ENT_NOQUOTES, 'UTF-8')
201+
. htmlspecialchars((string) $caption, ENT_NOQUOTES, 'UTF-8')
202202
. '</option>';
203203
}
204204
}

src/Forms/Rendering/DefaultFormRenderer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ public function renderBegin()
171171
$query = parse_url($el->action, PHP_URL_QUERY);
172172
$el->action = str_replace("?$query", '', $el->action);
173173
$s = '';
174-
foreach (preg_split('#[;&]#', $query, NULL, PREG_SPLIT_NO_EMPTY) as $param) {
174+
foreach (preg_split('#[;&]#', $query, -1, PREG_SPLIT_NO_EMPTY) as $param) {
175175
$parts = explode('=', $param, 2);
176176
$name = urldecode($parts[0]);
177177
if (!isset($this->form[$name])) {

src/Forms/Validator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ public static function validateLength(IControl $control, $range)
181181
$range = [$range, $range];
182182
}
183183
$value = $control->getValue();
184-
return Validators::isInRange(is_array($value) ? count($value) : Strings::length($value), $range);
184+
return Validators::isInRange(is_array($value) ? count($value) : Strings::length((string) $value), $range);
185185
}
186186

187187

0 commit comments

Comments
 (0)