mirror of
https://gerrit.wikimedia.org/r/mediawiki/skins/Vector.git
synced 2024-11-23 23:33:54 +00:00
featureManager: Add typehints
I735fd640 bumped the required MediaWiki version to 1.31. That version dropped support for PHP 5.x. Wherever possible, update FeatureManager's methods to use PHP 7.0.x's scalar and return type declarations. Bug: T244481 Change-Id: Ib5636d0ec5ec7f0c93b5b3317a12635668b589e2
This commit is contained in:
parent
e9d9949048
commit
64bd4601b4
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
@ -91,7 +92,7 @@ final class FeatureManager {
|
|||
* @throws \InvalidArgumentException If the feature references a requirement that isn't
|
||||
* registered
|
||||
*/
|
||||
public function registerFeature( $feature, $requirements ) {
|
||||
public function registerFeature( string $feature, $requirements ) {
|
||||
//
|
||||
// Validation
|
||||
if ( array_key_exists( $feature, $this->features ) ) {
|
||||
|
@ -129,7 +130,7 @@ final class FeatureManager {
|
|||
*
|
||||
* @throws \InvalidArgumentException If the feature isn't registered
|
||||
*/
|
||||
public function isFeatureEnabled( $feature ) {
|
||||
public function isFeatureEnabled( string $feature ) : bool {
|
||||
if ( !array_key_exists( $feature, $this->features ) ) {
|
||||
throw new \InvalidArgumentException( "The feature \"{$feature}\" isn't registered." );
|
||||
}
|
||||
|
@ -161,13 +162,11 @@ final class FeatureManager {
|
|||
*
|
||||
* @throws \LogicException If the requirement has already been registered
|
||||
*/
|
||||
public function registerRequirement( $name, $isMet ) {
|
||||
public function registerRequirement( string $name, bool $isMet ) {
|
||||
if ( array_key_exists( $name, $this->requirements ) ) {
|
||||
throw new \LogicException( "The requirement \"{$name}\" is already registered." );
|
||||
}
|
||||
|
||||
Assert::parameterType( 'boolean', $isMet, 'isMet' );
|
||||
|
||||
$this->requirements[$name] = $isMet;
|
||||
}
|
||||
|
||||
|
@ -179,7 +178,7 @@ final class FeatureManager {
|
|||
*
|
||||
* @throws \InvalidArgumentException If the requirement isn't registered
|
||||
*/
|
||||
public function isRequirementMet( $name ) {
|
||||
public function isRequirementMet( string $name ) : bool {
|
||||
if ( !array_key_exists( $name, $this->requirements ) ) {
|
||||
throw new \InvalidArgumentException( "Requirement \"{$name}\" isn't registered." );
|
||||
}
|
||||
|
|
|
@ -41,16 +41,6 @@ class FeatureManagerTest extends \MediaWikiUnitTestCase {
|
|||
$featureManager->registerRequirement( 'requirementA', true );
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::registerRequirement
|
||||
*/
|
||||
public function testRegisterRequirementValidatesIsEnabled() {
|
||||
$this->expectException( \Wikimedia\Assert\ParameterAssertionException::class );
|
||||
|
||||
$featureManager = new FeatureManager();
|
||||
$featureManager->registerRequirement( 'requirementA', 'foo' );
|
||||
}
|
||||
|
||||
public static function provideInvalidFeatureConfig() {
|
||||
return [
|
||||
|
||||
|
|
Loading…
Reference in a new issue