From 64bd4601b4679be804c82bd910fe91909073d2fa Mon Sep 17 00:00:00 2001 From: Sam Smith Date: Fri, 28 Feb 2020 17:26:35 +0000 Subject: [PATCH] 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 --- includes/FeatureManagement/FeatureManager.php | 11 +++++------ .../unit/FeatureManagement/FeatureManagerTest.php | 10 ---------- 2 files changed, 5 insertions(+), 16 deletions(-) diff --git a/includes/FeatureManagement/FeatureManager.php b/includes/FeatureManagement/FeatureManager.php index c7f4ca9..0f250de 100644 --- a/includes/FeatureManagement/FeatureManager.php +++ b/includes/FeatureManagement/FeatureManager.php @@ -1,4 +1,5 @@ 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." ); } diff --git a/tests/phpunit/unit/FeatureManagement/FeatureManagerTest.php b/tests/phpunit/unit/FeatureManagement/FeatureManagerTest.php index 22f1420..ff613d3 100644 --- a/tests/phpunit/unit/FeatureManagement/FeatureManagerTest.php +++ b/tests/phpunit/unit/FeatureManagement/FeatureManagerTest.php @@ -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 [