Browse Source

methods moved to functions.php

Jozef Grencik 2 years ago
parent
commit
a2f668425f

+ 117 - 0
src/Core/functions.php

@@ -16,6 +16,7 @@ declare(strict_types=1);
  */
 namespace Cake\Core;
 
+use JsonException;
 use Stringable;
 
 if (!defined('DS')) {
@@ -325,3 +326,119 @@ if (!function_exists('Cake\Core\deprecationWarning')) {
         trigger_error($message, E_USER_DEPRECATED);
     }
 }
+
+if (!function_exists('Cake\Core\toString')) {
+    /**
+     * Converts the given value to a string.
+     *
+     * This method attempts to convert the given value to a string.
+     * If the value is already a string, it returns the value as it is.
+     * If the conversion is not possible, it returns NULL.
+     *
+     * @param mixed $value The value to be converted.
+     * @return ?string Returns the string representation of the value, or null if the value is not a string.
+     * @since 5.1.0
+     */
+    function toString(mixed $value): ?string
+    {
+        if (is_string($value)) {
+            return $value;
+        }
+        if (is_int($value)) {
+            return (string)$value;
+        }
+        if (is_bool($value)) {
+            return $value ? '1' : '0';
+        }
+        if (is_float($value)) {
+            if (is_nan($value) || is_infinite($value)) {
+                return null;
+            }
+            try {
+                $return = json_encode($value, JSON_THROW_ON_ERROR);
+            } catch (JsonException) {
+                $return = null;
+            }
+
+            if ($return === null || str_contains($return, 'e')) {
+                $return = rtrim(sprintf('%.' . (PHP_FLOAT_DIG + 3) . 'F', $value), '.0');
+            }
+
+            return $return;
+        }
+        if ($value instanceof Stringable) {
+            return (string)$value;
+        }
+
+        return null;
+    }
+}
+
+if (!function_exists('Cake\Core\toInt')) {
+    /**
+     * Converts a value to an integer.
+     *
+     * This method attempts to convert the given value to an integer.
+     * If the conversion is successful, it returns the value as an integer.
+     * If the conversion fails, it returns NULL.
+     *
+     * String values are trimmed using trim().
+     *
+     * @param mixed $value The value to be converted to an integer.
+     * @return int|null Returns the converted integer value or null if the conversion fails.
+     * @since 5.1.0
+     */
+    function toInt(mixed $value): ?int
+    {
+        if (is_int($value)) {
+            return $value;
+        }
+        if (is_string($value)) {
+            $value = filter_var($value, FILTER_VALIDATE_INT, FILTER_NULL_ON_FAILURE);
+
+            return $value === PHP_INT_MIN ? null : $value;
+        }
+        if (is_float($value)) {
+            /**
+             * @link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_SAFE_INTEGER
+             * 9007199254740991 = 2^53-1 = the maximum safe integer that can be represented without losing precision.
+             * Beyond this numerical limit, the equality (int)9007199254740993.0 === 9007199254740992 returns true.
+             */
+            if ($value >= -9007199254740991 && $value <= 9007199254740991) {
+                return (int)$value;
+            }
+
+            return null;
+        }
+        if (is_bool($value)) {
+            return (int)$value;
+        }
+
+        return null;
+    }
+}
+
+if (!function_exists('Cake\Core\toBool')) {
+    /**
+     * Converts a value to boolean.
+     *
+     *  1 | '1' | 1.0 | true  - values returns as true
+     *  0 | '0' | 0.0 | false - values returns as false
+     *  Other values returns as null.
+     *
+     * @param mixed $value The value to convert to boolean.
+     * @return bool|null Returns true if the value is truthy, false if it's falsy, or NULL otherwise.
+     * @since 5.1.0
+     */
+    function toBool(mixed $value): ?bool
+    {
+        if ($value === '1' || $value === 1 || $value === 1.0 || $value === true) {
+            return true;
+        }
+        if ($value === '0' || $value === 0 || $value === 0.0 || $value === false) {
+            return false;
+        }
+
+        return null;
+    }
+}

+ 59 - 0
src/Core/functions_global.php

@@ -24,6 +24,9 @@ use function Cake\Core\pj as cakePj;
 use function Cake\Core\pluginSplit as cakePluginSplit;
 use function Cake\Core\pr as cakePr;
 use function Cake\Core\triggerWarning as cakeTriggerWarning;
+use function Cake\Core\toString as cakeToString;
+use function Cake\Core\toInt as cakeToInt;
+use function Cake\Core\toBool as cakeToBool;
 
 if (!function_exists('h')) {
     /**
@@ -169,3 +172,59 @@ if (!function_exists('deprecationWarning')) {
         cakeDeprecationWarning($version, $message, $stackFrame + 1);
     }
 }
+
+if (!function_exists('toString')) {
+    /**
+     * Converts the given value to a string.
+     *
+     * This method attempts to convert the given value to a string.
+     * If the value is already a string, it returns the value as it is.
+     * If the conversion is not possible, it returns NULL.
+     *
+     * @param mixed $value The value to be converted.
+     * @return ?string Returns the string representation of the value, or null if the value is not a string.
+     * @since 5.1.0
+     */
+    function toString(mixed $value): ?string
+    {
+        return cakeToString($value);
+    }
+}
+
+if (!function_exists('toInt')) {
+    /**
+     * Converts a value to an integer.
+     *
+     * This method attempts to convert the given value to an integer.
+     * If the conversion is successful, it returns the value as an integer.
+     * If the conversion fails, it returns NULL.
+     *
+     * String values are trimmed using trim().
+     *
+     * @param mixed $value The value to be converted to an integer.
+     * @return int|null Returns the converted integer value or null if the conversion fails.
+     * @since 5.1.0
+     */
+    function toInt(mixed $value): ?int
+    {
+        return cakeToInt($value);
+    }
+}
+
+if (!function_exists('toBool')) {
+    /**
+     * Converts a value to boolean.
+     *
+     *  1 | '1' | 1.0 | true  - values returns as true
+     *  0 | '0' | 0.0 | false - values returns as false
+     *  Other values returns as null.
+     *
+     * @param mixed $value The value to convert to boolean.
+     * @return bool|null Returns true if the value is truthy, false if it's falsy, or NULL otherwise.
+     * @since 5.1.0
+     */
+    function toBool(mixed $value): ?bool
+    {
+        return cakeToBool($value);
+    }
+}

+ 0 - 134
src/Utility/Filter.php

@@ -1,134 +0,0 @@
-<?php
-declare(strict_types=1);
-
-/**
- * CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
- * Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
- *
- * Licensed under The MIT License
- * For full copyright and license information, please see the LICENSE.txt
- * Redistributions of files must retain the above copyright notice.
- *
- * @copyright     Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
- * @since         5.1.0
- * @license       https://opensource.org/licenses/mit-license.php MIT License
- */
-
-namespace Cake\Utility;
-
-use JsonException;
-use Stringable;
-
-/**
- * Methods for converting mixed values to specific data types, ensuring a type-safe approach to data manipulation.
- * This utility is useful for safely narrowing down the data types.
- */
-class Filter
-{
-    /**
-     * Converts the given value to a string.
-     *
-     * This method attempts to convert the given value to a string.
-     * If the value is already a string, it returns the value as it is.
-     * If the conversion is not possible, it returns NULL.
-     *
-     * @param mixed $value The value to be converted.
-     * @return ?string Returns the string representation of the value, or null if the value is not a string.
-     */
-    public static function toString(mixed $value): ?string
-    {
-        if (is_string($value)) {
-            return $value;
-        }
-        if (is_int($value)) {
-            return (string)$value;
-        }
-        if (is_bool($value)) {
-            return $value ? '1' : '0';
-        }
-        if (is_float($value)) {
-            if (is_nan($value) || is_infinite($value)) {
-                return null;
-            }
-            try {
-                $return = json_encode($value, JSON_THROW_ON_ERROR);
-            } catch (JsonException) {
-                $return = null;
-            }
-
-            if ($return === null || str_contains($return, 'e')) {
-                $return = rtrim(sprintf('%.' . (PHP_FLOAT_DIG + 3) . 'F', $value), '.0');
-            }
-
-            return $return;
-        }
-        if ($value instanceof Stringable) {
-            return (string)$value;
-        }
-
-        return null;
-    }
-
-    /**
-     * Converts a value to an integer.
-     *
-     * This method attempts to convert the given value to an integer.
-     * If the conversion is successful, it returns the value as an integer.
-     * If the conversion fails, it returns NULL.
-     *
-     * String values are trimmed using trim().
-     *
-     * @param mixed $value The value to be converted to an integer.
-     * @return int|null Returns the converted integer value or null if the conversion fails.
-     */
-    public static function toInt(mixed $value): ?int
-    {
-        if (is_int($value)) {
-            return $value;
-        }
-        if (is_string($value)) {
-            $value = filter_var($value, FILTER_VALIDATE_INT, FILTER_NULL_ON_FAILURE);
-
-            return $value === PHP_INT_MIN ? null : $value;
-        }
-        if (is_float($value)) {
-            /**
-             * @link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_SAFE_INTEGER
-             * 9007199254740991 = 2^53-1 = the maximum safe integer that can be represented without losing precision.
-             * Beyond this numerical limit, the equality (int)9007199254740993.0 === 9007199254740992 returns true.
-             */
-            if ($value >= -9007199254740991 && $value <= 9007199254740991) {
-                return (int)$value;
-            }
-
-            return null;
-        }
-        if (is_bool($value)) {
-            return (int)$value;
-        }
-
-        return null;
-    }
-
-    /**
-     * Converts a value to boolean.
-     *
-     *  1 | '1' | 1.0 | true  - values returns as true
-     *  0 | '0' | 0.0 | false - values returns as false
-     *  Other values returns as null.
-     *
-     * @param mixed $value The value to convert to boolean.
-     * @return bool|null Returns true if the value is truthy, false if it's falsy, or NULL otherwise.
-     */
-    public static function toBool(mixed $value): ?bool
-    {
-        if ($value === '1' || $value === 1 || $value === 1.0 || $value === true) {
-            return true;
-        }
-        if ($value === '0' || $value === 0 || $value === 0.0 || $value === false) {
-            return false;
-        }
-
-        return null;
-    }
-}

+ 24 - 1
tests/TestCase/Core/FunctionsGlobalTest.php

@@ -20,7 +20,6 @@ use Cake\Core\Configure;
 use Cake\Http\Response;
 use Cake\TestSuite\TestCase;
 use stdClass;
-use function env;
 
 require_once CAKE . 'Core/functions_global.php';
 
@@ -338,4 +337,28 @@ class FunctionsGlobalTest extends TestCase
             $this->assertTrue(true);
         });
     }
+
+    /**
+     * @dataProvider \Cake\Test\TestCase\Core\FunctionsTest::toStringProvider
+     */
+    public function testToString(mixed $rawValue, ?string $expected): void
+    {
+        $this->assertSame($expected, toString($rawValue));
+    }
+
+    /**
+     * @dataProvider \Cake\Test\TestCase\Core\FunctionsTest::toIntProvider
+     */
+    public function testToInt(mixed $rawValue, null|int $expected): void
+    {
+        $this->assertSame($expected, toInt($rawValue));
+    }
+
+    /**
+     * @dataProvider \Cake\Test\TestCase\Core\FunctionsTest::toBoolProvider
+     */
+    public function testToBool(mixed $rawValue, ?bool $expected): void
+    {
+        $this->assertSame($expected, toBool($rawValue));
+    }
 }

+ 206 - 0
tests/TestCase/Core/FunctionsTest.php

@@ -18,6 +18,7 @@ namespace Cake\Test\TestCase\Core;
 
 use Cake\Core\Configure;
 use Cake\Http\Response;
+use Cake\ORM\Entity;
 use Cake\TestSuite\TestCase;
 use stdClass;
 use function Cake\Core\deprecationWarning;
@@ -25,6 +26,9 @@ use function Cake\Core\env;
 use function Cake\Core\h;
 use function Cake\Core\namespaceSplit;
 use function Cake\Core\pluginSplit;
+use function Cake\Core\toBool;
+use function Cake\Core\toInt;
+use function Cake\Core\toString;
 use function Cake\Core\triggerWarning;
 
 /**
@@ -346,4 +350,206 @@ class FunctionsTest extends TestCase
             $this->assertTrue(true);
         });
     }
+
+    /**
+     * @dataProvider toStringProvider
+     */
+    public function testToString(mixed $rawValue, ?string $expected): void
+    {
+        $this->assertSame($expected, toString($rawValue));
+    }
+
+    /**
+     * @return array The array of test cases.
+     */
+    public static function toStringProvider(): array
+    {
+        return [
+            // input like string
+            '(string) empty' => ['', ''],
+            '(string) space' => [' ', ' '],
+            '(string) dash' => ['-', '-'],
+            '(string) zero' => ['0', '0'],
+            '(string) number' => ['55', '55'],
+            '(string) partially2 number' => ['5x', '5x'],
+            // input like int
+            '(int) number' => [55, '55'],
+            '(int) negative number' => [-5, '-5'],
+            '(int) PHP_INT_MAX + 2' => [9223372036854775809, '9223372036854775808'], //is float: see IEEE 754
+            '(int) PHP_INT_MAX + 1' => [9223372036854775808, '9223372036854775808'], //is float: see IEEE 754
+            '(int) PHP_INT_MAX + 0' => [9223372036854775807, '9223372036854775807'],
+            '(int) PHP_INT_MAX - 1' => [9223372036854775806, '9223372036854775806'],
+            '(int) PHP_INT_MIN + 1' => [-9223372036854775807, '-9223372036854775807'],
+            '(int) PHP_INT_MIN + 0' => [-9223372036854775808, '-9223372036854775808'],
+            '(int) PHP_INT_MIN - 1' => [-9223372036854775809, '-9223372036854775808'], //is float: see IEEE 754
+            '(int) PHP_INT_MIN - 2' => [-9223372036854775810, '-9223372036854775808'], //is float: see IEEE 754
+            // input like float
+            '(float) zero' => [0.0, '0'],
+            '(float) positive' => [5.5, '5.5'],
+            '(float) round' => [5.0, '5'],
+            '(float) negative' => [-5.5, '-5.5'],
+            '(float) round negative' => [-5.0, '-5'],
+            '(float) small' => [0.000000000003, '0.000000000003'],
+            '(float) small2' => [64321.0000003, '64321.0000003'],
+            '(float) fractions' => [-9223372036778.2233, '-9223372036778.223'], //is float: see IEEE 754
+            '(float) NaN' => [acos(8), null],
+            '(float) INF' => [INF, null],
+            '(float) -INF' => [-INF, null],
+            // boolean input types
+            '(bool) true' => [true, '1'],
+            '(bool) false' => [false, '0'],
+            // other input types
+            '(other) null' => [null, null],
+            '(other) empty-array' => [[], null],
+            '(other) int-array' => [[5], null],
+            '(other) string-array' => [['5'], null],
+            '(other) simple object' => [new stdClass(), null],
+            '(other) Stringable object' => [new Entity(), '[]'],
+        ];
+    }
+
+    /**
+     * @dataProvider toIntProvider
+     */
+    public function testToInt(mixed $rawValue, null|int $expected): void
+    {
+        $this->assertSame($expected, toInt($rawValue));
+    }
+
+    /**
+     * @return array The array of test cases.
+     */
+    public static function toIntProvider(): array
+    {
+        return [
+            // string input types
+            '(string) empty' => ['', null],
+            '(string) space' => [' ', null],
+            '(string) null' => ['null', null],
+            '(string) dash' => ['-', null],
+            '(string) ctz' => ['čťž', null],
+            '(string) hex' => ['0x539', null],
+            '(string) binary' => ['0b10100111001', null],
+            '(string) scientific e' => ['1.2e+2', null],
+            '(string) scientific E' => ['1.2E+2', null],
+            '(string) octal old' => ['0123', null],
+            '(string) octal new' => ['0o123', null],
+            '(string) decimal php74' => ['1_234_567', null],
+            '(string) zero' => ['0', 0],
+            '(string) number' => ['55', 55],
+            '(string) number_space_before' => [' 55', 55],
+            '(string) number_space_after' => ['55 ', 55],
+            '(string) negative number' => ['-5', -5],
+            '(string) float round' => ['5.0', null],
+            '(string) float round negative' => ['-5.0', null],
+            '(string) float real' => ['5.1', null],
+            '(string) float round slovak' => ['5,0', null],
+            '(string) money' => ['5 €', null],
+            '(string) PHP_INT_MAX + 1' => ['9223372036854775808', null],
+            '(string) PHP_INT_MAX + 0' => ['9223372036854775807', 9223372036854775807],
+            '(string) PHP_INT_MAX - 1' => ['9223372036854775806', 9223372036854775806],
+            '(string) PHP_INT_MIN + 1' => ['-9223372036854775807', -9223372036854775807],
+            '(string) PHP_INT_MIN + 0' => ['-9223372036854775808', null],
+            '(string) PHP_INT_MIN - 1' => ['-9223372036854775809', null],
+            '(string) string' => ['f', null],
+            '(string) partially1 number' => ['5 5', null],
+            '(string) partially2 number' => ['5x', null],
+            '(string) partially3 number' => ['x4', null],
+            '(string) double dot' => ['5.1.0', null],
+            // int input types
+            '(int) number' => [55, 55],
+            '(int) negative number' => [-5, -5],
+            '(int) PHP_INT_MAX + 1' => [9223372036854775808, null],
+            '(int) PHP_INT_MAX + 0' => [9223372036854775807, 9223372036854775807],
+            '(int) PHP_INT_MAX - 1' => [9223372036854775806, 9223372036854775806],
+            '(int) PHP_INT_MIN + 1' => [-9223372036854775807, -9223372036854775807],
+            // PHP_INT_MIN is float -> PHP inconsistency https://bugs.php.net/bug.php?id=53934
+            '(int) PHP_INT_MIN + 0' => [-9223372036854775808, null],
+            '(int) PHP_INT_MIN - 1' => [-9223372036854775809, null],
+            // float input types
+            '(float) zero' => [0.0, 0],
+            '(float) positive' => [5.5, 5],
+            '(float) round' => [5.0, 5],
+            '(float) negative' => [-5.5, -5],
+            '(float) round negative' => [-5.0, -5],
+            '(float) PHP_INT_MAX + 1' => [9223372036854775808.0, null],
+            '(float) PHP_INT_MAX + 0' => [9223372036854775807.0, null],
+            '(float) PHP_INT_MAX - 1' => [9223372036854775806.0, null],
+            '(float) PHP_INT_MIN + 1' => [-9223372036854775807.0, null],
+            '(float) PHP_INT_MIN + 0' => [-9223372036854775808.0, null],
+            '(float) PHP_INT_MIN - 1' => [-9223372036854775809.0, null],
+            '(float) 2^53 + 2' => [9007199254740994.0, null],
+            '(float) 2^53 + 1' => [9007199254740993.0, null],
+            '(float) 2^53 + 0' => [9007199254740992.0, null],
+            '(float) 2^53 - 1' => [9007199254740991.0, 9007199254740991],
+            '(float) 2^53 - 2' => [9007199254740990.0, 9007199254740990],
+            '(float) -(2^53) + 2' => [-9007199254740990.0, -9007199254740990],
+            '(float) -(2^53) + 1' => [-9007199254740991.0, -9007199254740991],
+            '(float) -(2^53) + 0' => [-9007199254740992.0, null],
+            '(float) -(2^53) - 1' => [-9007199254740992.0, null],
+            '(float) -(2^53) - 2' => [-9007199254740994.0, null],
+            '(float) NaN' => [acos(8), null],
+            '(float) INF' => [INF, null],
+            '(float) -INF' => [-INF, null],
+            // boolean input types
+            '(bool) true' => [true, 1],
+            '(bool) false' => [false, 0],
+            // other input types
+            '(other) null' => [null, null],
+            '(other) empty-array' => [[], null],
+            '(other) int-array' => [[5], null],
+            '(other) string-array' => [['5'], null],
+            '(other) simple object' => [new stdClass(), null],
+        ];
+    }
+
+    /**
+     * @dataProvider toBoolProvider
+     */
+    public function testToBool(mixed $rawValue, ?bool $expected): void
+    {
+        $this->assertSame($expected, toBool($rawValue));
+    }
+
+    /**
+     * @return array The array of test cases.
+     */
+    public static function toBoolProvider(): array
+    {
+        return [
+            // string input types
+            '(string) empty string' => ['', null],
+            '(string) space' => [' ', null],
+            '(string) some word' => ['abc', null],
+            '(string) double 0' => ['00', null],
+            '(string) single 0' => ['0', false],
+            '(string) false' => ['false', null],
+            '(string) double 1' => ['11', null],
+            '(string) single 1' => ['1', true],
+            '(string) true-string' => ['true', null],
+            // int input types
+            '(int) 0' => [0, false],
+            '(int) 1' => [1, true],
+            '(int) -1' => [-1, null],
+            '(int) 55' => [55, null],
+            '(int) negative number' => [-5, null],
+            // float input types
+            '(float) positive' => [5.5, null],
+            '(float) round' => [5.0, null],
+            '(float) 0.0' => [0.0, false],
+            '(float) 1.0' => [1.0, true],
+            '(float) NaN' => [acos(8), null],
+            '(float) INF' => [INF, null],
+            '(float) -INF' => [-INF, null],
+            // boolean input types
+            '(bool) true' => [true, true],
+            '(bool) false' => [false, false],
+            // other input types
+            '(other) null' => [null, null],
+            '(other) empty-array' => [[], null],
+            '(other) int-array' => [[5], null],
+            '(other) string-array' => [['5'], null],
+            '(other) simple object' => [new stdClass(), null],
+        ];
+    }
 }

+ 0 - 228
tests/TestCase/Utility/FilterTest.php

@@ -1,228 +0,0 @@
-<?php
-declare(strict_types=1);
-
-/**
- * CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
- * Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
- *
- * Licensed under The MIT License
- * For full copyright and license information, please see the LICENSE.txt
- * Redistributions of files must retain the above copyright notice.
- *
- * @copyright     Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
- * @link          https://cakephp.org CakePHP(tm) Project
- * @since         5.1.0
- * @license       https://opensource.org/licenses/mit-license.php MIT License
- */
-
-namespace Cake\Test\TestCase\Utility;
-
-use Cake\ORM\Entity;
-use Cake\Utility\Filter;
-use PHPUnit\Framework\TestCase;
-use stdClass;
-
-class FilterTest extends TestCase
-{
-    /**
-     * @dataProvider toStringProvider
-     */
-    public function testToString(mixed $rawValue, ?string $expected): void
-    {
-        $this->assertSame($expected, Filter::toString($rawValue));
-    }
-
-    /**
-     * @return array The array of test cases.
-     */
-    public static function toStringProvider(): array
-    {
-        return [
-            // input like string
-            '(string) empty' => ['', ''],
-            '(string) space' => [' ', ' '],
-            '(string) dash' => ['-', '-'],
-            '(string) zero' => ['0', '0'],
-            '(string) number' => ['55', '55'],
-            '(string) partially2 number' => ['5x', '5x'],
-            // input like int
-            '(int) number' => [55, '55'],
-            '(int) negative number' => [-5, '-5'],
-            '(int) PHP_INT_MAX + 2' => [9223372036854775809, '9223372036854775808'], //is float: see IEEE 754
-            '(int) PHP_INT_MAX + 1' => [9223372036854775808, '9223372036854775808'], //is float: see IEEE 754
-            '(int) PHP_INT_MAX + 0' => [9223372036854775807, '9223372036854775807'],
-            '(int) PHP_INT_MAX - 1' => [9223372036854775806, '9223372036854775806'],
-            '(int) PHP_INT_MIN + 1' => [-9223372036854775807, '-9223372036854775807'],
-            '(int) PHP_INT_MIN + 0' => [-9223372036854775808, '-9223372036854775808'],
-            '(int) PHP_INT_MIN - 1' => [-9223372036854775809, '-9223372036854775808'], //is float: see IEEE 754
-            '(int) PHP_INT_MIN - 2' => [-9223372036854775810, '-9223372036854775808'], //is float: see IEEE 754
-            // input like float
-            '(float) zero' => [0.0, '0'],
-            '(float) positive' => [5.5, '5.5'],
-            '(float) round' => [5.0, '5'],
-            '(float) negative' => [-5.5, '-5.5'],
-            '(float) round negative' => [-5.0, '-5'],
-            '(float) small' => [0.000000000003, '0.000000000003'],
-            '(float) small2' => [64321.0000003, '64321.0000003'],
-            '(float) fractions' => [-9223372036778.2233, '-9223372036778.223'], //is float: see IEEE 754
-            '(float) NaN' => [acos(8), null],
-            '(float) INF' => [INF, null],
-            '(float) -INF' => [-INF, null],
-            // boolean input types
-            '(bool) true' => [true, '1'],
-            '(bool) false' => [false, '0'],
-            // other input types
-            '(other) null' => [null, null],
-            '(other) empty-array' => [[], null],
-            '(other) int-array' => [[5], null],
-            '(other) string-array' => [['5'], null],
-            '(other) simple object' => [new stdClass(), null],
-            '(other) Stringable object' => [new Entity(), '[]'],
-        ];
-    }
-
-    /**
-     * @dataProvider toIntProvider
-     */
-    public function testToInt(mixed $rawValue, null|int $expected): void
-    {
-        $this->assertSame($expected, Filter::toInt($rawValue));
-    }
-
-    /**
-     * @return array The array of test cases.
-     */
-    public static function toIntProvider(): array
-    {
-        return [
-            // string input types
-            '(string) empty' => ['', null],
-            '(string) space' => [' ', null],
-            '(string) null' => ['null', null],
-            '(string) dash' => ['-', null],
-            '(string) ctz' => ['čťž', null],
-            '(string) hex' => ['0x539', null],
-            '(string) binary' => ['0b10100111001', null],
-            '(string) scientific e' => ['1.2e+2', null],
-            '(string) scientific E' => ['1.2E+2', null],
-            '(string) octal old' => ['0123', null],
-            '(string) octal new' => ['0o123', null],
-            '(string) decimal php74' => ['1_234_567', null],
-            '(string) zero' => ['0', 0],
-            '(string) number' => ['55', 55],
-            '(string) number_space_before' => [' 55', 55],
-            '(string) number_space_after' => ['55 ', 55],
-            '(string) negative number' => ['-5', -5],
-            '(string) float round' => ['5.0', null],
-            '(string) float round negative' => ['-5.0', null],
-            '(string) float real' => ['5.1', null],
-            '(string) float round slovak' => ['5,0', null],
-            '(string) money' => ['5 €', null],
-            '(string) PHP_INT_MAX + 1' => ['9223372036854775808', null],
-            '(string) PHP_INT_MAX + 0' => ['9223372036854775807', 9223372036854775807],
-            '(string) PHP_INT_MAX - 1' => ['9223372036854775806', 9223372036854775806],
-            '(string) PHP_INT_MIN + 1' => ['-9223372036854775807', -9223372036854775807],
-            '(string) PHP_INT_MIN + 0' => ['-9223372036854775808', null],
-            '(string) PHP_INT_MIN - 1' => ['-9223372036854775809', null],
-            '(string) string' => ['f', null],
-            '(string) partially1 number' => ['5 5', null],
-            '(string) partially2 number' => ['5x', null],
-            '(string) partially3 number' => ['x4', null],
-            '(string) double dot' => ['5.1.0', null],
-            // int input types
-            '(int) number' => [55, 55],
-            '(int) negative number' => [-5, -5],
-            '(int) PHP_INT_MAX + 1' => [9223372036854775808, null],
-            '(int) PHP_INT_MAX + 0' => [9223372036854775807, 9223372036854775807],
-            '(int) PHP_INT_MAX - 1' => [9223372036854775806, 9223372036854775806],
-            '(int) PHP_INT_MIN + 1' => [-9223372036854775807, -9223372036854775807],
-            // PHP_INT_MIN is float -> PHP inconsistency https://bugs.php.net/bug.php?id=53934
-            '(int) PHP_INT_MIN + 0' => [-9223372036854775808, null],
-            '(int) PHP_INT_MIN - 1' => [-9223372036854775809, null],
-            // float input types
-            '(float) zero' => [0.0, 0],
-            '(float) positive' => [5.5, 5],
-            '(float) round' => [5.0, 5],
-            '(float) negative' => [-5.5, -5],
-            '(float) round negative' => [-5.0, -5],
-            '(float) PHP_INT_MAX + 1' => [9223372036854775808.0, null],
-            '(float) PHP_INT_MAX + 0' => [9223372036854775807.0, null],
-            '(float) PHP_INT_MAX - 1' => [9223372036854775806.0, null],
-            '(float) PHP_INT_MIN + 1' => [-9223372036854775807.0, null],
-            '(float) PHP_INT_MIN + 0' => [-9223372036854775808.0, null],
-            '(float) PHP_INT_MIN - 1' => [-9223372036854775809.0, null],
-            '(float) 2^53 + 2' => [9007199254740994.0, null],
-            '(float) 2^53 + 1' => [9007199254740993.0, null],
-            '(float) 2^53 + 0' => [9007199254740992.0, null],
-            '(float) 2^53 - 1' => [9007199254740991.0, 9007199254740991],
-            '(float) 2^53 - 2' => [9007199254740990.0, 9007199254740990],
-            '(float) -(2^53) + 2' => [-9007199254740990.0, -9007199254740990],
-            '(float) -(2^53) + 1' => [-9007199254740991.0, -9007199254740991],
-            '(float) -(2^53) + 0' => [-9007199254740992.0, null],
-            '(float) -(2^53) - 1' => [-9007199254740992.0, null],
-            '(float) -(2^53) - 2' => [-9007199254740994.0, null],
-            '(float) NaN' => [acos(8), null],
-            '(float) INF' => [INF, null],
-            '(float) -INF' => [-INF, null],
-            // boolean input types
-            '(bool) true' => [true, 1],
-            '(bool) false' => [false, 0],
-            // other input types
-            '(other) null' => [null, null],
-            '(other) empty-array' => [[], null],
-            '(other) int-array' => [[5], null],
-            '(other) string-array' => [['5'], null],
-            '(other) simple object' => [new stdClass(), null],
-        ];
-    }
-
-    /**
-     * @dataProvider toBoolProvider
-     */
-    public function testToBool(mixed $rawValue, ?bool $expected): void
-    {
-        $this->assertSame($expected, Filter::toBool($rawValue));
-    }
-
-    /**
-     * @return array The array of test cases.
-     */
-    public static function toBoolProvider(): array
-    {
-        return [
-            // string input types
-            '(string) empty string' => ['', null],
-            '(string) space' => [' ', null],
-            '(string) some word' => ['abc', null],
-            '(string) double 0' => ['00', null],
-            '(string) single 0' => ['0', false],
-            '(string) false' => ['false', null],
-            '(string) double 1' => ['11', null],
-            '(string) single 1' => ['1', true],
-            '(string) true-string' => ['true', null],
-            // int input types
-            '(int) 0' => [0, false],
-            '(int) 1' => [1, true],
-            '(int) -1' => [-1, null],
-            '(int) 55' => [55, null],
-            '(int) negative number' => [-5, null],
-            // float input types
-            '(float) positive' => [5.5, null],
-            '(float) round' => [5.0, null],
-            '(float) 0.0' => [0.0, false],
-            '(float) 1.0' => [1.0, true],
-            '(float) NaN' => [acos(8), null],
-            '(float) INF' => [INF, null],
-            '(float) -INF' => [-INF, null],
-            // boolean input types
-            '(bool) true' => [true, true],
-            '(bool) false' => [false, false],
-            // other input types
-            '(other) null' => [null, null],
-            '(other) empty-array' => [[], null],
-            '(other) int-array' => [[5], null],
-            '(other) string-array' => [['5'], null],
-            '(other) simple object' => [new stdClass(), null],
-        ];
-    }
-}