r81904 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r81903‎ | r81904 | r81905 >
Date:17:13, 10 February 2011
Author:platonides
Status:ok (Comments)
Tags:
Comment:
Convert the if into an early exit. Whitespace ignoring diff recommended.
Modified paths:
  • /trunk/phase3/includes/Article.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/Article.php
@@ -1831,25 +1831,25 @@
18321832 // Delete if changing from redirect to non-redirect
18331833 $isRedirect = !is_null( $redirectTitle );
18341834
1835 - if ( $isRedirect || is_null( $lastRevIsRedirect ) || $lastRevIsRedirect !== $isRedirect ) {
1836 - wfProfileIn( __METHOD__ );
1837 - if ( $isRedirect ) {
1838 - $this->insertRedirectEntry( $redirectTitle );
1839 - } else {
1840 - // This is not a redirect, remove row from redirect table
1841 - $where = array( 'rd_from' => $this->getId() );
1842 - $dbw->delete( 'redirect', $where, __METHOD__ );
1843 - }
 1835+ if ( !$isRedirect && !is_null( $lastRevIsRedirect ) && $lastRevIsRedirect === $isRedirect ) {
 1836+ return true;
 1837+ }
 1838+
 1839+ wfProfileIn( __METHOD__ );
 1840+ if ( $isRedirect ) {
 1841+ $this->insertRedirectEntry( $redirectTitle );
 1842+ } else {
 1843+ // This is not a redirect, remove row from redirect table
 1844+ $where = array( 'rd_from' => $this->getId() );
 1845+ $dbw->delete( 'redirect', $where, __METHOD__ );
 1846+ }
18441847
1845 - if ( $this->getTitle()->getNamespace() == NS_FILE ) {
1846 - RepoGroup::singleton()->getLocalRepo()->invalidateImageRedirect( $this->getTitle() );
1847 - }
1848 - wfProfileOut( __METHOD__ );
1849 -
1850 - return ( $dbw->affectedRows() != 0 );
 1848+ if ( $this->getTitle()->getNamespace() == NS_FILE ) {
 1849+ RepoGroup::singleton()->getLocalRepo()->invalidateImageRedirect( $this->getTitle() );
18511850 }
 1851+ wfProfileOut( __METHOD__ );
18521852
1853 - return true;
 1853+ return ( $dbw->affectedRows() != 0 );
18541854 }
18551855
18561856 /**

Comments

#Comment by Aaron Schulz (talk | contribs)   04:25, 15 June 2011

+if ( !$isRedirect && !is_null( $lastRevIsRedirect ) && $lastRevIsRedirect === $isRedirect )

Can't you go beyond DeMorgan's here with the "$lastRevIsRedirect === $isRedirect" bit? By that point $isRedirect must be false (PHP would have short-circuited out already were it not).

Status & tagging log