diff --git a/Math.hooks.php b/Math.hooks.php index 223b80e..49cf0b9 100644 --- a/Math.hooks.php +++ b/Math.hooks.php @@ -311,7 +311,6 @@ class MathHooks { * @return bool */ static function onLoadExtensionSchemaUpdates( $updater = null ) { - if ( is_null( $updater ) ) { throw new Exception( 'Math extension is only necessary in 1.18 or above' ); } @@ -369,7 +368,7 @@ class MathHooks { */ public static function onParserAfterTidy( &$parser, &$text ) { $rbis = []; - foreach ( self::$tags as $key => $tag ){ + foreach ( self::$tags as $key => $tag ) { /** @var MathRenderer $renderer */ $renderer = $tag[0]; $rbi = new MathRestbaseInterface( $renderer->getTex(), $renderer->getInputType() ); @@ -377,7 +376,7 @@ class MathHooks { $rbis[] = $rbi; } MathRestbaseInterface::batchEvaluate( $rbis ); - foreach ( self::$tags as $key => $tag ){ + foreach ( self::$tags as $key => $tag ) { $value = call_user_func_array( [ "MathHooks","mathPostTagHook" ], $tag ); // Workaround for https://phabricator.wikimedia.org/T103269 $text = preg_replace( '/(]*>.*?)' . preg_quote( $key ) . diff --git a/MathFormatter.php b/MathFormatter.php index db7c722..a326eb4 100644 --- a/MathFormatter.php +++ b/MathFormatter.php @@ -5,14 +5,14 @@ use ValueFormatters\Exceptions\MismatchingDataValueTypeException; use ValueFormatters\ValueFormatter; use Wikibase\Lib\SnakFormatter; -/* -* Formats the tex string based on the known formats -* * text/plain: used in the value input field of Wikidata -* * text/x-wiki: wikitext -* * text/html: used in Wikidata to display the value of properties -* Formats can look like this: "text/html; disposition=widget" -* or just "text/plain" -*/ +/** + * Formats the tex string based on the known formats + * - text/plain: used in the value input field of Wikidata + * - text/x-wiki: wikitext + * - text/html: used in Wikidata to display the value of properties + * Formats can look like this: "text/html; disposition=widget" + * or just "text/plain" + */ class MathFormatter implements ValueFormatter { diff --git a/MathInputCheckRestbase.php b/MathInputCheckRestbase.php index b2627c5..b72f88a 100644 --- a/MathInputCheckRestbase.php +++ b/MathInputCheckRestbase.php @@ -39,7 +39,7 @@ class MathInputCheckRestbase extends MathInputCheck { if ( $errorRenderer === null ) { $errorRenderer = new MathSource( $this->inputTeX ); } - if ( isset( $e->error->message ) ){ + if ( isset( $e->error->message ) ) { if ( $e->error->message === 'Illegal TeX function' ) { return $errorRenderer->getError( 'math_unknown_function', $e->error->found ); } elseif ( preg_match( '/Math extension/', $e->error->message ) ) { @@ -81,7 +81,7 @@ class MathInputCheckRestbase extends MathInputCheck { */ public function getError() { $err = $this->restbaseInterface->getError(); - if ( $err === null ){ + if ( $err === null ) { return null; } return $this->errorObjectToHtml( $err ); diff --git a/MathInputCheckTexvc.php b/MathInputCheckTexvc.php index 40fb0ac..7d22f9d 100644 --- a/MathInputCheckTexvc.php +++ b/MathInputCheckTexvc.php @@ -51,7 +51,7 @@ class MathInputCheckTexvc extends MathInputCheck { public function isValid() { $us = $this; $checkWork = new PoolCounterWorkViaCallback( 'MathTexvc-check', "", [ - 'doWork' => function() use ( $us ) { + 'doWork' => function () use ( $us ) { return $us->doValidCheck(); } ] ); @@ -63,7 +63,7 @@ class MathInputCheckTexvc extends MathInputCheck { */ public function doValidCheck() { global $wgMathTexvcCheckExecutable; - if ( $wgMathTexvcCheckExecutable === false ){ + if ( $wgMathTexvcCheckExecutable === false ) { $texvcCheckExecutable = __DIR__ . '/texvccheck/texvccheck'; } else { $texvcCheckExecutable = $wgMathTexvcCheckExecutable; diff --git a/MathLaTeXML.php b/MathLaTeXML.php index d5ae368..aa0c055 100644 --- a/MathLaTeXML.php +++ b/MathLaTeXML.php @@ -106,7 +106,7 @@ class MathLaTeXML extends MathMathML { $post = $this->getLaTeXMLPostData(); // There is an API-inconsistency between different versions of the LaTeXML daemon // some versions require the literal prefix other don't allow it. - if ( ! strpos( $host, '/convert' ) ){ + if ( ! strpos( $host, '/convert' ) ) { $post = preg_replace( '/&tex=/', '&tex=literal:', $post, 1 ); } $this->lastError = ''; @@ -218,4 +218,3 @@ class MathLaTeXML extends MathMathML { return 'mathlatexml'; } } - diff --git a/MathMathML.php b/MathMathML.php index e1e6f06..23aa645 100644 --- a/MathMathML.php +++ b/MathMathML.php @@ -34,7 +34,7 @@ class MathMathML extends MathRenderer { $this->setMathml( '' . $tex . '' ); } elseif ( $params['type'] == 'ascii' ) { $this->inputType = 'ascii'; - } elseif ( $params['type'] == 'chem' ){ + } elseif ( $params['type'] == 'chem' ) { $this->inputType = 'chem'; } } @@ -493,7 +493,6 @@ class MathMathML extends MathRenderer { $this->userInputTex = $rpage->math_input; } parent::initializeFromDatabaseRow( $rpage ); - } /** diff --git a/MathRenderer.php b/MathRenderer.php index 99216f8..5cd16d7 100644 --- a/MathRenderer.php +++ b/MathRenderer.php @@ -553,11 +553,11 @@ abstract class MathRenderer { * @param string $mathStyle ('inlineDisplaystyle'|'display'|'inline') */ public function setMathStyle( $mathStyle = 'display' ) { - if ( $this->mathStyle !== $mathStyle ){ + if ( $this->mathStyle !== $mathStyle ) { $this->changed = true; } $this->mathStyle = $mathStyle; - if ( $mathStyle == 'inline' ){ + if ( $mathStyle == 'inline' ) { $this->inputType = 'inline-tex'; } else { $this->inputType = 'tex'; @@ -589,7 +589,7 @@ abstract class MathRenderer { // equation was already checked or checking is disabled return true; } else { - if ( self::getDisableTexFilter() == 'new' && $this->mode != 'source' ){ + if ( self::getDisableTexFilter() == 'new' && $this->mode != 'source' ) { if ( $this->readFromDatabase() ) { return true; } @@ -651,7 +651,7 @@ abstract class MathRenderer { */ public function getSvg( /** @noinspection PhpUnusedParameterInspection */ $render = 'render' ) { // Spaces will prevent the image from being displayed correctly in the browser - if ( !$this->svg && $this->rbi ){ + if ( !$this->svg && $this->rbi ) { $this->svg = $this->rbi->getSvg(); } return trim( $this->svg ); diff --git a/MathRestbaseInterface.php b/MathRestbaseInterface.php index a2d8470..2c29ec0 100644 --- a/MathRestbaseInterface.php +++ b/MathRestbaseInterface.php @@ -85,7 +85,7 @@ class MathRestbaseInterface { * @throws MWException */ public function getMathML() { - if ( !$this->mml ){ + if ( !$this->mml ) { $this->mml = $this->getContent( 'mml' ); } return $this->mml; @@ -132,7 +132,6 @@ class MathRestbaseInterface { ] ); } return $response; - } /** @@ -259,7 +258,7 @@ class MathRestbaseInterface { // Generates a TeX string that probably has not been generated before $uniqueTeX = uniqid( 't=', true ); $testInterface = new MathRestbaseInterface( $uniqueTeX ); - if ( ! $testInterface->checkTeX() ){ + if ( ! $testInterface->checkTeX() ) { $this->log()->warning( 'Config check failed, since test expression was considered as invalid.', [ 'uniqueTeX' => $uniqueTeX ] ); return false; @@ -268,7 +267,7 @@ class MathRestbaseInterface { $url = $testInterface->getFullSvgUrl(); $req = MWHttpRequest::factory( $url ); $status = $req->execute(); - if ( $status->isOK() ){ + if ( $status->isOK() ) { return true; } $this->log()->warning( 'Config check failed, due to an invalid response code.', @@ -440,7 +439,7 @@ class MathRestbaseInterface { $detail = 'Server problem.'; $json = json_decode( $body ); if ( isset( $json->detail ) ) { - if ( is_array( $json->detail ) ){ + if ( is_array( $json->detail ) ) { $detail = $json->detail[0]; } elseif ( is_string( $json->detail ) ) { $detail = $json->detail; diff --git a/MathTexvc.php b/MathTexvc.php index 88c8610..6d28385 100644 --- a/MathTexvc.php +++ b/MathTexvc.php @@ -144,7 +144,7 @@ class MathTexvc extends MathRenderer { 'class' => 'mwe-math-fallback-image-inline tex', 'alt' => $this->getTex() ]; - if ( $this->getMathStyle() === 'display' ){ + if ( $this->getMathStyle() === 'display' ) { // if DisplayStyle is true, the equation will be centered in a new line $attributes[ 'class' ] = 'mwe-math-fallback-image-display tex'; } @@ -157,7 +157,6 @@ class MathTexvc extends MathRenderer { ] ) ); - } /** @@ -178,7 +177,7 @@ class MathTexvc extends MathRenderer { */ public function callTexvc() { global $wgTexvc, $wgTexvcBackgroundColor, $wgHooks; - if ( $wgTexvc === false ){ + if ( $wgTexvc === false ) { $texvc = __DIR__ . '/math/texvc'; } else { $texvc = $wgTexvc; diff --git a/MathValidator.php b/MathValidator.php index e8f997f..d4713d3 100644 --- a/MathValidator.php +++ b/MathValidator.php @@ -27,7 +27,7 @@ class MathValidator implements ValueValidator { $tex = $value->getValue(); $checker = new MathInputCheckRestbase( $tex ); - if ( $checker->isValid() ) { + if ( $checker->isValid() ) { return Result::newSuccess(); } diff --git a/MathWikidataHook.php b/MathWikidataHook.php index cc14635..a0a15bb 100644 --- a/MathWikidataHook.php +++ b/MathWikidataHook.php @@ -23,7 +23,7 @@ class MathWikidataHook { $dataTypeDefinitions['PT:math'] = [ 'value-type' => 'string', - 'validator-factory-callback' => function() { + 'validator-factory-callback' => function () { // load validator builders $factory = WikibaseRepo::getDefaultValidatorBuilders(); @@ -34,12 +34,12 @@ class MathWikidataHook { $validators[] = new MathValidator(); return $validators; }, - 'parser-factory-callback' => function( ParserOptions $options ) { + 'parser-factory-callback' => function ( ParserOptions $options ) { $repo = WikibaseRepo::getDefaultInstance(); $normalizer = new WikibaseStringValueNormalizer( $repo->getStringNormalizer() ); return new StringParser( $normalizer ); }, - 'formatter-factory-callback' => function( $format, FormatterOptions $options ) { + 'formatter-factory-callback' => function ( $format, FormatterOptions $options ) { global $wgOut; $wgOut->addModuleStyles( [ 'ext.math.styles' ] ); return new MathFormatter( $format ); @@ -68,7 +68,7 @@ class MathWikidataHook { $dataTypeDefinitions['PT:math'] = [ 'value-type' => 'string', - 'formatter-factory-callback' => function( $format, FormatterOptions $options ) { + 'formatter-factory-callback' => function ( $format, FormatterOptions $options ) { global $wgOut; $wgOut->addModuleStyles( [ 'ext.math.styles' ] ); return new MathFormatter( $format ); diff --git a/SpecialMathShowImage.php b/SpecialMathShowImage.php index 060e922..1f895bb 100644 --- a/SpecialMathShowImage.php +++ b/SpecialMathShowImage.php @@ -60,7 +60,7 @@ class SpecialMathShowImage extends SpecialPage { $this->setHeaders( false ); echo $this->printSvgError( 'No Inputhash specified' ); } else { - if ( $tex === '' && $asciimath === '' ){ + if ( $tex === '' && $asciimath === '' ) { switch ( $this->mode ) { case 'png': $this->renderer = MathTexvc::newFromMd5( $hash ); @@ -113,7 +113,7 @@ class SpecialMathShowImage extends SpecialPage { } $this->setHeaders( $success ); echo $output; - if ( $success ){ + if ( $success ) { $this->renderer->writeCache(); } } diff --git a/SpecialMathStatus.php b/SpecialMathStatus.php index 53480d3..16386b1 100644 --- a/SpecialMathStatus.php +++ b/SpecialMathStatus.php @@ -35,7 +35,7 @@ class SpecialMathStatus extends SpecialPage { $enabledMathModes = MathHooks::getMathNames(); $out->addWikiMsg( 'math-status-introduction', count( $enabledMathModes ) ); - foreach ( $enabledMathModes as $modeNr => $modeName ){ + foreach ( $enabledMathModes as $modeNr => $modeName ) { $out->addWikiText( "=== $modeName ===" ); switch ( $modeNr ) { case 'mathml': @@ -146,7 +146,7 @@ class SpecialMathStatus extends SpecialPage { } private function assertTrue( $expression, $message = '' ) { - if ( $expression ){ + if ( $expression ) { $this->getOutput()->addWikiMsgArray( 'math-test-success', $message ); return true; } else { @@ -163,7 +163,7 @@ class SpecialMathStatus extends SpecialPage { private function assertEquals( $expected, $real, $message = '' ) { if ( is_array( $expected ) ) { - foreach ( $expected as $alternative ){ + foreach ( $expected as $alternative ) { if ( $alternative === $real ) { $this->getOutput()->addWikiMsgArray( 'math-test-success', $message ); return true; diff --git a/composer.json b/composer.json index 7a7cc76..fea45d1 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "require-dev": { "jakub-onderka/php-parallel-lint": "0.9.2", - "mediawiki/mediawiki-codesniffer": "0.7.2", + "mediawiki/mediawiki-codesniffer": "0.9.0", "jakub-onderka/php-console-highlighter": "0.3.2" }, "scripts": { diff --git a/maintenance/MathGenerateTests.php b/maintenance/MathGenerateTests.php index 6fc0577..bf8b0d9 100644 --- a/maintenance/MathGenerateTests.php +++ b/maintenance/MathGenerateTests.php @@ -21,8 +21,7 @@ require_once __DIR__ . '/../../../maintenance/Maintenance.php'; -class MathGenerateTests extends Maintenance -{ +class MathGenerateTests extends Maintenance { const REFERENCE_PAGE = 'mediawikiwiki:Extension:Math/CoverageTest'; public function __construct() { @@ -35,7 +34,6 @@ class MathGenerateTests extends Maintenance ); $this->addOption( 'length', "If set the only n equations were processed", false, true, "l" ); $this->addOption( 'user', "User with rights to view the page", false, true, "u" ); - } private static function getMathTagsFromPage( $titleString ) { diff --git a/phpcs.xml b/phpcs.xml index d81a292..811d29e 100644 --- a/phpcs.xml +++ b/phpcs.xml @@ -1,8 +1,19 @@ - + + + + + + + + + + + + . - - + + vendor diff --git a/tests/MathDatabaseTest.php b/tests/MathDatabaseTest.php index 5e521f7..7e55f7c 100644 --- a/tests/MathDatabaseTest.php +++ b/tests/MathDatabaseTest.php @@ -118,6 +118,5 @@ class MathDatabaseTest extends MediaWikiTestCase { $this->assertFalse( $this->renderer->writeCache() ); // as a result no entry can be found in the database. $this->assertFalse( $this->renderer->readFromDatabase() ); - } } diff --git a/tests/MathHooksTest.php b/tests/MathHooksTest.php index eb52538..516652c 100644 --- a/tests/MathHooksTest.php +++ b/tests/MathHooksTest.php @@ -35,7 +35,7 @@ class MathHooksTest extends MediaWikiTestCase { 'mathml' => 'mathml', 'latexml' => 'latexml', ]; - foreach ( $testCases as $input => $expected ){ + foreach ( $testCases as $input => $expected ) { $real = MathHooks::mathModeToString( $input, $default ); $this->assertEquals( $expected, $real, "Conversion math mode $input -> $expected" ); } @@ -54,7 +54,7 @@ class MathHooksTest extends MediaWikiTestCase { 'display' => 'display', 'inline' => 'inline', ]; - foreach ( $testCases as $input => $expected ){ + foreach ( $testCases as $input => $expected ) { $real = MathHooks::mathStyleToString( $input, $default ); $this->assertEquals( $expected, $real, "Conversion in math style" ); } @@ -76,7 +76,7 @@ class MathHooksTest extends MediaWikiTestCase { false => 'always' ]; - foreach ( $testCases as $input => $expected ){ + foreach ( $testCases as $input => $expected ) { $real = MathHooks::mathCheckToString( $input, $default ); $this->assertEquals( $expected, $real, "Conversion in math check method" ); } @@ -92,7 +92,7 @@ class MathHooksTest extends MediaWikiTestCase { 'invalid'=> $default ]; - foreach ( $testCases as $input => $expected ){ + foreach ( $testCases as $input => $expected ) { $real = MathHooks::mathModeToHashKey( $input, $default ); $this->assertEquals( $expected, $real, "Conversion to hash key" ); } diff --git a/tests/MathInputCheckRestbaseTest.php b/tests/MathInputCheckRestbaseTest.php index dca32e0..4e565cb 100644 --- a/tests/MathInputCheckRestbaseTest.php +++ b/tests/MathInputCheckRestbaseTest.php @@ -27,7 +27,6 @@ class MathInputCheckRestbaseTest extends MediaWikiTestCase { } $this->BadObject = new MathInputCheckRestbase( '\newcommand{\text{do evil things}}' ); $this->GoodObject = new MathInputCheckRestbase( '\sin\left(\frac12x\right)' ); - } /** diff --git a/tests/MathInputCheckTest.php b/tests/MathInputCheckTest.php index 6d9a3f3..cb7781d 100644 --- a/tests/MathInputCheckTest.php +++ b/tests/MathInputCheckTest.php @@ -7,8 +7,7 @@ * * @licence GNU GPL v2+ */ -class MathInputCheckTest extends MediaWikiTestCase -{ +class MathInputCheckTest extends MediaWikiTestCase { /** * @covers MathInputCheck::isValid */ diff --git a/tests/MathRendererTest.php b/tests/MathRendererTest.php index 9ce8f40..f0d8845 100644 --- a/tests/MathRendererTest.php +++ b/tests/MathRendererTest.php @@ -85,7 +85,6 @@ class MathRendererTest extends MediaWikiTestCase { ] )->disableOriginalConstructor()->getMock(); $renderer->setPurge(); $this->assertEquals( $renderer->isPurge(), true, "Test purge." ); - } public function testDisableCheckingAlways() { @@ -104,7 +103,6 @@ class MathRendererTest extends MediaWikiTestCase { $this->assertEquals( $renderer->checkTeX(), true ); // now setTex sould not be called again $this->assertEquals( $renderer->checkTeX(), true ); - } public function testDisableCheckingNever() {