mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Math
synced 2024-11-27 17:01:07 +00:00
Merge "Use native str_starts_with/str_contains and such where possible"
This commit is contained in:
commit
8fb5044103
|
@ -92,7 +92,7 @@ class MathLaTeXML extends MathMathML {
|
|||
|
||||
// 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( $this->host, '/convert' ) ) {
|
||||
if ( !str_contains( $this->host, '/convert' ) ) {
|
||||
$postData = preg_replace( '/&tex=/', '&tex=literal:', $postData, 1 );
|
||||
}
|
||||
|
||||
|
|
|
@ -85,21 +85,13 @@ class MhchemPatterns {
|
|||
*/
|
||||
if ( !$pattern instanceof Reg ) {
|
||||
// Added this if to catch empty needle for strpos input in PHP
|
||||
if ( !MhchemUtil::issetJS( $pattern ) ) {
|
||||
if ( !MhchemUtil::issetJS( $pattern ) || str_starts_with( $input, $pattern ) ) {
|
||||
return $pattern;
|
||||
}
|
||||
if ( strpos( $input, $pattern ) !== 0 ) {
|
||||
return null;
|
||||
}
|
||||
return $pattern;
|
||||
} else {
|
||||
$matches = [];
|
||||
$match = preg_match( $pattern->getRegExp(), $input, $matches );
|
||||
if ( !$match ) {
|
||||
return null;
|
||||
}
|
||||
} elseif ( preg_match( $pattern->getRegExp(), $input, $matches ) ) {
|
||||
return $matches[0];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private function findObserveGroupsInner( string $input, $i, $endChars ): ?array {
|
||||
|
|
|
@ -31,10 +31,6 @@ class TexVC {
|
|||
$this->tu = TexUtil::getInstance();
|
||||
}
|
||||
|
||||
private function strStartsWith( $haystack, $needle ): bool {
|
||||
return strpos( $haystack, $needle ) === 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Usually this step is done implicitly within the check-method.
|
||||
* @param string $input tex-string as input for the grammar
|
||||
|
@ -139,8 +135,8 @@ class TexVC {
|
|||
return $result;
|
||||
} catch ( Exception $ex ) {
|
||||
if ( $ex instanceof SyntaxError && !$options['oldtexvc']
|
||||
&& $this->strStartsWith( $ex->getMessage(), 'Deprecation' ) ) {
|
||||
|
||||
&& str_starts_with( $ex->getMessage(), 'Deprecation' )
|
||||
) {
|
||||
$warnings[] = [
|
||||
'type' => 'texvc-deprecation',
|
||||
'details' => $this->handleTexError( $ex, $options )
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
namespace MediaWiki\Extension\Math\Tests;
|
||||
|
||||
use MediaWiki\Extension\Math\Math;
|
||||
use MediaWiki\Extension\Math\MathConfig;
|
||||
|
||||
/**
|
||||
* @covers \MediaWiki\Extension\Math\Math
|
||||
|
@ -9,6 +10,6 @@ use MediaWiki\Extension\Math\Math;
|
|||
class MathIntegrationTest extends \MediaWikiIntegrationTestCase {
|
||||
public function testGetMathConfigNull() {
|
||||
$config = Math::getMathConfig();
|
||||
$this->assertInstanceOf( '\MediaWiki\Extension\Math\MathConfig', $config );
|
||||
$this->assertInstanceOf( MathConfig::class, $config );
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue