Siebrand has uploaded a new change for review.
https://gerrit.wikimedia.org/r/275792
Change subject: Use identical comparison instead of equal where possible
......................................................................
Use identical comparison instead of equal where possible
Change-Id: I0ded83e529fdb2dc3a34b299d75799fd1bec2f87
---
M Expr.php
M ParserFunctions.hooks.php
M ParserFunctions_body.php
3 files changed, 46 insertions(+), 44 deletions(-)
git pull
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ParserFunctions
refs/changes/92/275792/1
diff --git a/Expr.php b/Expr.php
index ef98c26..394fd25 100644
--- a/Expr.php
+++ b/Expr.php
@@ -210,7 +210,7 @@
continue;
} elseif ( false !== strpos( EXPR_NUMBER_CLASS, $char )
) {
// Number
- if ( $expecting != 'expression' ) {
+ if ( $expecting !== 'expression' ) {
throw new ExprError(
'unexpected_number' );
}
@@ -240,14 +240,14 @@
switch( $op ) {
// constant
case EXPR_EXPONENT:
- if ( $expecting != 'expression' ) {
+ if ( $expecting !== 'expression' ) {
continue;
}
$operands[] = exp( 1 );
$expecting = 'operator';
continue 2;
case EXPR_PI:
- if ( $expecting != 'expression' ) {
+ if ( $expecting !== 'expression' ) {
throw new ExprError(
'unexpected_number' );
}
$operands[] = pi();
@@ -268,7 +268,7 @@
case EXPR_TRUNC:
case EXPR_CEIL:
case EXPR_SQRT:
- if ( $expecting != 'expression' ) {
+ if ( $expecting !== 'expression' ) {
throw new ExprError(
'unexpected_operator', $word );
}
$operators[] = $op;
@@ -280,15 +280,15 @@
// Next the two-character operators
- elseif ( $char2 == '<=' ) {
+ elseif ( $char2 === '<=' ) {
$name = $char2;
$op = EXPR_LESSEQ;
$p += 2;
- } elseif ( $char2 == '>=' ) {
+ } elseif ( $char2 === '>=' ) {
$name = $char2;
$op = EXPR_GREATEREQ;
$p += 2;
- } elseif ( $char2 == '<>' || $char2 == '!=' ) {
+ } elseif ( $char2 === '<>' || $char2 === '!=' ) {
$name = $char2;
$op = EXPR_NOTEQ;
$p += 2;
@@ -296,9 +296,9 @@
// Finally the single-character operators
- elseif ( $char == '+' ) {
+ elseif ( $char === '+' ) {
++$p;
- if ( $expecting == 'expression' ) {
+ if ( $expecting === 'expression' ) {
// Unary plus
$operators[] = EXPR_POSITIVE;
continue;
@@ -306,9 +306,9 @@
// Binary plus
$op = EXPR_PLUS;
}
- } elseif ( $char == '-' ) {
+ } elseif ( $char === '-' ) {
++$p;
- if ( $expecting == 'expression' ) {
+ if ( $expecting === 'expression' ) {
// Unary minus
$operators[] = EXPR_NEGATIVE;
continue;
@@ -316,26 +316,26 @@
// Binary minus
$op = EXPR_MINUS;
}
- } elseif ( $char == '*' ) {
+ } elseif ( $char === '*' ) {
$name = $char;
$op = EXPR_TIMES;
++$p;
- } elseif ( $char == '/' ) {
+ } elseif ( $char === '/' ) {
$name = $char;
$op = EXPR_DIVIDE;
++$p;
- } elseif ( $char == '^' ) {
+ } elseif ( $char === '^' ) {
$name = $char;
$op = EXPR_POW;
++$p;
- } elseif ( $char == '(' ) {
- if ( $expecting == 'operator' ) {
+ } elseif ( $char === '(' ) {
+ if ( $expecting === 'operator' ) {
throw new ExprError(
'unexpected_operator', '(' );
}
$operators[] = EXPR_OPEN;
++$p;
continue;
- } elseif ( $char == ')' ) {
+ } elseif ( $char === ')' ) {
$lastOp = end( $operators );
while ( $lastOp && $lastOp != EXPR_OPEN ) {
$this->doOperation( $lastOp, $operands
);
@@ -350,15 +350,15 @@
$expecting = 'operator';
++$p;
continue;
- } elseif ( $char == '=' ) {
+ } elseif ( $char === '=' ) {
$name = $char;
$op = EXPR_EQUALITY;
++$p;
- } elseif ( $char == '<' ) {
+ } elseif ( $char === '<' ) {
$name = $char;
$op = EXPR_LESS;
++$p;
- } elseif ( $char == '>' ) {
+ } elseif ( $char === '>' ) {
$name = $char;
$op = EXPR_GREATER;
++$p;
@@ -367,7 +367,7 @@
}
// Binary operator processing
- if ( $expecting == 'expression' ) {
+ if ( $expecting === 'expression' ) {
throw new ExprError( 'unexpected_operator',
$name );
}
diff --git a/ParserFunctions.hooks.php b/ParserFunctions.hooks.php
index bac580c..63ff756 100644
--- a/ParserFunctions.hooks.php
+++ b/ParserFunctions.hooks.php
@@ -60,7 +60,7 @@
}
public static function onScribuntoExternalLibraries( $engine, array
&$extraLibraries ) {
- if ( $engine == 'lua' ) {
+ if ( $engine === 'lua' ) {
$extraLibraries['mw.ext.ParserFunctions'] =
'Scribunto_LuaParserFunctionsLibrary';
}
return true;
diff --git a/ParserFunctions_body.php b/ParserFunctions_body.php
index 2651b06..3be2aa0 100644
--- a/ParserFunctions_body.php
+++ b/ParserFunctions_body.php
@@ -116,7 +116,7 @@
public static function ifeqObj( $parser, $frame, $args ) {
$left = isset( $args[0] ) ? self::decodeTrimExpand( $args[0],
$frame ) : '';
$right = isset( $args[1] ) ? self::decodeTrimExpand( $args[1],
$frame ) : '';
- if ( $left == $right ) {
+ if ( $left === $right ) {
return isset( $args[2] ) ? trim( $frame->expand(
$args[2] ) ) : '';
} else {
return isset( $args[3] ) ? trim( $frame->expand(
$args[3] ) ) : '';
@@ -165,7 +165,7 @@
* @return string
*/
public static function switchObj( $parser, $frame, $args ) {
- if ( count( $args ) == 0 ) {
+ if ( count( $args ) === 0 ) {
return '';
}
$primary = self::decodeTrimExpand( array_shift( $args ), $frame
);
@@ -188,7 +188,7 @@
return trim( $frame->expand( $valueNode
) );
} else {
$test = self::decodeTrimExpand(
$nameNode, $frame );
- if ( $test == $primary ) {
+ if ( $test === $primary ) {
# Found a match, return now
return trim( $frame->expand(
$valueNode ) );
} elseif ( $defaultFound ||
$mwDefault->matchStartToEnd( $test ) ) {
@@ -202,7 +202,7 @@
$lastItemHadNoEquals = true;
// $lastItem is an "out" variable
$decodedTest = self::decodeTrimExpand(
$valueNode, $frame, $lastItem );
- if ( $decodedTest == $primary ) {
+ if ( $decodedTest === $primary ) {
$found = true;
} elseif ( $mwDefault->matchStartToEnd(
$decodedTest ) ) {
$defaultFound = true;
@@ -236,22 +236,22 @@
public static function rel2abs( $parser , $to = '' , $from = '' ) {
$from = trim( $from );
- if ( $from == '' ) {
+ if ( $from === '' ) {
$from = $parser->getTitle()->getPrefixedText();
}
$to = rtrim( $to , ' /' );
// if we have an empty path, or just one containing a dot
- if ( $to == '' || $to == '.' ) {
+ if ( $to === '' || $to === '.' ) {
return $from;
}
// if the path isn't relative
- if ( substr( $to , 0 , 1 ) != '/' &&
- substr( $to , 0 , 2 ) != './' &&
- substr( $to , 0 , 3 ) != '../' &&
- $to != '..' )
+ if ( substr( $to , 0 , 1 ) !== '/' &&
+ substr( $to , 0 , 2 ) !== './' &&
+ substr( $to , 0 , 3 ) !== '../' &&
+ $to !== '..' )
{
$from = '';
}
@@ -270,7 +270,7 @@
$newExploded = array();
foreach ( $exploded as $current ) {
- if ( $current == '..' ) { // removing one level
+ if ( $current === '..' ) { // removing one level
if ( !count( $newExploded ) ) {
// attempted to access a node above
root node
$msg = wfMessage(
'pfunc_rel2abs_invalid_depth', $fullPath )->inContentLanguage()->escaped();
@@ -302,7 +302,7 @@
$title = Title::newFromText( $titletext );
$wgContLang->findVariantLink( $titletext, $title, true );
if ( $title ) {
- if ( $title->getNamespace() == NS_MEDIA ) {
+ if ( $title->getNamespace() === NS_MEDIA ) {
/* If namespace is specified as NS_MEDIA, then
we want to
* check the physical file, not the
"description" page.
*/
@@ -316,7 +316,7 @@
$parser->mOutput->addImage(
$file->getName(),
$file->getTimestamp(), $file->getSha1() );
return $file->exists() ? $then : $else;
- } elseif ( $title->getNamespace() == NS_SPECIAL ) {
+ } elseif ( $title->getNamespace() === NS_SPECIAL ) {
/* Don't bother with the count for special
pages,
* since their existence can be checked without
* accessing the database.
@@ -332,7 +332,7 @@
$pdbk = $title->getPrefixedDBkey();
$lc = LinkCache::singleton();
$id = $lc->getGoodLinkID( $pdbk );
- if ( $id != 0 ) {
+ if ( $id !== 0 ) {
$parser->mOutput->addLink( $title, $id
);
return $then;
} elseif ( $lc->isBadLink( $pdbk ) ) {
@@ -548,7 +548,7 @@
if ( $offset > 0 ) {
--$offset;
}
- if ( $parts == 0 ) {
+ if ( $parts === 0 ) {
return implode( '/', array_slice(
$bits, $offset ) );
} else {
return implode( '/', array_slice(
$bits, $offset, $parts ) );
@@ -614,7 +614,7 @@
return self::tooLongError();
}
- if ( $inNeedle == '' ) { $inNeedle = ' '; }
+ if ( $inNeedle === '' ) { $inNeedle = ' '; }
$pos = mb_strpos( $inStr, $inNeedle, intval( $inOffset ) );
if ( $pos === false ) { $pos = ""; }
@@ -643,7 +643,7 @@
return self::tooLongError();
}
- if ( $inNeedle == '' ) { $inNeedle = ' '; }
+ if ( $inNeedle === '' ) { $inNeedle = ' '; }
$pos = mb_strrpos( $inStr, $inNeedle );
if ( $pos === false ) { $pos = -1; }
@@ -676,7 +676,7 @@
return self::tooLongError();
}
- if ( intval( $inLength ) == 0 ) {
+ if ( intval( $inLength ) === 0 ) {
$result = mb_substr( $inStr, intval( $inStart ) );
} else {
$result = mb_substr( $inStr, intval( $inStart ),
intval( $inLength ) );
@@ -705,7 +705,7 @@
return self::tooLongError();
}
- if ( $inSubStr == '' ) {
+ if ( $inSubStr === '' ) {
$inSubStr = ' ';
}
@@ -743,7 +743,7 @@
return self::tooLongError();
}
- if ( $inReplaceFrom == '' ) { $inReplaceFrom = ' '; }
+ if ( $inReplaceFrom === '' ) { $inReplaceFrom = ' '; }
// Precompute limit to avoid generating enormous string:
$diff = mb_strlen( $inReplaceTo ) - mb_strlen( $inReplaceFrom );
@@ -755,7 +755,9 @@
$inLimit = intval( $inLimit );
if ( $inLimit >= 0 ) {
- if ( $limit > $inLimit || $limit == -1 ) { $limit =
$inLimit; }
+ if ( $limit > $inLimit || $limit === -1 ) {
+ $limit = $inLimit;
+ }
}
// Use regex to allow limit and handle UTF-8 correctly.
@@ -793,7 +795,7 @@
$inStr = $parser->killMarkers( (string)$inStr );
$inDiv = $parser->killMarkers( (string)$inDiv );
- if ( $inDiv == '' ) {
+ if ( $inDiv === '' ) {
$inDiv = ' ';
}
--
To view, visit https://gerrit.wikimedia.org/r/275792
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I0ded83e529fdb2dc3a34b299d75799fd1bec2f87
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/ParserFunctions
Gerrit-Branch: master
Gerrit-Owner: Siebrand <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits