diff --git a/deploy/lib/Filter.php b/deploy/lib/Filter.php index eb6e45b4b..63288d6bd 100644 --- a/deploy/lib/Filter.php +++ b/deploy/lib/Filter.php @@ -5,8 +5,7 @@ /** * Filter & Sanitation wrappers */ -class Filter -{ +class Filter { /** * Return a casting with a result of a positive int, or else zero. * @@ -14,37 +13,31 @@ class Filter * this function will cast strings with leading integers to those integers. * E.g. 555'sql-injection becomes 555 */ - public static function toNonNegativeInt($num) - { + public static function toNonNegativeInt($num) { return ((int)$num == $num && (int)$num > 0 ? (int)$num : 0); } /** * Casts to an integer anything that can be cast that way non-destructively, otherwise null. */ - public static function toInt($dirty) - { + public static function toInt($dirty) { return $dirty == (int) $dirty ? (int) $dirty : null; // Cast anything that can be non-destructively cast. } - public static function toAlphaNumeric($dirty) - { + public static function toAlphaNumeric($dirty) { return preg_replace('/[^a-zA-Z0-9]/', '', $dirty); } - public static function toAllowableUsername($dirty) - { + public static function toAllowableUsername($dirty) { return preg_replace('/[^a-zA-Z0-9_-]/', '', $dirty); } - public static function toEmail($dirty) - { + public static function toEmail($dirty) { return filter_var($dirty, FILTER_SANITIZE_EMAIL); } - public static function stripHighUtf8($dirty) - { + public static function stripHighUtf8($dirty) { return filter_var($dirty, FILTER_UNSAFE_RAW, FILTER_FLAG_STRIP_HIGH | FILTER_FLAG_STRIP_LOW); } } diff --git a/deploy/tests/unit/environment_test.php b/deploy/tests/unit/environment_test.php index e050b36c8..cbb5c305f 100644 --- a/deploy/tests/unit/environment_test.php +++ b/deploy/tests/unit/environment_test.php @@ -9,10 +9,8 @@ /** * @group environment */ -class TestInput extends \NWTest -{ - public function setUp(): void - { +class TestInput extends \NWTest { + public function setUp(): void { parent::setUp(); $get = [ 'id' => 7, @@ -35,30 +33,26 @@ public function setUp(): void RequestWrapper::inject($request); // Pass a request to be used by tests } - public function tearDown(): void - { + public function tearDown(): void { RequestWrapper::destroy(); parent::tearDown(); } - public function testInputWithinEnvironment() - { + public function testInputWithinEnvironment() { $id = RequestWrapper::getPostOrGet('id'); $this->assertEquals(7, $id); $default_result = RequestWrapper::getPostOrGet('doesnotexist', 5); $this->assertEquals(5, $default_result); } - public function testPostWithinMockedEnvironment() - { + public function testPostWithinMockedEnvironment() { $posted = RequestWrapper::getPost('post_post_field', 'Bob'); $this->assertEquals('Bob', $posted); $default = RequestWrapper::getPost('blah_doesnt_exist', 7777); $this->assertEquals(7777, $default); } - public function testNonNegativeInt() - { + public function testNonNegativeInt() { $this->assertEquals(4, Filter::toNonNegativeInt(4)); $this->assertEquals(0, Filter::toNonNegativeInt(-4)); $this->assertEquals(0, Filter::toNonNegativeInt(4.1)); @@ -71,8 +65,7 @@ public function testNonNegativeInt() /** * */ - public function testSanitizeToInt() - { + public function testSanitizeToInt() { $this->assertEquals(4, Filter::toInt(4)); $this->assertEquals(-4, Filter::toInt(-4)); $this->assertNull(Filter::toInt(4.1)); @@ -82,8 +75,7 @@ public function testSanitizeToInt() $this->assertEquals(0, Filter::toInt(0)); } - public function testToInt() - { + public function testToInt() { $this->assertEquals(4, Filter::toInt(4)); $this->assertEquals(-4, Filter::toInt(-4)); $this->assertNull(Filter::toInt(4.1)); @@ -93,8 +85,7 @@ public function testToInt() $this->assertEquals(0, Filter::toInt(0)); } - public function testFilterStripHighUtf8() - { + public function testFilterStripHighUtf8() { $this->assertEquals('boba', Filter::stripHighUtf8("bob\0aƤ\x80")); } }