From bdeec56d1f4bdde0f1e532e59e9b8352db64ea0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thiemo=20M=C3=A4ttig?= Date: Mon, 10 Jul 2017 11:40:12 +0200 Subject: [PATCH] Fix and add missing documentation and fix minor code smell issues Change-Id: Ifa2f8a47fbd0bdd20334f59dd06a21339b9a4292 --- Math.hooks.php | 10 +++++++--- MathFormatter.php | 2 +- MathMathML.php | 10 +++++++--- MathRenderer.php | 4 ++-- MathRestbaseInterface.php | 11 +++++++---- MathTexvc.php | 4 ++-- tests/MathCoverageTest.php | 2 +- tests/MathIdTest.php | 2 +- tests/MathMathMLTest.php | 3 +-- 9 files changed, 29 insertions(+), 19 deletions(-) diff --git a/Math.hooks.php b/Math.hooks.php index 49cf0b9..13b8845 100644 --- a/Math.hooks.php +++ b/Math.hooks.php @@ -9,7 +9,12 @@ use MediaWiki\Logger\LoggerFactory; class MathHooks { + + /** + * @var array[] + */ private static $tags = []; + const MATHCACHEKEY = 'math='; public static function mathConstantToString( $value, array $defs, $prefix, $default ) { @@ -388,10 +393,9 @@ class MathHooks { self::$tags = []; return true; } + /** - * - * @global type $wgOut - * @param type $toolbar + * @param string $toolbar HTML */ static function onEditPageBeforeEditToolbar( &$toolbar ) { global $wgOut; diff --git a/MathFormatter.php b/MathFormatter.php index a326eb4..5e3c68c 100644 --- a/MathFormatter.php +++ b/MathFormatter.php @@ -63,7 +63,7 @@ class MathFormatter implements ValueFormatter { default: $renderer = new MathMathML( $tex ); - if ( $renderer->checkTex() && $renderer->render() ) { + if ( $renderer->checkTeX() && $renderer->render() ) { $html = $renderer->getHtmlOutput(); } else { $html = $renderer->getLastError(); diff --git a/MathMathML.php b/MathMathML.php index 23aa645..6ce53a2 100644 --- a/MathMathML.php +++ b/MathMathML.php @@ -20,7 +20,12 @@ class MathMathML extends MathRenderer { /** @var boolean if false MathML output is not validated */ private $XMLValidation = true; + + /** + * @var string|bool + */ private $svgPath = false; + private $mathoidStyle; public function __construct( $tex = '', $params = [] ) { @@ -176,9 +181,8 @@ class MathMathML extends MathRenderer { $this->getPostData(); } $options = [ 'method' => 'POST', 'postData' => $post, 'timeout' => $wgMathLaTeXMLTimeout ]; - /** @var $req (CurlHttpRequest|PhpHttpRequest) the request object */ + /** @var CurlHttpRequest|PhpHttpRequest $req the request object */ $req = $httpRequestClass::factory( $host, $options ); - /** @var Status $req Status the request status */ $status = $req->execute(); if ( $status->isGood() ) { $res = $req->getContent(); @@ -334,7 +338,7 @@ class MathMathML extends MathRenderer { /** * @param boolean $noRender - * @return type + * @return Title|string */ private function getFallbackImageUrl( $noRender = false ) { if ( $this->svgPath ) { diff --git a/MathRenderer.php b/MathRenderer.php index 5cd16d7..7b2db14 100644 --- a/MathRenderer.php +++ b/MathRenderer.php @@ -487,14 +487,14 @@ abstract class MathRenderer { /** * Get the attributes of the math tag * - * @return [] + * @return array */ public function getParams() { return $this->params; } /** - * @param [] $params + * @param array $params */ public function setParams( $params ) { // $changed is not set to true here, because the attributes do not affect diff --git a/MathRestbaseInterface.php b/MathRestbaseInterface.php index 2c29ec0..f248f48 100644 --- a/MathRestbaseInterface.php +++ b/MathRestbaseInterface.php @@ -22,7 +22,6 @@ class MathRestbaseInterface { private $purge = false; /** - * MathRestbaseInterface constructor. * @param string $tex * @param string $type */ @@ -34,8 +33,8 @@ class MathRestbaseInterface { /** * Bundles several requests for fetching MathML. * Does not send requests, if the the input TeX is invalid. - * @param $rbis - * @param $serviceClient + * @param MathRestbaseInterface[] $rbis + * @param VirtualRESTServiceClient $serviceClient */ private static function batchGetMathML( $rbis, $serviceClient ) { $requests = []; @@ -135,7 +134,7 @@ class MathRestbaseInterface { } /** - * @param array $rbis array of MathRestbaseInterface instances + * @param MathRestbaseInterface[] $rbis */ public static function batchEvaluate( $rbis ) { if ( count( $rbis ) == 0 ) { @@ -162,6 +161,9 @@ class MathRestbaseInterface { self::batchGetMathML( $rbis, $serviceClient ); } + /** + * @return VirtualRESTServiceClient + */ private function getServiceClient() { global $wgVirtualRestConfig, $wgMathConcurrentReqs; $http = new MultiHttpClient( [ 'maxConnsPerHost' => $wgMathConcurrentReqs ] ); @@ -263,6 +265,7 @@ class MathRestbaseInterface { [ 'uniqueTeX' => $uniqueTeX ] ); return false; } + try { $url = $testInterface->getFullSvgUrl(); $req = MWHttpRequest::factory( $url ); diff --git a/MathTexvc.php b/MathTexvc.php index 6d28385..85c5407 100644 --- a/MathTexvc.php +++ b/MathTexvc.php @@ -57,7 +57,7 @@ class MathTexvc extends MathRenderer { } /** - * @param database_row $rpage + * @param stdClass $rpage * @return bool */ protected function initializeFromDatabaseRow( $rpage ) { @@ -330,7 +330,7 @@ class MathTexvc extends MathRenderer { if ( !$backend ) { $backend = new FSFileBackend( [ 'name' => 'math-backend', - 'wikiId' => wfWikiId(), + 'wikiId' => wfWikiID(), 'lockManager' => new NullLockManager( [] ), 'containerPaths' => [ 'math-render' => $wgMathDirectory ], 'fileMode' => 0777, diff --git a/tests/MathCoverageTest.php b/tests/MathCoverageTest.php index 17abed0..05abcf9 100644 --- a/tests/MathCoverageTest.php +++ b/tests/MathCoverageTest.php @@ -85,7 +85,7 @@ class MathCoverageTest extends MediaWikiTestCase { /** * Gets the test-data from the file ParserTest.json - * @return [$input, $output] where $input is the test input string + * @return string[] [ $input, $output ] where $input is the test input string * and $output is the rendered html5-output string */ public function provideCoverage() { diff --git a/tests/MathIdTest.php b/tests/MathIdTest.php index 38ac6bc..0f5e053 100644 --- a/tests/MathIdTest.php +++ b/tests/MathIdTest.php @@ -17,7 +17,7 @@ class MathIdTest extends MediaWikiTestCase { public function testBasics() { define( 'RANDOM_ID', 'a_random_id' ); $renderer = MathRenderer::getRenderer( "a+b", [ 'id' => RANDOM_ID ] ); - $this->assertEquals( RANDOM_ID, $renderer->getId() ); + $this->assertEquals( RANDOM_ID, $renderer->getID() ); } } diff --git a/tests/MathMathMLTest.php b/tests/MathMathMLTest.php index 745c449..5f36c60 100644 --- a/tests/MathMathMLTest.php +++ b/tests/MathMathMLTest.php @@ -69,7 +69,7 @@ class MathMathMLTest extends MediaWikiTestCase { $requestReturn = $renderer->makeRequest( $url, 'a+b', $res, $error, 'MathMLHttpRequestTester' ); $this->assertEquals( true, $requestReturn, "successful call return" ); - $this->isTrue( $res, "successfull call" ); + $this->assertTrue( $res, 'successfull call' ); $this->assertEquals( $error, '', "successfull call errormessage" ); } @@ -139,7 +139,6 @@ class MathMathMLTest extends MediaWikiTestCase { * Helper class for testing * @author physikerwelt * @see MWHttpRequestTester - * */ class MathMLHttpRequestTester {