From b0a6fd332a369d17a2e516e6744b145526acf011 Mon Sep 17 00:00:00 2001 From: Reedy Date: Sun, 11 May 2014 17:17:49 +0100 Subject: [PATCH] Replace complex for loop for foreach, count and break Change-Id: If1d3193f9579ce6b0d3c790b234d56ea1fe73237 --- includes/ImageQueryPage.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) 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() ); -- 2.20.1