From b3e57cbfc27cf94dba9c9561e8172fb14c89eda2 Mon Sep 17 00:00:00 2001 From: "Moritz Schubotz (physikerwelt)" Date: Tue, 22 Nov 2022 15:11:26 +0100 Subject: [PATCH] Make code using the Math.CheckerFactory service discoverable Otherwise IDEs and other tools don't know what's going on. ...->getService() returns mixed. Change-Id: If0429485941c19eb0e88896cb1ada66a5320bafe --- src/Math.php | 5 +++++ src/MathRenderer.php | 3 +-- src/MathValidator.php | 4 +--- tests/phpunit/InputCheck/MathoidCheckerTest.php | 5 ++--- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/Math.php b/src/Math.php index 696780669..ec4db3eb1 100644 --- a/src/Math.php +++ b/src/Math.php @@ -2,6 +2,7 @@ namespace MediaWiki\Extension\Math; +use MediaWiki\Extension\Math\InputCheck\InputCheckFactory; use MediaWiki\MediaWikiServices; use Psr\Container\ContainerInterface; @@ -24,4 +25,8 @@ final class Math { ->get( 'Math.Config' ); } + public static function getCheckerFactory( ContainerInterface $services = null ): InputCheckFactory { + return ( $services ?: MediaWikiServices::getInstance() ) + ->get( 'Math.CheckerFactory' ); + } } diff --git a/src/MathRenderer.php b/src/MathRenderer.php index 65209efca..2f8659616 100644 --- a/src/MathRenderer.php +++ b/src/MathRenderer.php @@ -689,8 +689,7 @@ abstract class MathRenderer { * @return bool */ protected function doCheck() { - $checker = MediaWikiServices::getInstance() - ->getService( 'Math.CheckerFactory' ) + $checker = Math::getCheckerFactory() ->newDefaultChecker( $this->tex, $this->getInputType(), $this->rbi ); try { diff --git a/src/MathValidator.php b/src/MathValidator.php index 2394c50d3..6a9d77d71 100644 --- a/src/MathValidator.php +++ b/src/MathValidator.php @@ -4,7 +4,6 @@ namespace MediaWiki\Extension\Math; use DataValues\StringValue; use InvalidArgumentException; -use MediaWiki\MediaWikiServices; use ValueValidators\Error; use ValueValidators\Result; use ValueValidators\ValueValidator; @@ -31,8 +30,7 @@ class MathValidator implements ValueValidator { // get input String from value $tex = $value->getValue(); - $checker = MediaWikiServices::getInstance() - ->getService( 'Math.CheckerFactory' ) + $checker = Math::getCheckerFactory() ->newLocalChecker( $tex, 'tex' ); if ( $checker->isValid() ) { diff --git a/tests/phpunit/InputCheck/MathoidCheckerTest.php b/tests/phpunit/InputCheck/MathoidCheckerTest.php index ff8f0dff5..577e51152 100644 --- a/tests/phpunit/InputCheck/MathoidCheckerTest.php +++ b/tests/phpunit/InputCheck/MathoidCheckerTest.php @@ -3,9 +3,9 @@ namespace MediaWiki\Extension\Math\InputCheck; use HashBagOStuff; +use MediaWiki\Extension\Math\Math; use MediaWiki\Extension\Math\MathMathML; use MediaWiki\Http\HttpRequestFactory; -use MediaWiki\MediaWikiServices; use MediaWikiIntegrationTestCase; use MockHttpTrait; use WANObjectCache; @@ -130,8 +130,7 @@ class MathoidCheckerTest extends MediaWikiIntegrationTestCase { * @return MathoidChecker */ private function getMathoidChecker( $tex = '\sin x' ): MathoidChecker { - return MediaWikiServices::getInstance() - ->getService( 'Math.CheckerFactory' ) + return Math::getCheckerFactory() ->newMathoidChecker( $tex, 'tex' ); }