Replace complex for loop for foreach, count and break
authorReedy <reedy@wikimedia.org>
Sun, 11 May 2014 16:17:49 +0000 (17:17 +0100)
committerReedy <reedy@wikimedia.org>
Sun, 11 May 2014 20:27:32 +0000 (21:27 +0100)
Change-Id: If1d3193f9579ce6b0d3c790b234d56ea1fe73237

includes/ImageQueryPage.php

index b5bddf0..b0266cb 100644 (file)
@@ -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() );