r90330 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r90329‎ | r90330 | r90331 >
Date:03:36, 18 June 2011
Author:neilk
Status:ok (Comments)
Tags:
Comment:
fix invocation of static function
Modified paths:
  • /trunk/phase3/tests/phpunit/includes/api/RandomImageGenerator.php (modified) (history)

Diff [purge]

Index: trunk/phase3/tests/phpunit/includes/api/RandomImageGenerator.php
@@ -161,6 +161,20 @@
162162 return $spec;
163163 }
164164
 165+ /**
 166+ * Given array( array('x' => 10, 'y' => 20), array( 'x' => 30, y=> 5 ) )
 167+ * returns "10,20 30,5"
 168+ * Useful for SVG and imagemagick command line arguments
 169+ * @param $shape: Array of arrays, each array containing x & y keys mapped to numeric values
 170+ * @return string
 171+ */
 172+ static function shapePointsToString( $shape ) {
 173+ $points = array();
 174+ foreach ( $shape as $point ) {
 175+ $points[] = $point['x'] . ',' . $point['y'];
 176+ }
 177+ return join( " ", $points );
 178+ }
165179
166180 /**
167181 * Based on image specification, write a very simple SVG file to disk.
@@ -179,7 +193,7 @@
180194 foreach ( $spec['draws'] as $drawSpec ) {
181195 $shape = $g->addChild( 'polygon' );
182196 $shape->addAttribute( 'fill', $drawSpec['fill'] );
183 - $shape->addAttribute( 'points', shapePointsToString( $drawSpec['shape'] ) );
 197+ $shape->addAttribute( 'points', self::shapePointsToString( $drawSpec['shape'] ) );
184198 };
185199 if ( ! $fh = fopen( $filename, 'w' ) ) {
186200 throw new Exception( "couldn't open $filename for writing" );
@@ -190,14 +204,6 @@
191205 }
192206 }
193207
194 - public function shapePointsToString( $shape ) {
195 - $points = array();
196 - foreach ( $shape as $point ) {
197 - $points[] = $point['x'] . ',' . $point['y'];
198 - }
199 - return join( " ", $points );
200 - }
201 -
202208 /**
203209 * Based on an image specification, write such an image to disk, using Imagick PHP extension
204210 * @param $spec: spec describing background and circles to draw
@@ -240,7 +246,7 @@
241247 $args[] = wfEscapeShellArg( "xc:" . $spec['fill'] );
242248 foreach( $spec['draws'] as $draw ) {
243249 $fill = $draw['fill'];
244 - $polygon = shapePointsToString( $draw['shape'] );
 250+ $polygon = self::shapePointsToString( $draw['shape'] );
245251 $drawCommand = "fill $fill polygon $polygon";
246252 $args[] = '-draw ' . wfEscapeShellArg( $drawCommand );
247253 }

Comments

#Comment by 😂 (talk | contribs)   17:33, 19 June 2011

Not sure why it needs to be static, but it's ok either way.

Status & tagging log