jenkins-bot has submitted this change and it was merged. (
https://gerrit.wikimedia.org/r/354875 )
Change subject: Add phpcs and make pass
......................................................................
Add phpcs and make pass
Change-Id: I7fb0a09e0c23d29f89cd3c1fc6579c90ed4cec1f
---
M SpecialVipsTest.php
M VipsScaler_body.php
M composer.json
A phpcs.xml
M tests/phpunit/VipsScalerTest.php
5 files changed, 188 insertions(+), 169 deletions(-)
Approvals:
Hashar: Looks good to me, approved
jenkins-bot: Verified
diff --git a/SpecialVipsTest.php b/SpecialVipsTest.php
index 3e3fc99..89bd03b 100644
--- a/SpecialVipsTest.php
+++ b/SpecialVipsTest.php
@@ -37,7 +37,7 @@
$request = $this->getRequest();
$this->setHeaders();
- if( !$this->userCanExecute( $this->getUser() ) ) {
+ if ( !$this->userCanExecute( $this->getUser() ) ) {
$this->displayRestrictionError();
return;
}
@@ -54,12 +54,12 @@
protected function showThumbnails() {
$request = $this->getRequest();
- # Check if there is any input
+ // Check if there is any input
if ( !( $request->getText( 'file' ) ) ) {
return;
}
- # Check if valid file was provided
+ // Check if valid file was provided
$title = Title::newFromText( $request->getText( 'file' ),
NS_FILE );
if ( is_null( $title ) ) {
$this->getOutput()->addWikiMsg(
'vipsscaler-invalid-file' );
@@ -71,13 +71,13 @@
return;
}
- # Create options
+ // Create options
$width = $request->getInt( 'width' );
if ( !$width ) {
$this->getOutput()->addWikiMsg(
'vipsscaler-invalid-width' );
return;
}
- $vipsUrlOptions = array( 'thumb' => $file->getName(), 'width'
=> $width );
+ $vipsUrlOptions = [ 'thumb' => $file->getName(), 'width' =>
$width ];
if ( $request->getVal( 'sharpen' ) ) {
$vipsUrlOptions['sharpen'] = floatval(
$request->getVal( 'sharpen' ) );
}
@@ -85,57 +85,57 @@
$vipsUrlOptions['bilinear'] = 1;
}
- # Generate normal thumbnail
- $params = array( 'width' => $width );
+ // Generate normal thumbnail
+ $params = [ 'width' => $width ];
$thumb = $file->transform( $params );
if ( !$thumb || $thumb->isError() ) {
$this->getOutput()->addWikiMsg(
'vipsscaler-thumb-error' );
return;
}
- # Check if we actually scaled the file
+ // Check if we actually scaled the file
$normalThumbUrl = $thumb->getUrl();
if ( wfExpandUrl( $normalThumbUrl ) == $file->getFullUrl() ) {
// TODO: message
}
- # Make url to the vips thumbnail
+ // Make url to the vips thumbnail
$vipsThumbUrl = $this->getPageTitle()->getLocalUrl(
$vipsUrlOptions );
- # HTML for the thumbnails
- $thumbs = Html::rawElement( 'div', array( 'id' =>
'mw-vipstest-thumbnails' ),
- Html::element( 'img', array(
- 'src' =>
$normalThumbUrl,
- 'alt' => wfMessage(
'vipsscaler-default-thumb' ),
- ) ) . ' ' .
- Html::element( 'img', array(
- 'src' => $vipsThumbUrl,
- 'alt' => wfMessage(
'vipsscaler-vips-thumb' ),
- ) )
- );
+ // HTML for the thumbnails
+ $thumbs = Html::rawElement( 'div', [ 'id' =>
'mw-vipstest-thumbnails' ],
+ Html::element( 'img', [
+ 'src' => $normalThumbUrl,
+ 'alt' => wfMessage( 'vipsscaler-default-thumb'
),
+ ] ) . ' ' .
+ Html::element( 'img', [
+ 'src' => $vipsThumbUrl,
+ 'alt' => wfMessage( 'vipsscaler-vips-thumb' ),
+ ] )
+ );
- # Helper messages shown above the thumbnails rendering
+ // Helper messages shown above the thumbnails rendering
$help = wfMessage( 'vipsscaler-thumbs-help' )->parseAsBlock();
- # A checkbox to easily alternate between both views:
+ // A checkbox to easily alternate between both views:
$checkbox = Xml::checkLabel(
wfMessage( 'vipsscaler-thumbs-switch-label' ),
'mw-vipstest-thumbs-switch',
'mw-vipstest-thumbs-switch'
);
- # Wrap the three HTML snippets above in a fieldset:
+ // Wrap the three HTML snippets above in a fieldset:
$html = Xml::fieldset(
wfMessage( 'vipsscaler-thumbs-legend' ),
$help . $checkbox . $thumbs
);
- # Finally output all of the above
+ // Finally output all of the above
$this->getOutput()->addHTML( $html );
- $this->getOutput()->addModules( array(
+ $this->getOutput()->addModules( [
'ext.vipsscaler',
'jquery.ucompare',
- ) );
+ ] );
}
/**
@@ -145,14 +145,14 @@
$form = new HTMLForm( $this->getFormFields(),
$this->getContext() );
$form->setWrapperLegend( $this->msg( 'vipsscaler-form-legend'
)->text() );
$form->setSubmitText( $this->msg( 'vipsscaler-form-submit'
)->text() );
- $form->setSubmitCallback( array( __CLASS__, 'processForm' ) );
+ $form->setSubmitCallback( [ __CLASS__, 'processForm' ] );
$form->setMethod( 'get' );
// Looks like HTMLForm does not actually show the form if
submission
// was correct. So we have to show it again.
// See HTMLForm::show()
$result = $form->show();
- if( $result === true || $result instanceof Status &&
$result->isGood() ) {
+ if ( $result === true || $result instanceof Status &&
$result->isGood() ) {
$form->displayForm( $result );
$this->showThumbnails();
}
@@ -163,38 +163,38 @@
* @return Array A form structure using the HTMLForm system
*/
protected function getFormFields() {
- $fields = array(
- 'File' => array(
+ $fields = [
+ 'File' => [
'name' => 'file',
'class' => 'HTMLTextField',
'required' => true,
'size' => '80',
'label-message' => 'vipsscaler-form-file',
- 'validation-callback' => array( __CLASS__,
'validateFileInput' ),
- ),
- 'Width' => array(
+ 'validation-callback' => [ __CLASS__,
'validateFileInput' ],
+ ],
+ 'Width' => [
'name' => 'width',
'class' => 'HTMLIntField',
'default' => '640',
'size' => '5',
'required' => true,
'label-message' => 'vipsscaler-form-width',
- 'validation-callback' => array( __CLASS__,
'validateWidth' ),
- ),
- 'SharpenRadius' => array(
+ 'validation-callback' => [ __CLASS__,
'validateWidth' ],
+ ],
+ 'SharpenRadius' => [
'name' => 'sharpen',
'class' => 'HTMLFloatField',
'default' => '0.0',
'size' => '5',
'label-message' =>
'vipsscaler-form-sharpen-radius',
- 'validation-callback' => array( __CLASS__,
'validateSharpen' ),
- ),
- 'Bilinear' => array(
+ 'validation-callback' => [ __CLASS__,
'validateSharpen' ],
+ ],
+ 'Bilinear' => [
'name' => 'bilinear',
'class' => 'HTMLCheckField',
'label-message' => 'vipsscaler-form-bilinear',
- ),
- );
+ ],
+ ];
/**
* Match ImageMagick by default
@@ -213,16 +213,16 @@
*/
public static function validateFileInput( $input, $alldata ) {
if ( !trim( $input ) ) {
- # Don't show an error if the file is not yet specified,
- # because it is annoying
+ // Don't show an error if the file is not yet specified,
+ // because it is annoying
return true;
}
$title = Title::newFromText( $input, NS_FILE );
- if( is_null( $title ) ) {
+ if ( is_null( $title ) ) {
return wfMessage( 'vipsscaler-invalid-file' )->text();
}
- $file = wfFindFile( $title ); # @todo What does it do?
+ $file = wfFindFile( $title ); // @todo What does it do?
if ( !$file || !$file->exists() ) {
return wfMessage( 'vipsscaler-invalid-file' )->text();
}
@@ -238,8 +238,9 @@
*/
public static function validateWidth( $input, $allData ) {
if ( self::validateFileInput( $allData['File'], $allData ) !==
true
- || !trim( $allData['File'] ) ) {
- # Invalid file, error will already be shown at file
field
+ || !trim( $allData['File'] )
+ ) {
+ // Invalid file, error will already be shown at file
field
return true;
}
$title = Title::newFromText( $allData['File'], NS_FILE );
@@ -279,7 +280,7 @@
$request = $this->getRequest();
- # Validate title and file existance
+ // Validate title and file existance
$title = Title::newFromText( $request->getText( 'thumb' ),
NS_FILE );
if ( is_null( $title ) ) {
$this->streamError( 404, "VipsScaler: invalid title\n"
);
@@ -291,24 +292,24 @@
return;
}
- # Check if vips can handle this file
+ // Check if vips can handle this file
if ( VipsScaler::getVipsHandler( $file ) === false ) {
$this->streamError( 500, "VipsScaler: VIPS cannot
handle this file type\n" );
return;
}
- # Validate param string
+ // Validate param string
$handler = $file->getHandler();
- $params = array( 'width' => $request->getInt( 'width' ) );
+ $params = [ 'width' => $request->getInt( 'width' ) ];
if ( !$handler->normaliseParams( $file, $params ) ) {
$this->streamError( 500, "VipsScaler: invalid
parameters\n" );
return;
}
- # Get the thumbnail
+ // Get the thumbnail
if ( is_null( $wgVipsThumbnailerHost ) || $request->getBool(
'noproxy' ) ) {
- # No remote scaler, need to do it ourselves.
- # Emulate the BitmapHandlerTransform hook
+ // No remote scaler, need to do it ourselves.
+ // Emulate the BitmapHandlerTransform hook
$tmpFile = VipsCommand::makeTemp( $file->getExtension()
);
$tmpFile->bind( $this );
@@ -316,18 +317,18 @@
$dstUrl = '';
wfDebug( __METHOD__ . ": Creating vips thumbnail at
$dstPath\n" );
- $scalerParams = array(
- # The size to which the image will be resized
+ $scalerParams = [
+ // The size to which the image will be resized
'physicalWidth' => $params['physicalWidth'],
'physicalHeight' => $params['physicalHeight'],
'physicalDimensions' =>
"{$params['physicalWidth']}x{$params['physicalHeight']}",
- # The size of the image on the page
+ // The size of the image on the page
'clientWidth' => $params['width'],
'clientHeight' => $params['height'],
- # Comment as will be added to the EXIF of the
thumbnail
+ // Comment as will be added to the EXIF of the
thumbnail
'comment' => isset( $params['descriptionUrl'] )
?
"File source:
{$params['descriptionUrl']}" : '',
- # Properties of the original image
+ // Properties of the original image
'srcWidth' => $file->getWidth(),
'srcHeight' => $file->getHeight(),
'mimeType' => $file->getMimeType(),
@@ -335,43 +336,43 @@
'dstPath' => $dstPath,
'dstUrl' => $dstUrl,
'interlace' => $request->getVal( 'interlace',
false ),
- );
+ ];
- $options = array();
+ $options = [];
if ( $request->getBool( 'bilinear' ) ) {
$options['bilinear'] = true;
wfDebug( __METHOD__ . ": using bilinear
scaling\n" );
}
if ( $request->getVal( 'sharpen' ) && $request->getVal(
'sharpen' ) < 5 ) {
- # Limit sharpen sigma to 5, otherwise we have
to write huge convolution matrices
- $options['sharpen'] = array( 'sigma' =>
floatval( $request->getVal( 'sharpen' ) ) );
+ // Limit sharpen sigma to 5, otherwise we have
to write huge convolution matrices
+ $options['sharpen'] = [ 'sigma' => floatval(
$request->getVal( 'sharpen' ) ) ];
wfDebug( __METHOD__ . ": sharpening with radius
{$options['sharpen']}\n" );
}
- # Call the hook
+ // Call the hook
/** @var MediaTransformOutput $mto */
$mto = null;
VipsScaler::doTransform( $handler, $file,
$scalerParams, $options, $mto );
if ( $mto && !$mto->isError() ) {
wfDebug( __METHOD__ . ": streaming
thumbnail...\n" );
$this->getOutput()->disable();
- StreamFile::stream( $dstPath, array(
+ StreamFile::stream( $dstPath, [
"Cache-Control: public,
max-age=$wgVipsTestExpiry, s-maxage=$wgVipsTestExpiry",
'Expires: ' . gmdate( 'r ', time() +
$wgVipsTestExpiry )
- ) );
+ ] );
} else {
$this->streamError( 500, $mto->getHtmlMsg() );
}
- # Cleanup the temporary file
+ // Cleanup the temporary file
wfSuppressWarnings();
unlink( $dstPath );
wfRestoreWarnings();
} else {
- # Request the thumbnail at a remote scaler
+ // Request the thumbnail at a remote scaler
$url = wfExpandUrl( $request->getRequestURL(),
PROTO_INTERNAL );
- $url = wfAppendQuery( $url, array( 'noproxy' => '1' ) );
+ $url = wfAppendQuery( $url, [ 'noproxy' => '1' ] );
wfDebug( __METHOD__ . ": Getting vips thumb from remote
url $url\n" );
$bits = IP::splitHostAndPort( $wgVipsThumbnailerHost );
@@ -384,15 +385,15 @@
}
$proxy = IP::combineHostAndPort( $host, $port );
- $options = array(
+ $options = [
'method' => 'GET',
'proxy' => $proxy,
- );
+ ];
$req = MWHttpRequest::factory( $url, $options );
$status = $req->execute();
if ( $status->isOk() ) {
- # Disable output and stream the file
+ // Disable output and stream the file
$this->getOutput()->disable();
wfResetOutputBuffers();
header( 'Content-Type: ' . $file->getMimeType()
);
diff --git a/VipsScaler_body.php b/VipsScaler_body.php
index f36bf21..6c39f1d 100644
--- a/VipsScaler_body.php
+++ b/VipsScaler_body.php
@@ -41,7 +41,7 @@
* @return bool
*/
public static function onTransform( $handler, $file, &$params, &$mto ) {
- # Check $wgVipsConditions
+ // Check $wgVipsConditions
$options = self::getHandlerOptions( $handler, $file, $params );
if ( !$options ) {
wfDebug( "...\n" );
@@ -77,18 +77,18 @@
) {
$actualSrcPath .= $vipsCommands[0]->makePageArgument(
$params['page'] );
}
- # Execute the commands
+ // Execute the commands
/** @var VipsCommand $command */
foreach ( $vipsCommands as $i => $command ) {
- # Set input/output files
+ // Set input/output files
if ( $i == 0 && count( $vipsCommands ) == 1 ) {
- # Single command, so output directly to dstPath
+ // Single command, so output directly to dstPath
$command->setIO( $actualSrcPath,
$params['dstPath'] );
} elseif ( $i == 0 ) {
- # First command, input from srcPath, output to
temp
+ // First command, input from srcPath, output to
temp
$command->setIO( $actualSrcPath, 'v',
VipsCommand::TEMP_OUTPUT );
} elseif ( $i + 1 == count( $vipsCommands ) ) {
- # Last command, output to dstPath
+ // Last command, output to dstPath
$command->setIO( $vipsCommands[$i - 1],
$params['dstPath'] );
} else {
$command->setIO( $vipsCommands[$i - 1], 'v',
VipsCommand::TEMP_OUTPUT );
@@ -103,16 +103,16 @@
}
}
- # Set comment
+ // Set comment
if ( !empty( $options['setcomment'] ) && !empty(
$params['comment'] ) ) {
self::setJpegComment( $params['dstPath'],
$params['comment'] );
}
- # Set the output variable
+ // Set the output variable
$mto = new ThumbnailImage( $file, $params['dstUrl'],
$params['clientWidth'], $params['clientHeight'],
$params['dstPath'] );
- # Stop processing
+ // Stop processing
return false;
}
@@ -125,34 +125,34 @@
*/
public static function makeCommands( $handler, $file, $params, $options
) {
global $wgVipsCommand;
- $commands = array();
+ $commands = [];
- # Get the proper im_XXX2vips handler
+ // Get the proper im_XXX2vips handler
$vipsHandler = self::getVipsHandler( $file );
if ( !$vipsHandler ) {
- return array();
+ return [];
}
- # Check if we need to convert to a .v file first
+ // Check if we need to convert to a .v file first
if ( !empty( $options['preconvert'] ) ) {
- $commands[] = new VipsCommand( $wgVipsCommand, array(
$vipsHandler ) );
+ $commands[] = new VipsCommand( $wgVipsCommand, [
$vipsHandler ] );
}
- # Do the resizing
+ // Do the resizing
$rotation = 360 - $handler->getRotation( $file );
wfDebug( __METHOD__ . " rotating '{$file->getName()}' by
{$rotation}°\n" );
if ( empty( $options['bilinear'] ) ) {
# Calculate shrink factors. Offsetting by a small
amount is required
# because of rounding down of the target size by VIPS.
See 25990#c7
- #
+
# No need to invert source and physical dimensions.
They already got
# switched if needed.
- #
+
# Use sprintf() instead of plain string conversion so
that we can
# control the precision
- $rx = sprintf( "%.18e", $params['srcWidth'] /
($params['physicalWidth'] + 0.125) );
- $ry = sprintf( "%.18e", $params['srcHeight'] /
($params['physicalHeight'] + 0.125) );
+ $rx = sprintf( "%.18e", $params['srcWidth'] / (
$params['physicalWidth'] + 0.125 ) );
+ $ry = sprintf( "%.18e", $params['srcHeight'] / (
$params['physicalHeight'] + 0.125 ) );
wfDebug( sprintf(
"%s to shrink '%s'. Source: %sx%s, Physical:
%sx%s. Shrink factors (rx,ry) = %sx%s.\n",
@@ -160,7 +160,7 @@
$params['srcWidth'], $params['srcHeight'],
$params['physicalWidth'],
$params['physicalHeight'],
$rx, $ry
- ));
+ ) );
if (
floor( $params['srcWidth'] / round( $rx ) ) ==
$params['physicalWidth']
@@ -181,7 +181,7 @@
$shrinkCmd = 'shrink';
}
- $commands[] = new VipsCommand( $wgVipsCommand, array(
$shrinkCmd, $rx, $ry ) );
+ $commands[] = new VipsCommand( $wgVipsCommand, [
$shrinkCmd, $rx, $ry ] );
} else {
if ( $rotation % 180 == 90 ) {
$dstWidth = $params['physicalHeight'];
@@ -196,10 +196,10 @@
$params['srcWidth'], $params['srcHeight'],
$params['physicalWidth'],
$params['physicalHeight'],
$dstWidth, $dstHeight
- ));
+ ) );
$commands[] = new VipsCommand( $wgVipsCommand,
- array( 'im_resize_linear', $dstWidth,
$dstHeight ) );
+ [ 'im_resize_linear', $dstWidth, $dstHeight ] );
}
if ( !empty( $options['sharpen'] ) ) {
@@ -208,22 +208,22 @@
if ( !empty( $options['convolution'] ) ) {
$commands[] = new VipsConvolution( $wgVipsCommand,
- array( 'im_convf', $options['convolution'] ) );
+ [ 'im_convf', $options['convolution'] ] );
}
# Rotation
if ( $rotation % 360 != 0 && $rotation % 90 == 0 ) {
- $commands[] = new VipsCommand( $wgVipsCommand, array(
"im_rot{$rotation}" ) );
+ $commands[] = new VipsCommand( $wgVipsCommand, [
"im_rot{$rotation}" ] );
}
// Interlace
if ( isset( $params['interlace'] ) && $params['interlace'] ) {
list( $major, $minor ) = File::splitMime(
$file->getMimeType() );
- if ( $major == 'image' && in_array( $minor, array(
'jpeg', 'png' ) ) ) {
- $commands[] = new VipsCommand( $wgVipsCommand,
array( "{$minor}save", "--interlace" ));
+ if ( $major == 'image' && in_array( $minor, [ 'jpeg',
'png' ] ) ) {
+ $commands[] = new VipsCommand( $wgVipsCommand,
[ "{$minor}save", "--interlace" ] );
} else {
// File type unsupported for interlacing,
return empty array to cancel processing
- return array();
+ return [];
}
}
@@ -244,12 +244,12 @@
intval( round( $sigma * 3 ) ) : $params['radius'];
$norm = 0;
- $conv = array();
+ $conv = [];
- # Fill the matrix with a negative Gaussian distribution
+ // Fill the matrix with a negative Gaussian distribution
$variance = $sigma * $sigma;
for ( $x = -$radius; $x <= $radius; $x++ ) {
- $row = array();
+ $row = [];
for ( $y = -$radius; $y <= $radius; $y++ ) {
$z = -exp( -( $x*$x + $y*$y ) / ( 2 * $variance
) ) /
( 2 * pi() * $variance );
@@ -259,13 +259,13 @@
$conv[] = $row;
}
- # Calculate the scaling parameter to ensure that the mean of the
- # matrix is zero
+ // Calculate the scaling parameter to ensure that the mean of
the
+ // matrix is zero
$scale = - $conv[$radius][$radius] - $norm;
- # Set the center pixel to obtain a sharpening matrix
+ // Set the center pixel to obtain a sharpening matrix
$conv[$radius][$radius] = -$norm * 2;
- # Add the matrix descriptor
- array_unshift( $conv, array( $radius * 2 + 1, $radius * 2 + 1,
$scale, 0 ) );
+ // Add the matrix descriptor
+ array_unshift( $conv, [ $radius * 2 + 1, $radius * 2 + 1,
$scale, 0 ] );
return $conv;
}
@@ -357,7 +357,7 @@
public static function getVipsHandler( $file ) {
list( $major, $minor ) = File::splitMime( $file->getMimeType()
);
- if ( $major == 'image' && in_array( $minor, array( 'jpeg',
'png', 'tiff' ) ) ) {
+ if ( $major == 'image' && in_array( $minor, [ 'jpeg', 'png',
'tiff' ] ) ) {
return "im_{$minor}2vips";
} else {
return false;
@@ -464,8 +464,8 @@
*/
public function execute() {
# Build and escape the command string
- $env = array( 'IM_CONCURRENCY' => '1' );
- $limits = array( 'filesize' => 409600 );
+ $env = [ 'IM_CONCURRENCY' => '1' ];
+ $limits = [ 'filesize' => 409600 ];
$cmd = wfEscapeShellArg(
$this->vips,
array_shift( $this->args ),
@@ -482,7 +482,7 @@
# Cleanup temp file
if ( $retval != 0 && file_exists( $this->output ) ) {
- unlink ( $this->output );
+ unlink( $this->output );
}
if ( $this->removeInput ) {
unlink( $this->input );
@@ -562,8 +562,8 @@
wfDebug( __METHOD__ . ": Convolving image [\n" .
$convolutionString . "] \n" );
- $env = array( 'IM_CONCURRENCY' => '1' );
- $limits = array( 'filesize' => 409600 );
+ $env = [ 'IM_CONCURRENCY' => '1' ];
+ $limits = [ 'filesize' => 409600 ];
$cmd = wfEscapeShellArg(
$this->vips,
array_shift( $this->args ),
@@ -573,7 +573,7 @@
foreach ( $this->args as $arg ) {
$cmd .= ' ' . wfEscapeShellArg( $arg );
}
- # Execute
+ // Execute
$retval = 0;
$this->err = wfShellExecWithStderr( $cmd, $retval, $env,
$limits );
@@ -587,15 +587,15 @@
$this->err .= wfShellExecWithStderr( $formatCmd,
$retval, $env, $limits );
}
- # Cleanup temp file
+ // Cleanup temp file
if ( $retval != 0 && file_exists( $this->output ) ) {
- unlink ( $this->output );
+ unlink( $this->output );
}
if ( $this->removeInput ) {
unlink( $this->input );
}
- # Remove the temporary matrix file
+ // Remove the temporary matrix file
$tmpFile->purge();
$tmpOutput->purge();
@@ -607,12 +607,13 @@
*
* @see https://github.com/jcupitt/libvips/issues/344 for why we do this
* @param string $input Path to file
- * @return int Vips internal format number (common value 0 =
VIPS_FORMAT_UCHAR, 2 = VIPS_FORMAT_USHORT)
+ * @return int Vips internal format number
+ * (common value 0 = VIPS_FORMAT_UCHAR, 2 = VIPS_FORMAT_USHORT)
*/
function getFormat( $input ) {
$retval = 0;
$cmd = wfEscapeShellArg( $this->vips, 'im_header_int',
'format', $input );
- $res = wfShellExec( $cmd, $retval, array( 'IM_CONCURRENCY' =>
'1' ) );
+ $res = wfShellExec( $cmd, $retval, [ 'IM_CONCURRENCY' => '1' ]
);
$res = trim( $res );
if ( $retval !== 0 || !is_numeric( $res ) ) {
@@ -627,7 +628,8 @@
}
if ( $format === -1 || $format >= 6 ) {
// This will still work, but not something we expect to
ever get. So log.
- wfDebugLog( 'vips', __METHOD__ . ": Vips format value
is outside the range expected (got: $format)\n" );
+ wfDebugLog( 'vips', __METHOD__ . ": Vips format value
is outside the range expected " .
+ "(got: $format)\n" );
}
return $format;
diff --git a/composer.json b/composer.json
index 686b65b..b8f68fb 100644
--- a/composer.json
+++ b/composer.json
@@ -1,11 +1,14 @@
{
"require-dev": {
"jakub-onderka/php-parallel-lint": "0.9.2",
- "jakub-onderka/php-console-highlighter": "0.3.2"
+ "jakub-onderka/php-console-highlighter": "0.3.2",
+ "mediawiki/mediawiki-codesniffer": "0.7.2"
},
"scripts": {
+ "fix": "phpcbf",
"test": [
- "parallel-lint . --exclude vendor"
+ "parallel-lint . --exclude vendor",
+ "phpcs -p -s"
]
}
}
diff --git a/phpcs.xml b/phpcs.xml
new file mode 100644
index 0000000..ede6c5d
--- /dev/null
+++ b/phpcs.xml
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ruleset>
+ <rule ref="vendor/mediawiki/mediawiki-codesniffer/MediaWiki"/>
+ <file>.</file>
+ <arg name="extensions" value="php,php5,inc"/>
+ <arg name="encoding" value="utf8"/>
+ <exclude-pattern>vendor</exclude-pattern>
+ <exclude-pattern>node_modules</exclude-pattern>
+</ruleset>
diff --git a/tests/phpunit/VipsScalerTest.php b/tests/phpunit/VipsScalerTest.php
index d91b343..e43bedb 100644
--- a/tests/phpunit/VipsScalerTest.php
+++ b/tests/phpunit/VipsScalerTest.php
@@ -16,13 +16,13 @@
function testShrinkCommand( $params, $type, $expectedCommands ) {
// This file doesn't neccesarily need to actually exist
$fakeFile = $this->dataFile( "non-existent", $type );
- $actualCommands = VipsScaler::makeCommands( $this->handler,
$fakeFile, $params, array() );
+ $actualCommands = VipsScaler::makeCommands( $this->handler,
$fakeFile, $params, [] );
$this->assertEquals( $expectedCommands, $actualCommands );
}
function shrinkCommandProvider() {
global $wgVipsCommand;
- $paramBase = array(
+ $paramBase = [
'comment' => '',
'srcWidth' => 2048,
'srcHeight' => 1536,
@@ -33,61 +33,65 @@
'physicalHeight' => '768',
'clientWidth' => '1024',
'clientHeight' => '768',
- );
- return array(
- array(
+ ];
+ return [
+ [
$paramBase,
'image/tiff',
- array(
- new VipsCommand( $wgVipsCommand, array(
'shrink', 2, 2 ) )
- )
- ),
- array(
+ [
+ new VipsCommand( $wgVipsCommand, [
'shrink', 2, 2 ] )
+ ]
+ ],
+ [
$paramBase,
'image/png',
- array(
- new VipsCommand( $wgVipsCommand, array(
'shrink', 2, 2 ) )
- )
- ),
- array(
- array( 'page' => 3 ) + $paramBase,
+ [
+ new VipsCommand( $wgVipsCommand, [
'shrink', 2, 2 ] )
+ ]
+ ],
+ [
+ [ 'page' => 3 ] + $paramBase,
'image/tiff',
- array(
- new VipsCommand( $wgVipsCommand, array(
'shrink', 2, 2 ) )
- )
- ),
- array(
- array( 'physicalWidth' => 1065 ) + $paramBase,
+ [
+ new VipsCommand( $wgVipsCommand, [
'shrink', 2, 2 ] )
+ ]
+ ],
+ [
+ [ 'physicalWidth' => 1065 ] + $paramBase,
'image/tiff',
- array(
- new VipsCommand( $wgVipsCommand, array(
'im_shrink', $this->calcScale( 2048, 1065 ), $this->calcScale( 1536, 768 ) ) )
- )
- ),
- array(
- array( 'physicalHeight' => 1065 ) + $paramBase,
+ [
+ new VipsCommand( $wgVipsCommand, [
'im_shrink', $this->calcScale( 2048, 1065 ),
+ $this->calcScale( 1536, 768 ) ]
)
+ ]
+ ],
+ [
+ [ 'physicalHeight' => 1065 ] + $paramBase,
'image/tiff',
- array(
- new VipsCommand( $wgVipsCommand, array(
'im_shrink', $this->calcScale( 2048, 1024 ), $this->calcScale( 1536, 1065 ) ) )
- )
- ),
- array(
- array( 'physicalWidth' => 1065, 'page' => 5 ) +
$paramBase,
+ [
+ new VipsCommand( $wgVipsCommand, [
'im_shrink', $this->calcScale( 2048, 1024 ),
+ $this->calcScale( 1536, 1065 )
] )
+ ]
+ ],
+ [
+ [ 'physicalWidth' => 1065, 'page' => 5 ] +
$paramBase,
'image/tiff',
- array(
- new VipsCommand( $wgVipsCommand, array(
'im_shrink', $this->calcScale( 2048, 1065 ), $this->calcScale( 1536, 768 ) ) )
- )
- ),
- array(
- array( 'physicalWidth' => 1065 ) + $paramBase,
+ [
+ new VipsCommand( $wgVipsCommand, [
'im_shrink', $this->calcScale( 2048, 1065 ),
+ $this->calcScale( 1536, 768 ) ]
)
+ ]
+ ],
+ [
+ [ 'physicalWidth' => 1065 ] + $paramBase,
'image/png',
- array(
- new VipsCommand( $wgVipsCommand, array(
'shrink', $this->calcScale( 2048, 1065 ), $this->calcScale( 1536, 768 ) ) )
- )
- ),
- );
+ [
+ new VipsCommand( $wgVipsCommand, [
'shrink', $this->calcScale( 2048, 1065 ),
+ $this->calcScale( 1536, 768 ) ]
)
+ ]
+ ],
+ ];
}
private function calcScale( $srcDim, $finalDim ) {
- return sprintf( "%.18e", $srcDim / ($finalDim + 0.125) );
+ return sprintf( "%.18e", $srcDim / ( $finalDim + 0.125 ) );
}
}
--
To view, visit https://gerrit.wikimedia.org/r/354875
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I7fb0a09e0c23d29f89cd3c1fc6579c90ed4cec1f
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/VipsScaler
Gerrit-Branch: master
Gerrit-Owner: Umherirrender <[email protected]>
Gerrit-Reviewer: Hashar <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits