Skip to content

Commit

Permalink
Code formatting, rip the bandaid off in one go
Browse files Browse the repository at this point in the history
  • Loading branch information
joehoyle committed Apr 3, 2016
1 parent 05e7837 commit 8cf788b
Show file tree
Hide file tree
Showing 6 changed files with 132 additions and 135 deletions.
8 changes: 4 additions & 4 deletions inc/class-s3-uploads-changed-files-iterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ public function accept() {
if ( $current->getMTime() > $data[1] ) {
WP_CLI::line( "(dry-run) Uploading {$current->getPathname()}" );
}
return false;
return false;
}

$key = $this->sourceConverter->convert((string) $current);
if (!($data = $this->getTargetData($key))) {
$key = $this->sourceConverter->convert( (string) $current );
if ( ! ( $data = $this->getTargetData( $key ) ) ) {
return true;
}

// Ensure it hasn't been modified since the mtime
return $current->getMTime() > $data[1];
}
}
}
156 changes: 76 additions & 80 deletions inc/class-s3-uploads-local-stream-wrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class S3_Uploads_Local_Stream_Wrapper {
*
* @var resource
*/
public $handle = NULL;
public $handle = null;

/**
* Instance URI (stream).
Expand All @@ -40,7 +40,7 @@ static function getDirectoryPath() {
return $upload_dir['basedir'] . '/s3';
}

function setUri($uri) {
function setUri( $uri ) {
$this->uri = $uri;
}

Expand All @@ -64,45 +64,45 @@ function getUri() {
* Returns a string representing a location suitable for writing of a file,
* or FALSE if unable to write to the file such as with read-only streams.
*/
protected function getTarget($uri = NULL) {
if (!isset($uri)) {
protected function getTarget( $uri = null ) {
if ( ! isset( $uri ) ) {
$uri = $this->uri;
}

list($scheme, $target) = explode('://', $uri, 2);
list( $scheme, $target) = explode( '://', $uri, 2 );

// Remove erroneous leading or trailing, forward-slashes and backslashes.
return trim($target, '\/');
return trim( $target, '\/' );
}

static function getMimeType($uri, $mapping = NULL) {
static function getMimeType( $uri, $mapping = null ) {

$extension = '';
$file_parts = explode('.', basename($uri));
$file_parts = explode( '.', basename( $uri ) );

// Remove the first part: a full filename should not match an extension.
array_shift($file_parts);
array_shift( $file_parts );

// Iterate over the file parts, trying to find a match.
// For my.awesome.image.jpeg, we try:
// - jpeg
// - image.jpeg, and
// - awesome.image.jpeg
while ($additional_part = array_pop($file_parts)) {
$extension = strtolower($additional_part . ($extension ? '.' . $extension : ''));
if (isset($mapping['extensions'][$extension])) {
return $mapping['mimetypes'][$mapping['extensions'][$extension]];
// - jpeg
// - image.jpeg, and
// - awesome.image.jpeg
while ( $additional_part = array_pop( $file_parts ) ) {
$extension = strtolower( $additional_part . ( $extension ? '.' . $extension : '' ) );
if ( isset( $mapping['extensions'][ $extension ] ) ) {
return $mapping['mimetypes'][ $mapping['extensions'][ $extension ] ];
}
}

return 'application/octet-stream';
}

function chmod($mode) {
$output = @chmod($this->getLocalPath(), $mode);
function chmod( $mode ) {
$output = @chmod( $this->getLocalPath(), $mode );
// We are modifying the underlying file here, so we have to clear the stat
// cache so that PHP understands that URI has changed too.
clearstatcache(TRUE, $this->getLocalPath());
clearstatcache( true, $this->getLocalPath() );
return $output;
}

Expand All @@ -123,17 +123,17 @@ function realpath() {
* path, as determined by the realpath() function. If $uri is set but not
* valid, returns FALSE.
*/
protected function getLocalPath($uri = NULL) {
if (!isset($uri)) {
protected function getLocalPath( $uri = null ) {
if ( ! isset( $uri ) ) {
$uri = $this->uri;
}
$path = $this->getDirectoryPath() . '/' . $this->getTarget($uri);
$path = $this->getDirectoryPath() . '/' . $this->getTarget( $uri );
$realpath = $path;

$directory = realpath($this->getDirectoryPath());

if (!$realpath || !$directory || strpos($realpath, $directory) !== 0) {
return FALSE;
$directory = realpath( $this->getDirectoryPath() );

if ( ! $realpath || ! $directory || strpos( $realpath, $directory ) !== 0 ) {
return false;
}
return $realpath;
}
Expand All @@ -155,12 +155,12 @@ protected function getLocalPath($uri = NULL) {
*
* @see http://php.net/manual/streamwrapper.stream-open.php
*/
public function stream_open($uri, $mode, $options, &$opened_path) {
public function stream_open( $uri, $mode, $options, &$opened_path ) {
$this->uri = $uri;
$path = $this->getLocalPath();
$this->handle = ($options & STREAM_REPORT_ERRORS) ? fopen($path, $mode) : @fopen($path, $mode);
$this->handle = ( $options & STREAM_REPORT_ERRORS ) ? fopen( $path, $mode ) : @fopen( $path, $mode );

if ((bool) $this->handle && $options & STREAM_USE_PATH) {
if ( (bool) $this->handle && $options & STREAM_USE_PATH ) {
$opened_path = $path;
}

Expand All @@ -183,12 +183,12 @@ public function stream_open($uri, $mode, $options, &$opened_path) {
*
* @see http://php.net/manual/streamwrapper.stream-lock.php
*/
public function stream_lock($operation) {
if (in_array($operation, array(LOCK_SH, LOCK_EX, LOCK_UN, LOCK_NB))) {
return flock($this->handle, $operation);
public function stream_lock( $operation ) {
if ( in_array( $operation, array( LOCK_SH, LOCK_EX, LOCK_UN, LOCK_NB ) ) ) {
return flock( $this->handle, $operation );
}

return TRUE;
return true;
}

/**
Expand All @@ -202,8 +202,8 @@ public function stream_lock($operation) {
*
* @see http://php.net/manual/streamwrapper.stream-read.php
*/
public function stream_read($count) {
return fread($this->handle, $count);
public function stream_read( $count ) {
return fread( $this->handle, $count );
}

/**
Expand All @@ -217,8 +217,8 @@ public function stream_read($count) {
*
* @see http://php.net/manual/streamwrapper.stream-write.php
*/
public function stream_write($data) {
return fwrite($this->handle, $data);
public function stream_write( $data ) {
return fwrite( $this->handle, $data );
}

/**
Expand All @@ -230,7 +230,7 @@ public function stream_write($data) {
* @see http://php.net/manual/streamwrapper.stream-eof.php
*/
public function stream_eof() {
return feof($this->handle);
return feof( $this->handle );
}

/**
Expand All @@ -246,10 +246,10 @@ public function stream_eof() {
*
* @see http://php.net/manual/streamwrapper.stream-seek.php
*/
public function stream_seek($offset, $whence) {
public function stream_seek( $offset, $whence ) {
// fseek returns 0 on success and -1 on a failure.
// stream_seek 1 on success and 0 on a failure.
return !fseek($this->handle, $offset, $whence);
return ! fseek( $this->handle, $offset, $whence );
}

/**
Expand All @@ -261,7 +261,7 @@ public function stream_seek($offset, $whence) {
* @see http://php.net/manual/streamwrapper.stream-flush.php
*/
public function stream_flush() {
return fflush($this->handle);
return fflush( $this->handle );
}

/**
Expand All @@ -273,7 +273,7 @@ public function stream_flush() {
* @see http://php.net/manual/streamwrapper.stream-tell.php
*/
public function stream_tell() {
return ftell($this->handle);
return ftell( $this->handle );
}

/**
Expand All @@ -286,7 +286,7 @@ public function stream_tell() {
* @see http://php.net/manual/streamwrapper.stream-stat.php
*/
public function stream_stat() {
return fstat($this->handle);
return fstat( $this->handle );
}

/**
Expand All @@ -298,7 +298,7 @@ public function stream_stat() {
* @see http://php.net/manual/streamwrapper.stream-close.php
*/
public function stream_close() {
return fclose($this->handle);
return fclose( $this->handle );
}

/**
Expand All @@ -313,7 +313,7 @@ public function stream_close() {
*
* @see http://php.net/manual/streamwrapper.stream-cast.php
*/
public function stream_cast($cast_as) {
public function stream_cast( $cast_as ) {
return false;
}

Expand All @@ -328,9 +328,9 @@ public function stream_cast($cast_as) {
*
* @see http://php.net/manual/streamwrapper.unlink.php
*/
public function unlink($uri) {
public function unlink( $uri ) {
$this->uri = $uri;
return unlink($this->getLocalPath());
return unlink( $this->getLocalPath() );
}

/**
Expand All @@ -346,8 +346,8 @@ public function unlink($uri) {
*
* @see http://php.net/manual/streamwrapper.rename.php
*/
public function rename($from_uri, $to_uri) {
return rename($this->getLocalPath($from_uri), $this->getLocalPath($to_uri));
public function rename( $from_uri, $to_uri ) {
return rename( $this->getLocalPath( $from_uri ), $this->getLocalPath( $to_uri ) );
}

/**
Expand All @@ -365,22 +365,20 @@ public function rename($from_uri, $to_uri) {
*
* @see http://php.net/manual/streamwrapper.mkdir.php
*/
public function mkdir($uri, $mode, $options) {
public function mkdir( $uri, $mode, $options ) {
$this->uri = $uri;
$recursive = (bool) ($options & STREAM_MKDIR_RECURSIVE);
if ($recursive) {
if ( $recursive ) {
// $this->getLocalPath() fails if $uri has multiple levels of directories
// that do not yet exist.
$localpath = $this->getDirectoryPath() . '/' . $this->getTarget($uri);
}
else {
$localpath = $this->getLocalPath($uri);
}
if ($options & STREAM_REPORT_ERRORS) {
return mkdir($localpath, $mode, $recursive);
$localpath = $this->getDirectoryPath() . '/' . $this->getTarget( $uri );
} else {
$localpath = $this->getLocalPath( $uri );
}
else {
return @mkdir($localpath, $mode, $recursive);
if ( $options & STREAM_REPORT_ERRORS ) {
return mkdir( $localpath, $mode, $recursive );
} else {
return @mkdir( $localpath, $mode, $recursive );
}
}

Expand All @@ -397,13 +395,12 @@ public function mkdir($uri, $mode, $options) {
*
* @see http://php.net/manual/streamwrapper.rmdir.php
*/
public function rmdir($uri, $options) {
public function rmdir( $uri, $options ) {
$this->uri = $uri;
if ($options & STREAM_REPORT_ERRORS) {
return rmdir($this->getLocalPath());
}
else {
return @rmdir($this->getLocalPath());
if ( $options & STREAM_REPORT_ERRORS ) {
return rmdir( $this->getLocalPath() );
} else {
return @rmdir( $this->getLocalPath() );
}
}

Expand All @@ -421,16 +418,15 @@ public function rmdir($uri, $options) {
*
* @see http://php.net/manual/streamwrapper.url-stat.php
*/
public function url_stat($uri, $flags) {
public function url_stat( $uri, $flags ) {
$this->uri = $uri;
$path = $this->getLocalPath();
// Suppress warnings if requested or if the file or directory does not
// exist. This is consistent with PHP's plain filesystem stream wrapper.
if ($flags & STREAM_URL_STAT_QUIET || !file_exists($path)) {
return @stat($path);
}
else {
return stat($path);
if ( $flags & STREAM_URL_STAT_QUIET || ! file_exists( $path ) ) {
return @stat( $path );
} else {
return stat( $path );
}
}

Expand All @@ -447,9 +443,9 @@ public function url_stat($uri, $flags) {
*
* @see http://php.net/manual/streamwrapper.dir-opendir.php
*/
public function dir_opendir($uri, $options) {
public function dir_opendir( $uri, $options ) {
$this->uri = $uri;
$this->handle = opendir($this->getLocalPath());
$this->handle = opendir( $this->getLocalPath() );

return (bool) $this->handle;
}
Expand All @@ -463,7 +459,7 @@ public function dir_opendir($uri, $options) {
* @see http://php.net/manual/streamwrapper.dir-readdir.php
*/
public function dir_readdir() {
return readdir($this->handle);
return readdir( $this->handle );
}

/**
Expand All @@ -475,11 +471,11 @@ public function dir_readdir() {
* @see http://php.net/manual/streamwrapper.dir-rewinddir.php
*/
public function dir_rewinddir() {
rewinddir($this->handle);
rewinddir( $this->handle );
// We do not really have a way to signal a failure as rewinddir() does not
// have a return value and there is no way to read a directory handler
// without advancing to the next file.
return TRUE;
return true;
}

/**
Expand All @@ -491,9 +487,9 @@ public function dir_rewinddir() {
* @see http://php.net/manual/streamwrapper.dir-closedir.php
*/
public function dir_closedir() {
closedir($this->handle);
closedir( $this->handle );
// We do not really have a way to signal a failure as closedir() does not
// have a return value.
return TRUE;
return true;
}
}
}
Loading

0 comments on commit 8cf788b

Please sign in to comment.