r105544 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r105543‎ | r105544 | r105545 >
Date:13:02, 8 December 2011
Author:hashar
Status:ok
Tags:
Comment:
clean up whitespace / reindent
Modified paths:
  • /trunk/phase3/tests/phpunit/includes/api/RandomImageGenerator.php (modified) (history)

Diff [purge]

Index: trunk/phase3/tests/phpunit/includes/api/RandomImageGenerator.php
@@ -27,11 +27,11 @@
2828 class RandomImageGenerator {
2929
3030 private $dictionaryFile;
31 - private $minWidth = 400;
32 - private $maxWidth = 800;
33 - private $minHeight = 400;
34 - private $maxHeight = 800;
35 - private $shapesToDraw = 5;
 31+ private $minWidth = 400 ;
 32+ private $maxWidth = 800 ;
 33+ private $minHeight = 400 ;
 34+ private $maxHeight = 800 ;
 35+ private $shapesToDraw = 5 ;
3636
3737 /**
3838 * Orientations: 0th row, 0th column, EXIF orientation code, rotation 2x2 matrix that is opposite of orientation
@@ -40,29 +40,29 @@
4141 * (we also would need a non-symmetric shape for the images to test those, like a letter F)
4242 */
4343 private static $orientations = array(
44 - array(
45 - '0thRow' => 'top',
46 - '0thCol' => 'left',
47 - 'exifCode' => 1,
48 - 'counterRotation' => array( array( 1, 0 ), array( 0, 1 ) )
 44+ array(
 45+ '0thRow' => 'top',
 46+ '0thCol' => 'left',
 47+ 'exifCode' => 1,
 48+ 'counterRotation' => array( array( 1, 0 ), array( 0, 1 ) )
4949 ),
50 - array(
 50+ array(
5151 '0thRow' => 'bottom',
52 - '0thCol' => 'right',
53 - 'exifCode' => 3,
54 - 'counterRotation' => array( array( -1, 0 ), array( 0, -1 ) )
 52+ '0thCol' => 'right',
 53+ 'exifCode' => 3,
 54+ 'counterRotation' => array( array( -1, 0 ), array( 0, -1 ) )
5555 ),
56 - array(
57 - '0thRow' => 'right',
58 - '0thCol' => 'top',
59 - 'exifCode' => 6,
60 - 'counterRotation' => array( array( 0, 1 ), array( 1, 0 ) )
 56+ array(
 57+ '0thRow' => 'right',
 58+ '0thCol' => 'top',
 59+ 'exifCode' => 6,
 60+ 'counterRotation' => array( array( 0, 1 ), array( 1, 0 ) )
6161 ),
62 - array(
63 - '0thRow' => 'left',
64 - '0thCol' => 'bottom',
65 - 'exifCode' => 8,
66 - 'counterRotation' => array( array( 0, -1 ), array( -1, 0 ) )
 62+ array(
 63+ '0thRow' => 'left',
 64+ '0thCol' => 'bottom',
 65+ 'exifCode' => 8,
 66+ 'counterRotation' => array( array( 0, -1 ), array( -1, 0 ) )
6767 )
6868 );
6969
@@ -76,10 +76,10 @@
7777
7878 // find the dictionary file, to generate random names
7979 if ( !isset( $this->dictionaryFile ) ) {
80 - foreach ( array(
81 - '/usr/share/dict/words',
82 - '/usr/dict/words',
83 - dirname( __FILE__ ) . '/words.txt' )
 80+ foreach ( array(
 81+ '/usr/share/dict/words',
 82+ '/usr/dict/words',
 83+ dirname( __FILE__ ) . '/words.txt' )
8484 as $dictionaryFile ) {
8585 if ( is_file( $dictionaryFile ) and is_readable( $dictionaryFile ) ) {
8686 $this->dictionaryFile = $dictionaryFile;
@@ -116,7 +116,7 @@
117117 */
118118 function getImageWriteMethod( $format ) {
119119 global $wgUseImageMagick, $wgImageMagickConvertCommand;
120 - if ( $format === 'svg' ) {
 120+ if ( $format === 'svg' ) {
121121 return 'writeSvg';
122122 } else {
123123 // figure out how to write images
@@ -125,7 +125,7 @@
126126 return 'writeImageWithApi';
127127 } elseif ( $wgUseImageMagick && $wgImageMagickConvertCommand && is_executable( $wgImageMagickConvertCommand ) ) {
128128 return 'writeImageWithCommandLine';
129 - }
 129+ }
130130 }
131131 throw new Exception( "RandomImageGenerator: could not find a suitable method to write images in '$format' format" );
132132 }
@@ -211,7 +211,7 @@
212212 */
213213 static function shapePointsToString( $shape ) {
214214 $points = array();
215 - foreach ( $shape as $point ) {
 215+ foreach ( $shape as $point ) {
216216 $points[] = $point['x'] . ',' . $point['y'];
217217 }
218218 return join( " ", $points );
@@ -224,16 +224,16 @@
225225 * @param $format: file format to write (which is obviously always svg here)
226226 * @param $filename: filename to write to
227227 */
228 - public function writeSvg( $spec, $format, $filename ) {
 228+ public function writeSvg( $spec, $format, $filename ) {
229229 $svg = new SimpleXmlElement( '<svg/>' );
230230 $svg->addAttribute( 'xmlns', 'http://www.w3.org/2000/svg' );
231 - $svg->addAttribute( 'version', '1.1' );
232 - $svg->addAttribute( 'width', $spec['width'] );
233 - $svg->addAttribute( 'height', $spec['height'] );
 231+ $svg->addAttribute( 'version', '1.1' );
 232+ $svg->addAttribute( 'width', $spec['width'] );
 233+ $svg->addAttribute( 'height', $spec['height'] );
234234 $g = $svg->addChild( 'g' );
235235 foreach ( $spec['draws'] as $drawSpec ) {
236236 $shape = $g->addChild( 'polygon' );
237 - $shape->addAttribute( 'fill', $drawSpec['fill'] );
 237+ $shape->addAttribute( 'fill', $drawSpec['fill'] );
238238 $shape->addAttribute( 'points', self::shapePointsToString( $drawSpec['shape'] ) );
239239 };
240240 if ( ! $fh = fopen( $filename, 'w' ) ) {
@@ -252,20 +252,20 @@
253253 * @param $filename: filename to write to
254254 */
255255 public function writeImageWithApi( $spec, $format, $filename ) {
256 - // this is a hack because I can't get setImageOrientation() to work. See below.
 256+ // this is a hack because I can't get setImageOrientation() to work. See below.
257257 global $wgExiv2Command;
258258
259259 $image = new Imagick();
260260 /**
261 - * If the format is 'jpg', will also add a random orientation -- the image will be drawn rotated with triangle points
 261+ * If the format is 'jpg', will also add a random orientation -- the image will be drawn rotated with triangle points
262262 * facing in some direction (0, 90, 180 or 270 degrees) and a countering rotation should turn the triangle points upward again
263263 */
264264 $orientation = self::$orientations[0]; // default is normal orientation
265265 if ( $format == 'jpg' ) {
266266 $orientation = self::$orientations[ array_rand( self::$orientations ) ];
267 - $spec = self::rotateImageSpec( $spec, $orientation['counterRotation'] );
 267+ $spec = self::rotateImageSpec( $spec, $orientation['counterRotation'] );
268268 }
269 -
 269+
270270 $image->newImage( $spec['width'], $spec['height'], new ImagickPixel( $spec['fill'] ) );
271271
272272 foreach ( $spec['draws'] as $drawSpec ) {
@@ -288,7 +288,7 @@
289289 $cmd = wfEscapeShellArg( $wgExiv2Command )
290290 . " -M "
291291 . wfEscapeShellArg( "set Exif.Image.Orientation " . $orientation['exifCode'] )
292 - . " "
 292+ . " "
293293 . wfEscapeShellArg( $filename );
294294
295295 $retval = 0;
@@ -302,7 +302,7 @@
303303 /**
304304 * Given an image specification, produce rotated version
305305 * This is used when simulating a rotated image capture with EXIF orientation
306 - * @param $spec Object returned by getImageSpec
 306+ * @param $spec Object returned by getImageSpec
307307 * @param $matrix 2x2 transformation matrix
308308 * @return transformed Spec
309309 */
@@ -313,8 +313,8 @@
314314 $correctionY = 0;
315315 if ( $dims['x'] < 0 ) {
316316 $correctionX = abs( $dims['x'] );
317 - }
318 - if ( $dims['y'] < 0 ) {
 317+ }
 318+ if ( $dims['y'] < 0 ) {
319319 $correctionY = abs( $dims['y'] );
320320 }
321321 $tSpec['width'] = abs( $dims['x'] );
@@ -322,7 +322,7 @@
323323 $tSpec['fill'] = $spec['fill'];
324324 $tSpec['draws'] = array();
325325 foreach( $spec['draws'] as $draw ) {
326 - $tDraw = array(
 326+ $tDraw = array(
327327 'fill' => $draw['fill'],
328328 'shape' => array()
329329 );
@@ -339,13 +339,13 @@
340340
341341 /**
342342 * Given a matrix and a pair of images, return new position
343 - * @param $matrix: 2x2 rotation matrix
 343+ * @param $matrix: 2x2 rotation matrix
344344 * @param $x: x-coordinate number
345345 * @param $y: y-coordinate number
346 - * @return Array transformed with properties x, y
 346+ * @return Array transformed with properties x, y
347347 */
348348 private static function matrixMultiply2x2( $matrix, $x, $y ) {
349 - return array(
 349+ return array(
350350 'x' => $x * $matrix[0][0] + $y * $matrix[0][1],
351351 'y' => $x * $matrix[1][0] + $y * $matrix[1][1]
352352 );
@@ -356,10 +356,10 @@
357357 * Based on an image specification, write such an image to disk, using the command line ImageMagick program ('convert').
358358 *
359359 * Sample command line:
360 - * $ convert -size 100x60 xc:rgb(90,87,45) \
361 - * -draw 'fill rgb(12,34,56) polygon 41,39 44,57 50,57 41,39' \
362 - * -draw 'fill rgb(99,123,231) circle 59,39 56,57' \
363 - * -draw 'fill rgb(240,12,32) circle 50,21 50,3' filename.png
 360+ * $ convert -size 100x60 xc:rgb(90,87,45) \
 361+ * -draw 'fill rgb(12,34,56) polygon 41,39 44,57 50,57 41,39' \
 362+ * -draw 'fill rgb(99,123,231) circle 59,39 56,57' \
 363+ * -draw 'fill rgb(240,12,32) circle 50,21 50,3' filename.png
364364 *
365365 * @param $spec: spec describing background and shapes to draw
366366 * @param $format: file format to write (unused by this method but kept so it has the same signature as writeImageWithApi)

Status & tagging log