From ba20453651010afc3951427d06f13c932af006ce Mon Sep 17 00:00:00 2001 From: Damiano Improta Date: Wed, 10 Dec 2025 16:35:26 +0100 Subject: [PATCH] filter_input -> filter_var --- ...ffectivePrimitiveTypeIdentifierService.php | 23 ++++++++----------- tests/EffectivePrimitiveTypeTest.php | 2 +- 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/src/Service/EffectivePrimitiveTypeIdentifierService.php b/src/Service/EffectivePrimitiveTypeIdentifierService.php index cd0dc66..81bfdc1 100644 --- a/src/Service/EffectivePrimitiveTypeIdentifierService.php +++ b/src/Service/EffectivePrimitiveTypeIdentifierService.php @@ -27,6 +27,7 @@ */ final class EffectivePrimitiveTypeIdentifierService { + /** *

Returns strict effective primitive type of a variable

. * @@ -93,9 +94,7 @@ public function getTypedValueFromArray($needle, $array, $trim = false, $forceStr */ public function getTypedValueFromPost($needle, $trim = false, $forceString = false, $sanitizeHtml = false) { - $inputPost = filter_input(INPUT_POST, $needle, FILTER_NULL_ON_FAILURE); - - return $this->getTypedValue($inputPost, $trim, $forceString, $sanitizeHtml); + return array_key_exists($needle, $_POST) ? $this->getTypedValue(filter_var($_POST[$needle], FILTER_NULL_ON_FAILURE), $trim, $forceString, $sanitizeHtml) : null; } /** @@ -110,9 +109,7 @@ public function getTypedValueFromPost($needle, $trim = false, $forceString = fal */ public function getTypedValueFromServer($needle, $trim = false, $forceString = false, $sanitizeHtml = false) { - $inputPost = filter_input(INPUT_SERVER, $needle, FILTER_NULL_ON_FAILURE); - - return $this->getTypedValue($inputPost, $trim, $forceString, $sanitizeHtml); + return array_key_exists($needle, $_SERVER) ? $this->getTypedValue(filter_var($_SERVER[$needle], FILTER_NULL_ON_FAILURE), $trim, $forceString, $sanitizeHtml) : null; } /** @@ -127,9 +124,7 @@ public function getTypedValueFromServer($needle, $trim = false, $forceString = f */ public function getTypedValueFromGet($needle, $trim = false, $forceString = false, $sanitizeHtml = false) { - $inputGet = filter_input(INPUT_GET, $needle, FILTER_NULL_ON_FAILURE); - - return $this->getTypedValue($inputGet, $trim, $forceString, $sanitizeHtml); + return array_key_exists($needle, $_GET) ? $this->getTypedValue(filter_var($_GET[$needle], FILTER_NULL_ON_FAILURE), $trim, $forceString, $sanitizeHtml) : null; } /** @@ -210,10 +205,10 @@ private function getSanitizedString($value, $trim = false, $sanitizeHtml = false private function sanitizeHtml($string) { $stringFiltered = (string) filter_var( - $string, - FILTER_UNSAFE_RAW, - FILTER_NULL_ON_FAILURE | FILTER_FLAG_STRIP_LOW | FILTER_FLAG_STRIP_HIGH | FILTER_FLAG_STRIP_BACKTICK - ); + $string, + FILTER_UNSAFE_RAW, + FILTER_NULL_ON_FAILURE | FILTER_FLAG_STRIP_LOW | FILTER_FLAG_STRIP_HIGH | FILTER_FLAG_STRIP_BACKTICK + ); $stringStripped = strip_tags($stringFiltered); $stringDecoded = html_entity_decode($stringStripped); $pattern = [ @@ -230,4 +225,4 @@ private function sanitizeHtml($string) return (string) preg_replace($pattern, $replacement, $stringDecoded); } -} +} \ No newline at end of file diff --git a/tests/EffectivePrimitiveTypeTest.php b/tests/EffectivePrimitiveTypeTest.php index af1abc7..0c45db8 100644 --- a/tests/EffectivePrimitiveTypeTest.php +++ b/tests/EffectivePrimitiveTypeTest.php @@ -285,9 +285,9 @@ public function testAssociativeArraySantizieMethod(): void $array['value'] = $value; $ept = new EffectivePrimitiveTypeIdentifierService(); $result = $ept->getTypedValueFromArray('value', $array); + $this->assertIsString($result); $this->assertTrue($array['value'] === $result); $this->assertEquals($array['value'], $result); - $this->assertIsString($result); } public function testAssociativeArraySantizieWitTrimMethod(): void