Use native str_starts_with/str_contains and such where possible

Includes a few other smaller cleanups that aren't worth a separate
patch, in my opinion.

Change-Id: I42d6e70ef132bfc2cf606164e2e62becb1f915df
这个提交包含在:
thiemowmde 2024-04-19 20:48:34 +02:00
父节点 6c12bdfc8b
当前提交 71bd192002
共有 4 个文件被更改,包括 8 次插入19 次删除

查看文件

@ -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 );
}
}