@@ -34,7 +34,6 @@ class Authenticator{
3434 /** @var \chillerlan\Settings\SettingsContainerInterface|\chillerlan\Authenticator\AuthenticatorOptions */
3535 protected SettingsContainerInterface $ options ;
3636 protected AuthenticatorInterface $ authenticator ;
37- protected string $ mode = AuthenticatorInterface::TOTP ;
3837
3938 /**
4039 * Authenticator constructor
@@ -59,14 +58,11 @@ public function setOptions(SettingsContainerInterface $options):self{
5958 $ this ->options = $ options ;
6059
6160 // invoke a new authenticator interface if necessary
62- if (!isset ($ this ->authenticator ) || $ this ->options -> mode !== $ this ->mode ){
61+ if (!isset ($ this ->authenticator ) || $ this ->authenticator :: MODE !== $ this -> options ->mode ){
6362 $ class = AuthenticatorInterface::MODES [$ this ->options ->mode ];
64- $ this ->mode = $ this ->options ->mode ;
65- $ this ->authenticator = new $ class ;
63+ $ this ->authenticator = new $ class ($ this ->options );
6664 }
6765
68- $ this ->authenticator ->setOptions ($ this ->options );
69-
7066 return $ this ;
7167 }
7268
@@ -148,28 +144,31 @@ public function getUri(string $label, string $issuer, ?int $hotpCounter = null,
148144 'issuer ' => $ issuer ,
149145 ];
150146
151- if (($ omitSettings ?? $ this ->options ->omitUriSettings ) !== true ){
152- $ values ['digits ' ] = $ this ->options ->digits ;
153- $ values ['algorithm ' ] = $ this ->options ->algorithm ;
147+ if ($ this ->authenticator ::MODE === AuthenticatorInterface::HOTP ){
154148
155- if ($ this -> mode === AuthenticatorInterface:: TOTP ){
156- $ values [ ' period ' ] = $ this -> options -> period ;
149+ if ($ hotpCounter === null || $ hotpCounter < 0 ){
150+ throw new InvalidArgumentException ( ' initial counter value must be set and greater or equal to 0 ' ) ;
157151 }
158152
153+ $ values ['counter ' ] = $ hotpCounter ;
159154 }
160155
161- if ($ this ->mode === AuthenticatorInterface::HOTP ){
156+ if (($ omitSettings ?? $ this ->options ->omitUriSettings ) !== true ){
157+ $ values ['digits ' ] = $ this ->options ->digits ;
158+ $ values ['algorithm ' ] = $ this ->options ->algorithm ;
162159
163- if ($ hotpCounter === null || $ hotpCounter < 0 ){
164- throw new InvalidArgumentException ( ' initial counter value must be set and greater or equal to 0 ' ) ;
160+ if ($ this -> authenticator :: MODE === AuthenticatorInterface:: TOTP ){
161+ $ values [ ' period ' ] = $ this -> options -> period ;
165162 }
166163
167- $ values ['counter ' ] = $ hotpCounter ;
168164 }
169165
170- $ values = http_build_query ($ values , '' , '& ' , PHP_QUERY_RFC3986 );
171-
172- return sprintf ('otpauth://%s/%s?%s ' , $ this ->mode , rawurlencode ($ label ), $ values );
166+ return sprintf (
167+ 'otpauth://%s/%s?%s ' ,
168+ $ this ->authenticator ::MODE ,
169+ rawurlencode ($ label ),
170+ http_build_query ($ values , '' , '& ' , PHP_QUERY_RFC3986 ),
171+ );
173172 }
174173
175174}
0 commit comments