Skip to content

Commit

Permalink
Fix Linting Error with ``set_time()
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ericmann committed Dec 3, 2024
1 parent 93438be commit 80c6819
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion providers/class-two-factor-totp.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
12 changes: 6 additions & 6 deletions tests/providers/class-two-factor-totp.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) );
}
Expand All @@ -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 ) );
}
Expand All @@ -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 ) );
}
Expand All @@ -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 ) );
}
Expand All @@ -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 ) );
}
Expand All @@ -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 ) );
}
Expand Down

0 comments on commit 80c6819

Please sign in to comment.