Merge "Use native str_starts_with/str_contains and such where possible"

This commit is contained in:
jenkins-bot 2024-04-21 10:32:55 +00:00 committed by Gerrit Code Review
commit 8fb5044103
4 changed files with 8 additions and 19 deletions

View file

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

View file

@ -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 {

View file

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

View file

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