From: Reedy Date: Sun, 11 May 2014 16:17:49 +0000 (+0100) Subject: Replace complex for loop for foreach, count and break X-Git-Tag: 1.31.0-rc.0~15749 X-Git-Url: http://git.cyclocoop.org/%7B%24admin_url%7Dcompta/comptes/journal.php?a=commitdiff_plain;h=b0a6fd332a369d17a2e516e6744b145526acf011;p=lhc%2Fweb%2Fwiklou.git Replace complex for loop for foreach, count and break Change-Id: If1d3193f9579ce6b0d3c790b234d56ea1fe73237 --- diff --git a/includes/ImageQueryPage.php b/includes/ImageQueryPage.php index b5bddf03bc..b0266cbaf7 100644 --- a/includes/ImageQueryPage.php +++ b/includes/ImageQueryPage.php @@ -47,14 +47,17 @@ abstract class ImageQueryPage extends QueryPage { # $res might contain the whole 1,000 rows, so we read up to # $num [should update this to use a Pager] - // @codingStandardsIgnoreStart Generic.CodeAnalysis.ForLoopWithTestFunctionCall.NotAllowed - for ( $i = 0; $i < $num && $row = $dbr->fetchObject( $res ); $i++ ) { - // @codingStandardsIgnoreEnd + $i = 0; + foreach ( $res as $row ) { + $i++; $namespace = isset( $row->namespace ) ? $row->namespace : NS_FILE; $title = Title::makeTitleSafe( $namespace, $row->title ); if ( $title instanceof Title && $title->getNamespace() == NS_FILE ) { $gallery->add( $title, $this->getCellHtml( $row ) ); } + if ( $i === $num ) { + break; + } } $out->addHTML( $gallery->toHtml() );