mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Cite
synced 2024-11-23 22:45:20 +00:00
Avoid a few isset() in favor of more recent syntax
As well as replacing a few `=== null` comparisons with the new ??= operator. Bug: T353227 Change-Id: I5b273f452d1e46d37fc28861b54c4e1f19a7a65a
This commit is contained in:
parent
34798cce42
commit
fee8606db6
|
@ -291,9 +291,7 @@ class Cite {
|
||||||
);
|
);
|
||||||
$arguments = $status->getValue();
|
$arguments = $status->getValue();
|
||||||
// Use the default group, or the references group when inside one.
|
// Use the default group, or the references group when inside one.
|
||||||
if ( $arguments['group'] === null ) {
|
$arguments['group'] ??= $this->inReferencesGroup ?? self::DEFAULT_GROUP;
|
||||||
$arguments['group'] = $this->inReferencesGroup ?? self::DEFAULT_GROUP;
|
|
||||||
}
|
|
||||||
|
|
||||||
// @phan-suppress-next-line PhanParamTooFewUnpack No good way to document it.
|
// @phan-suppress-next-line PhanParamTooFewUnpack No good way to document it.
|
||||||
$status->merge( $this->validateRef( $text, ...array_values( $arguments ) ) );
|
$status->merge( $this->validateRef( $text, ...array_values( $arguments ) ) );
|
||||||
|
|
|
@ -90,9 +90,7 @@ class CiteParserTagHooks {
|
||||||
* @return Cite
|
* @return Cite
|
||||||
*/
|
*/
|
||||||
private static function citeForParser( Parser $parser ): Cite {
|
private static function citeForParser( Parser $parser ): Cite {
|
||||||
if ( !isset( $parser->extCite ) ) {
|
$parser->extCite ??= new Cite( $parser );
|
||||||
$parser->extCite = new Cite( $parser );
|
|
||||||
}
|
|
||||||
return $parser->extCite;
|
return $parser->extCite;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -111,12 +111,8 @@ class ReferenceStack {
|
||||||
?string $follow,
|
?string $follow,
|
||||||
?string $dir
|
?string $dir
|
||||||
): ?array {
|
): ?array {
|
||||||
if ( !isset( $this->refs[$group] ) ) {
|
$this->refs[$group] ??= [];
|
||||||
$this->refs[$group] = [];
|
$this->groupRefSequence[$group] ??= 0;
|
||||||
}
|
|
||||||
if ( !isset( $this->groupRefSequence[$group] ) ) {
|
|
||||||
$this->groupRefSequence[$group] = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
$ref = [
|
$ref = [
|
||||||
'count' => $name ? 0 : -1,
|
'count' => $name ? 0 : -1,
|
||||||
|
@ -403,11 +399,8 @@ class ReferenceStack {
|
||||||
* @param string $text
|
* @param string $text
|
||||||
*/
|
*/
|
||||||
public function appendText( string $group, string $name, string $text ) {
|
public function appendText( string $group, string $name, string $text ) {
|
||||||
if ( isset( $this->refs[$group][$name]['text'] ) ) {
|
$this->refs[$group][$name]['text'] ??= '';
|
||||||
$this->refs[$group][$name]['text'] .= $text;
|
$this->refs[$group][$name]['text'] .= $text;
|
||||||
} else {
|
|
||||||
$this->refs[$group][$name]['text'] = $text;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -264,13 +264,11 @@ class ReferencesFormatter {
|
||||||
private function referencesFormatEntryAlternateBacklinkLabel(
|
private function referencesFormatEntryAlternateBacklinkLabel(
|
||||||
Parser $parser, int $offset
|
Parser $parser, int $offset
|
||||||
): string {
|
): string {
|
||||||
if ( $this->backlinkLabels === null ) {
|
$this->backlinkLabels ??= preg_split(
|
||||||
$this->backlinkLabels = preg_split(
|
'/\s+/',
|
||||||
'/\s+/',
|
$this->messageLocalizer->msg( 'cite_references_link_many_format_backlink_labels' )
|
||||||
$this->messageLocalizer->msg( 'cite_references_link_many_format_backlink_labels' )
|
->plain()
|
||||||
->plain()
|
);
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->backlinkLabels[$offset]
|
return $this->backlinkLabels[$offset]
|
||||||
?? $this->errorReporter->plain( $parser, 'cite_error_references_no_backlink_label' );
|
?? $this->errorReporter->plain( $parser, 'cite_error_references_no_backlink_label' );
|
||||||
|
|
|
@ -24,26 +24,22 @@ class CitationToolDefinition {
|
||||||
->plain()
|
->plain()
|
||||||
);
|
);
|
||||||
|
|
||||||
if ( $citationDefinition === null ) {
|
$citationDefinition ??= json_decode(
|
||||||
$citationDefinition = json_decode(
|
$context->msg( 'visualeditor-cite-tool-definition.json' )
|
||||||
$context->msg( 'visualeditor-cite-tool-definition.json' )
|
->inContentLanguage()
|
||||||
->inContentLanguage()
|
->plain()
|
||||||
->plain()
|
);
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
$citationTools = [];
|
$citationTools = [];
|
||||||
if ( is_array( $citationDefinition ) ) {
|
if ( is_array( $citationDefinition ) ) {
|
||||||
foreach ( $citationDefinition as $tool ) {
|
foreach ( $citationDefinition as $tool ) {
|
||||||
if ( !isset( $tool->title ) ) {
|
// The following messages are generated here:
|
||||||
// The following messages are generated here:
|
// * visualeditor-cite-tool-name-book
|
||||||
// * visualeditor-cite-tool-name-book
|
// * visualeditor-cite-tool-name-journal
|
||||||
// * visualeditor-cite-tool-name-journal
|
// * visualeditor-cite-tool-name-news
|
||||||
// * visualeditor-cite-tool-name-news
|
// * visualeditor-cite-tool-name-web
|
||||||
// * visualeditor-cite-tool-name-web
|
$tool->title ??= $context->msg( 'visualeditor-cite-tool-name-' . $tool->name )
|
||||||
$tool->title = $context->msg( 'visualeditor-cite-tool-name-' . $tool->name )
|
->text();
|
||||||
->text();
|
|
||||||
}
|
|
||||||
$citationTools[] = $tool;
|
$citationTools[] = $tool;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,7 +43,7 @@ class CiteParserHooksTest extends \MediaWikiUnitTestCase {
|
||||||
$citeParserHooks = new CiteParserHooks();
|
$citeParserHooks = new CiteParserHooks();
|
||||||
$citeParserHooks->onParserClearState( $parser );
|
$citeParserHooks->onParserClearState( $parser );
|
||||||
|
|
||||||
$this->assertFalse( isset( $parser->extCite ) );
|
$this->assertObjectNotHasProperty( 'extCite', $parser );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -56,7 +56,7 @@ class CiteParserHooksTest extends \MediaWikiUnitTestCase {
|
||||||
$citeParserHooks = new CiteParserHooks();
|
$citeParserHooks = new CiteParserHooks();
|
||||||
$citeParserHooks->onParserCloned( $parser );
|
$citeParserHooks->onParserCloned( $parser );
|
||||||
|
|
||||||
$this->assertFalse( isset( $parser->extCite ) );
|
$this->assertObjectNotHasProperty( 'extCite', $parser );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -370,16 +370,13 @@ class ReferencesFormatterTest extends \MediaWikiUnitTestCase {
|
||||||
$mockMessageLocalizer->method( 'msg' )
|
$mockMessageLocalizer->method( 'msg' )
|
||||||
->willReturn( $mockMessage );
|
->willReturn( $mockMessage );
|
||||||
|
|
||||||
$mockErrorReporter = $this->createMock( ErrorReporter::class );
|
$errorReporter = $this->createMock( ErrorReporter::class );
|
||||||
if ( $expectedLabel === null ) {
|
$errorReporter->expects( $expectedLabel ? $this->never() : $this->once() )
|
||||||
$mockErrorReporter->expects( $this->once() )->method( 'plain' );
|
->method( 'plain' );
|
||||||
} else {
|
|
||||||
$mockErrorReporter->expects( $this->never() )->method( 'plain' );
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @var ReferencesFormatter $formatter */
|
/** @var ReferencesFormatter $formatter */
|
||||||
$formatter = TestingAccessWrapper::newFromObject( new ReferencesFormatter(
|
$formatter = TestingAccessWrapper::newFromObject( new ReferencesFormatter(
|
||||||
$mockErrorReporter,
|
$errorReporter,
|
||||||
$this->createMock( AnchorFormatter::class ),
|
$this->createMock( AnchorFormatter::class ),
|
||||||
$mockMessageLocalizer
|
$mockMessageLocalizer
|
||||||
) );
|
) );
|
||||||
|
|
Loading…
Reference in a new issue