From 80c681951c49b233d6ac7b697a2495852451e37f Mon Sep 17 00:00:00 2001 From: Eric Mann Date: Tue, 3 Dec 2024 11:47:01 -0800 Subject: [PATCH] Fix Linting Error with ```set_time()` According to the linter: > Method name "Two_Factor_Totp::__set_time" is discouraged; PHP has reserved all method names with a double underscore prefix for future use. Rename the function to make the linter happy. --- providers/class-two-factor-totp.php | 2 +- tests/providers/class-two-factor-totp.php | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/providers/class-two-factor-totp.php b/providers/class-two-factor-totp.php index 1a418121..c40b8dc5 100644 --- a/providers/class-two-factor-totp.php +++ b/providers/class-two-factor-totp.php @@ -72,7 +72,7 @@ private static function time() { * * @param int $now Timestamp to use when overriding time(). */ - public static function __set_time( $now ) { + public static function set_time( $now ) { self::$now = $now; } diff --git a/tests/providers/class-two-factor-totp.php b/tests/providers/class-two-factor-totp.php index 202f5e35..909e52c7 100644 --- a/tests/providers/class-two-factor-totp.php +++ b/tests/providers/class-two-factor-totp.php @@ -343,7 +343,7 @@ public function test_sha1_generate() { $token = $provider->base32_encode( self::$token ); foreach (self::$vectors as $time => $vector) { - $provider::__set_time( (int) $time ); + $provider::set_time( (int) $time ); $this->assertEquals( $vector[0], $provider::calc_totp( $token, false, 8, $hash, self::$step ) ); $this->assertEquals( substr( $vector[0], 2 ), $provider::calc_totp( $token, false, 6, $hash, self::$step ) ); } @@ -363,7 +363,7 @@ public function test_sha1_authenticate() { $token = $provider->base32_encode( self::$token ); foreach ( self::$vectors as $time => $vector ) { - $provider::__set_time( (int) $time ); + $provider::set_time( (int) $time ); $this->assertTrue( $provider::is_valid_authcode( $token, $vector[0], $hash ) ); $this->assertTrue( $provider::is_valid_authcode( $token, substr( $vector[0], 2 ), $hash ) ); } @@ -382,7 +382,7 @@ public function test_sha256_generate() { $token = $provider->base32_encode( self::$token ); foreach ( self::$vectors as $time => $vector ) { - $provider::__set_time( (int) $time ); + $provider::set_time( (int) $time ); $this->assertEquals( $vector[1], $provider::calc_totp( $token, false, 8, $hash, self::$step ) ); $this->assertEquals( substr( $vector[1], 2 ), $provider::calc_totp( $token, false, 6, $hash, self::$step ) ); } @@ -402,7 +402,7 @@ public function test_sha256_authenticate() { $token = $provider->base32_encode( self::$token ); foreach ( self::$vectors as $time => $vector ) { - $provider::__set_time( (int) $time ); + $provider::set_time( (int) $time ); $this->assertTrue( $provider::is_valid_authcode( $token, $vector[1], $hash ) ); $this->assertTrue( $provider::is_valid_authcode( $token, substr( $vector[1], 2 ), $hash ) ); } @@ -421,7 +421,7 @@ public function test_sha512_generate() { $token = $provider->base32_encode( self::$token ); foreach ( self::$vectors as $time => $vector ) { - $provider::__set_time( (int) $time ); + $provider::set_time( (int) $time ); $this->assertEquals( $vector[2], $provider::calc_totp( $token, false, 8, $hash, self::$step ) ); $this->assertEquals( substr($vector[2], 2 ), $provider::calc_totp( $token, false, 6, $hash, self::$step ) ); } @@ -441,7 +441,7 @@ public function test_sha512_authenticate() { $token = $provider->base32_encode( self::$token ); foreach ( self::$vectors as $time => $vector ) { - $provider::__set_time( (int) $time ); + $provider::set_time( (int) $time ); $this->assertTrue( $provider::is_valid_authcode( $token, $vector[2], $hash ) ); $this->assertTrue( $provider::is_valid_authcode( $token, substr( $vector[2], 2 ), $hash ) ); }