mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Cite
synced 2024-11-23 22:45:20 +00:00
Replace isset() with null check
isset() should only be used to suppress errors, not for null check. When the variable is always defined, there is no need to use isset. Found by a new phan plugin (2efea9f989) https://www.mediawiki.org/wiki/Manual:Coding_conventions/PHP#isset Change-Id: I2eee98fdcb21192108183c431b10e0072b951f72
This commit is contained in:
parent
41bafe6f2c
commit
875b747d3c
|
@ -61,7 +61,7 @@ class FootnoteMarkFormatter {
|
||||||
private function makeLabel( ReferenceStackItem $ref, Parser $parser ): string {
|
private function makeLabel( ReferenceStackItem $ref, Parser $parser ): string {
|
||||||
$label = $this->fetchCustomizedLinkLabel( $parser, $ref->group, $ref->number ) ??
|
$label = $this->fetchCustomizedLinkLabel( $parser, $ref->group, $ref->number ) ??
|
||||||
$this->makeDefaultLabel( $ref );
|
$this->makeDefaultLabel( $ref );
|
||||||
if ( isset( $ref->extendsIndex ) ) {
|
if ( $ref->extendsIndex !== null ) {
|
||||||
$label .= '.' . $this->messageLocalizer->localizeDigits( (string)$ref->extendsIndex );
|
$label .= '.' . $this->messageLocalizer->localizeDigits( (string)$ref->extendsIndex );
|
||||||
}
|
}
|
||||||
return $label;
|
return $label;
|
||||||
|
|
|
@ -101,19 +101,19 @@ class ReferenceListFormatter {
|
||||||
// Make sure the parent is not a subreference.
|
// Make sure the parent is not a subreference.
|
||||||
// FIXME: Move to a validation function.
|
// FIXME: Move to a validation function.
|
||||||
$extends =& $ref->extends;
|
$extends =& $ref->extends;
|
||||||
if ( isset( $extends ) && isset( $groupRefs[$extends]->extends ) ) {
|
if ( $extends !== null && isset( $groupRefs[$extends]->extends ) ) {
|
||||||
$ref->warnings[] = [ 'cite_error_ref_nested_extends',
|
$ref->warnings[] = [ 'cite_error_ref_nested_extends',
|
||||||
$extends, $groupRefs[$extends]->extends ];
|
$extends, $groupRefs[$extends]->extends ];
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !$indented && isset( $extends ) ) {
|
if ( !$indented && $extends !== null ) {
|
||||||
// The nested <ol> must be inside the parent's <li>
|
// The nested <ol> must be inside the parent's <li>
|
||||||
if ( preg_match( '#</li>\s*$#D', $parserInput, $matches, PREG_OFFSET_CAPTURE ) ) {
|
if ( preg_match( '#</li>\s*$#D', $parserInput, $matches, PREG_OFFSET_CAPTURE ) ) {
|
||||||
$parserInput = substr( $parserInput, 0, $matches[0][1] );
|
$parserInput = substr( $parserInput, 0, $matches[0][1] );
|
||||||
}
|
}
|
||||||
$parserInput .= Html::openElement( 'ol', [ 'class' => 'mw-extended-references' ] );
|
$parserInput .= Html::openElement( 'ol', [ 'class' => 'mw-extended-references' ] );
|
||||||
$indented = $matches[0][0] ?? true;
|
$indented = $matches[0][0] ?? true;
|
||||||
} elseif ( $indented && !isset( $extends ) ) {
|
} elseif ( $indented && $extends === null ) {
|
||||||
$parserInput .= $this->closeIndention( $indented );
|
$parserInput .= $this->closeIndention( $indented );
|
||||||
$indented = false;
|
$indented = false;
|
||||||
}
|
}
|
||||||
|
@ -151,13 +151,13 @@ class ReferenceListFormatter {
|
||||||
|
|
||||||
// Special case for an incomplete follow="…". This is valid e.g. in the Page:… namespace on
|
// Special case for an incomplete follow="…". This is valid e.g. in the Page:… namespace on
|
||||||
// Wikisource. Note this returns a <p>, not an <li> as expected!
|
// Wikisource. Note this returns a <p>, not an <li> as expected!
|
||||||
if ( isset( $ref->follow ) ) {
|
if ( $ref->follow !== null ) {
|
||||||
return '<p id="' . $this->anchorFormatter->jumpLinkTarget( $ref->follow ) . '">' . $text . '</p>';
|
return '<p id="' . $this->anchorFormatter->jumpLinkTarget( $ref->follow ) . '">' . $text . '</p>';
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parameter $4 in the cite_references_link_one and cite_references_link_many messages
|
// Parameter $4 in the cite_references_link_one and cite_references_link_many messages
|
||||||
$extraAttributes = '';
|
$extraAttributes = '';
|
||||||
if ( isset( $ref->dir ) ) {
|
if ( $ref->dir !== null ) {
|
||||||
// The following classes are generated here:
|
// The following classes are generated here:
|
||||||
// * mw-cite-dir-ltr
|
// * mw-cite-dir-ltr
|
||||||
// * mw-cite-dir-rtl
|
// * mw-cite-dir-rtl
|
||||||
|
@ -165,7 +165,7 @@ class ReferenceListFormatter {
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( $ref->count === 1 ) {
|
if ( $ref->count === 1 ) {
|
||||||
if ( !isset( $ref->name ) ) {
|
if ( $ref->name === null ) {
|
||||||
$id = $ref->key;
|
$id = $ref->key;
|
||||||
$backlinkId = $this->anchorFormatter->backLink( $ref->key );
|
$backlinkId = $this->anchorFormatter->backLink( $ref->key );
|
||||||
} else {
|
} else {
|
||||||
|
@ -220,7 +220,7 @@ class ReferenceListFormatter {
|
||||||
private function renderTextAndWarnings(
|
private function renderTextAndWarnings(
|
||||||
Parser $parser, $key, ReferenceStackItem $ref, bool $isSectionPreview
|
Parser $parser, $key, ReferenceStackItem $ref, bool $isSectionPreview
|
||||||
): string {
|
): string {
|
||||||
if ( !isset( $ref->text ) ) {
|
if ( $ref->text === null ) {
|
||||||
return $this->errorReporter->plain( $parser,
|
return $this->errorReporter->plain( $parser,
|
||||||
$isSectionPreview
|
$isSectionPreview
|
||||||
? 'cite_warning_sectionpreview_no_text'
|
? 'cite_warning_sectionpreview_no_text'
|
||||||
|
@ -270,7 +270,7 @@ class ReferenceListFormatter {
|
||||||
private function referencesFormatEntryAlternateBacklinkLabel(
|
private function referencesFormatEntryAlternateBacklinkLabel(
|
||||||
Parser $parser, int $offset
|
Parser $parser, int $offset
|
||||||
): ?string {
|
): ?string {
|
||||||
if ( !isset( $this->backlinkLabels ) ) {
|
if ( $this->backlinkLabels === null ) {
|
||||||
$msg = $this->messageLocalizer->msg( 'cite_references_link_many_format_backlink_labels' );
|
$msg = $this->messageLocalizer->msg( 'cite_references_link_many_format_backlink_labels' );
|
||||||
$this->backlinkLabels = $msg->isDisabled() ? [] : preg_split( '/\s+/', $msg->plain() );
|
$this->backlinkLabels = $msg->isDisabled() ? [] : preg_split( '/\s+/', $msg->plain() );
|
||||||
}
|
}
|
||||||
|
|
|
@ -153,9 +153,9 @@ class ReferenceStack {
|
||||||
$ref->number ??= ++$this->groupRefSequence[$group];
|
$ref->number ??= ++$this->groupRefSequence[$group];
|
||||||
|
|
||||||
// Do not mess with a known parent a second time
|
// Do not mess with a known parent a second time
|
||||||
if ( $extends && !isset( $ref->extendsIndex ) ) {
|
if ( $extends && $ref->extendsIndex === null ) {
|
||||||
$parentRef =& $this->refs[$group][$extends];
|
$parentRef =& $this->refs[$group][$extends];
|
||||||
if ( !isset( $parentRef ) ) {
|
if ( $parentRef === null ) {
|
||||||
// Create a new placeholder and give it the current sequence number.
|
// Create a new placeholder and give it the current sequence number.
|
||||||
$parentRef = new ReferenceStackItem();
|
$parentRef = new ReferenceStackItem();
|
||||||
$parentRef->name = $extends;
|
$parentRef->name = $extends;
|
||||||
|
@ -347,7 +347,7 @@ class ReferenceStack {
|
||||||
$ref =& $this->refs[$group][$name];
|
$ref =& $this->refs[$group][$name];
|
||||||
$ref ??= new ReferenceStackItem();
|
$ref ??= new ReferenceStackItem();
|
||||||
$ref->placeholder = false;
|
$ref->placeholder = false;
|
||||||
if ( !isset( $ref->text ) ) {
|
if ( $ref->text === null ) {
|
||||||
$ref->text = $text;
|
$ref->text = $text;
|
||||||
} elseif ( $ref->text !== $text ) {
|
} elseif ( $ref->text !== $text ) {
|
||||||
// two refs with same key and different content
|
// two refs with same key and different content
|
||||||
|
|
|
@ -63,7 +63,7 @@ class Validator {
|
||||||
|
|
||||||
$groupRefs = $this->referenceStack->getGroupRefs( $group );
|
$groupRefs = $this->referenceStack->getGroupRefs( $group );
|
||||||
// @phan-suppress-next-line PhanTypeMismatchDimFetchNullable false positive
|
// @phan-suppress-next-line PhanTypeMismatchDimFetchNullable false positive
|
||||||
if ( isset( $groupRefs[$name] ) && !isset( $groupRefs[$name]->extends ) ) {
|
if ( isset( $groupRefs[$name] ) && $groupRefs[$name]->extends === null ) {
|
||||||
// T242141: A top-level <ref> can't be changed into a sub-reference
|
// T242141: A top-level <ref> can't be changed into a sub-reference
|
||||||
return StatusValue::newFatal( 'cite_error_references_duplicate_key', $name );
|
return StatusValue::newFatal( 'cite_error_references_duplicate_key', $name );
|
||||||
} elseif ( isset( $groupRefs[$extends]->extends ) ) {
|
} elseif ( isset( $groupRefs[$extends]->extends ) ) {
|
||||||
|
|
Loading…
Reference in a new issue