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:
Umherirrender 2024-10-27 14:13:06 +01:00
parent 41bafe6f2c
commit 875b747d3c
4 changed files with 13 additions and 13 deletions

View file

@ -61,7 +61,7 @@ class FootnoteMarkFormatter {
private function makeLabel( ReferenceStackItem $ref, Parser $parser ): string {
$label = $this->fetchCustomizedLinkLabel( $parser, $ref->group, $ref->number ) ??
$this->makeDefaultLabel( $ref );
if ( isset( $ref->extendsIndex ) ) {
if ( $ref->extendsIndex !== null ) {
$label .= '.' . $this->messageLocalizer->localizeDigits( (string)$ref->extendsIndex );
}
return $label;

View file

@ -101,19 +101,19 @@ class ReferenceListFormatter {
// Make sure the parent is not a subreference.
// FIXME: Move to a validation function.
$extends =& $ref->extends;
if ( isset( $extends ) && isset( $groupRefs[$extends]->extends ) ) {
if ( $extends !== null && isset( $groupRefs[$extends]->extends ) ) {
$ref->warnings[] = [ 'cite_error_ref_nested_extends',
$extends, $groupRefs[$extends]->extends ];
}
if ( !$indented && isset( $extends ) ) {
if ( !$indented && $extends !== null ) {
// The nested <ol> must be inside the parent's <li>
if ( preg_match( '#</li>\s*$#D', $parserInput, $matches, PREG_OFFSET_CAPTURE ) ) {
$parserInput = substr( $parserInput, 0, $matches[0][1] );
}
$parserInput .= Html::openElement( 'ol', [ 'class' => 'mw-extended-references' ] );
$indented = $matches[0][0] ?? true;
} elseif ( $indented && !isset( $extends ) ) {
} elseif ( $indented && $extends === null ) {
$parserInput .= $this->closeIndention( $indented );
$indented = false;
}
@ -151,13 +151,13 @@ class ReferenceListFormatter {
// 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!
if ( isset( $ref->follow ) ) {
if ( $ref->follow !== null ) {
return '<p id="' . $this->anchorFormatter->jumpLinkTarget( $ref->follow ) . '">' . $text . '</p>';
}
// Parameter $4 in the cite_references_link_one and cite_references_link_many messages
$extraAttributes = '';
if ( isset( $ref->dir ) ) {
if ( $ref->dir !== null ) {
// The following classes are generated here:
// * mw-cite-dir-ltr
// * mw-cite-dir-rtl
@ -165,7 +165,7 @@ class ReferenceListFormatter {
}
if ( $ref->count === 1 ) {
if ( !isset( $ref->name ) ) {
if ( $ref->name === null ) {
$id = $ref->key;
$backlinkId = $this->anchorFormatter->backLink( $ref->key );
} else {
@ -220,7 +220,7 @@ class ReferenceListFormatter {
private function renderTextAndWarnings(
Parser $parser, $key, ReferenceStackItem $ref, bool $isSectionPreview
): string {
if ( !isset( $ref->text ) ) {
if ( $ref->text === null ) {
return $this->errorReporter->plain( $parser,
$isSectionPreview
? 'cite_warning_sectionpreview_no_text'
@ -270,7 +270,7 @@ class ReferenceListFormatter {
private function referencesFormatEntryAlternateBacklinkLabel(
Parser $parser, int $offset
): ?string {
if ( !isset( $this->backlinkLabels ) ) {
if ( $this->backlinkLabels === null ) {
$msg = $this->messageLocalizer->msg( 'cite_references_link_many_format_backlink_labels' );
$this->backlinkLabels = $msg->isDisabled() ? [] : preg_split( '/\s+/', $msg->plain() );
}

View file

@ -153,9 +153,9 @@ class ReferenceStack {
$ref->number ??= ++$this->groupRefSequence[$group];
// 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];
if ( !isset( $parentRef ) ) {
if ( $parentRef === null ) {
// Create a new placeholder and give it the current sequence number.
$parentRef = new ReferenceStackItem();
$parentRef->name = $extends;
@ -347,7 +347,7 @@ class ReferenceStack {
$ref =& $this->refs[$group][$name];
$ref ??= new ReferenceStackItem();
$ref->placeholder = false;
if ( !isset( $ref->text ) ) {
if ( $ref->text === null ) {
$ref->text = $text;
} elseif ( $ref->text !== $text ) {
// two refs with same key and different content

View file

@ -63,7 +63,7 @@ class Validator {
$groupRefs = $this->referenceStack->getGroupRefs( $group );
// @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
return StatusValue::newFatal( 'cite_error_references_duplicate_key', $name );
} elseif ( isset( $groupRefs[$extends]->extends ) ) {