Skip to content

Commit 05c2904

Browse files
author
Wout Gevaert
committed
In Integer::__construct acount for return value false of filter_var
1 parent 54dee79 commit 05c2904

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/Expressions/Literals/Integer.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,19 @@ public function __construct($value)
3434
if (!is_int($value) && !is_string($value)) {
3535
throw new TypeError('An integer should be given as a string or integer, '.gettype($value).' received.');
3636
}
37-
$this->value = filter_var($value, FILTER_SANITIZE_NUMBER_INT);
37+
$parsedValue = filter_var($value, FILTER_SANITIZE_NUMBER_INT);
3838

39-
if (is_string($value) && $this->value !== $value) {
39+
if (false === $parsedValue) {
4040
throw new TypeError(
41-
'A non-integer string has been provided: "'.$value.'", should be something like "'.$this->value.'".'
41+
'A non-integer string has been provided: "'.$value.'".'
42+
);
43+
} elseif (is_string($value) && $parsedValue !== $value)) {
44+
throw new TypeError(
45+
'A non-integer string has been provided: "'.$value.'", should be something like "'.$parsedValue.'".'
4246
);
4347
}
48+
49+
$this->value = $parsedValue;
4450
}
4551

4652
/**

0 commit comments

Comments
 (0)