Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
90.91% |
10 / 11 |
|
88.89% |
8 / 9 |
CRAP | |
0.00% |
0 / 1 |
| OATHAuthServices | |
90.91% |
10 / 11 |
|
88.89% |
8 / 9 |
9.06 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getInstance | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
| getEncryptionHelper | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getExpiringRecoveryCodeGenerator | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getLogger | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getMandatory2FAChecker | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getModuleRegistry | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getUserRepository | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getWebAuthnAuthenticator | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * @license GPL-2.0-or-later |
| 4 | * |
| 5 | * @file |
| 6 | */ |
| 7 | |
| 8 | namespace MediaWiki\Extension\OATHAuth; |
| 9 | |
| 10 | use MediaWiki\Extension\OATHAuth\Enforce2FA\Mandatory2FAChecker; |
| 11 | use MediaWiki\Extension\OATHAuth\Key\EncryptionHelper; |
| 12 | use MediaWiki\MediaWikiServices; |
| 13 | |
| 14 | /** |
| 15 | * Type-safe wrapper for accessing OATHAuth services. |
| 16 | * |
| 17 | * @author Taavi Väänänen <hi@taavi.wtf> |
| 18 | */ |
| 19 | class OATHAuthServices { |
| 20 | public function __construct( private readonly MediaWikiServices $services ) { |
| 21 | } |
| 22 | |
| 23 | public static function getInstance( ?MediaWikiServices $services = null ): self { |
| 24 | return new self( |
| 25 | $services ?? MediaWikiServices::getInstance(), |
| 26 | ); |
| 27 | } |
| 28 | |
| 29 | public function getEncryptionHelper(): EncryptionHelper { |
| 30 | return $this->services->getService( 'OATHAuth.EncryptionHelper' ); |
| 31 | } |
| 32 | |
| 33 | public function getExpiringRecoveryCodeGenerator(): ExpiringRecoveryCodeGenerator { |
| 34 | return $this->services->getService( 'OATHAuth.ExpiringRecoveryCodeGenerator' ); |
| 35 | } |
| 36 | |
| 37 | public function getLogger(): OATHAuthLogger { |
| 38 | return $this->services->getService( 'OATHAuth.Logger' ); |
| 39 | } |
| 40 | |
| 41 | public function getMandatory2FAChecker(): Mandatory2FAChecker { |
| 42 | return $this->services->getService( 'OATHAuth.Mandatory2FAChecker' ); |
| 43 | } |
| 44 | |
| 45 | public function getModuleRegistry(): OATHAuthModuleRegistry { |
| 46 | return $this->services->getService( 'OATHAuth.ModuleRegistry' ); |
| 47 | } |
| 48 | |
| 49 | public function getUserRepository(): OATHUserRepository { |
| 50 | return $this->services->getService( 'OATHAuth.UserRepository' ); |
| 51 | } |
| 52 | |
| 53 | public function getWebAuthnAuthenticator(): WebAuthnAuthenticator { |
| 54 | return $this->services->getService( 'OATHAuth.WebAuthnAuthenticator' ); |
| 55 | } |
| 56 | } |