Skip to content

Commit

Permalink
Code style and clean ups (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nyholm committed May 14, 2017
1 parent e129ff7 commit c532ca4
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 119 deletions.
25 changes: 7 additions & 18 deletions src/ServerRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Message\StreamInterface;
use Psr\Http\Message\UploadedFileInterface;
use Psr\Http\Message\UriInterface;

/**
Expand All @@ -14,34 +15,22 @@
*/
class ServerRequest extends Request implements ServerRequestInterface
{
/**
* @var array
*/
/** @var array */
private $attributes = [];

/**
* @var array
*/
/** @var array */
private $cookieParams = [];

/**
* @var null|array|object
*/
/** @var null|array|object */
private $parsedBody;

/**
* @var array
*/
/** @var array */
private $queryParams = [];

/**
* @var array
*/
/** @var array */
private $serverParams;

/**
* @var array
*/
/** @var UploadedFileInterface[] */
private $uploadedFiles = [];

/**
Expand Down
26 changes: 6 additions & 20 deletions src/Stream.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,36 +12,22 @@
*/
class Stream implements StreamInterface
{
/**
* A resource reference.
*
* @var resource
*/
/** @var resource A resource reference */
private $stream;

/**
* @var bool
*/
/** @var bool */
private $seekable;

/**
* @var bool
*/
/** @var bool */
private $readable;

/**
* @var bool
*/
/** @var bool */
private $writable;

/**
* @var array|mixed|null|void
*/
/** @var array|mixed|null|void */
private $uri;

/**
* @var int
*/
/** @var int */
private $size;

/** @var array Hash of readable and writable stream types */
Expand Down
92 changes: 12 additions & 80 deletions src/UploadedFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,53 +16,31 @@
*/
class UploadedFile implements UploadedFileInterface
{
/**
* @var int[]
*/
/** @var int[] */
private static $errors = [
UPLOAD_ERR_OK,
UPLOAD_ERR_INI_SIZE,
UPLOAD_ERR_FORM_SIZE,
UPLOAD_ERR_PARTIAL,
UPLOAD_ERR_NO_FILE,
UPLOAD_ERR_NO_TMP_DIR,
UPLOAD_ERR_CANT_WRITE,
UPLOAD_ERR_EXTENSION,
UPLOAD_ERR_OK, UPLOAD_ERR_INI_SIZE, UPLOAD_ERR_FORM_SIZE, UPLOAD_ERR_PARTIAL, UPLOAD_ERR_NO_FILE,
UPLOAD_ERR_NO_TMP_DIR, UPLOAD_ERR_CANT_WRITE, UPLOAD_ERR_EXTENSION,
];

/**
* @var string
*/
/** @var string */
private $clientFilename;

/**
* @var string
*/
/** @var string */
private $clientMediaType;

/**
* @var int
*/
/** @var int */
private $error;

/**
* @var null|string
*/
/** @var null|string */
private $file;

/**
* @var bool
*/
/** @var bool */
private $moved = false;

/**
* @var int
*/
/** @var int */
private $size;

/**
* @var StreamInterface|null
*/
/** @var StreamInterface|null */
private $stream;

/**
Expand Down Expand Up @@ -190,23 +168,13 @@ private function setClientMediaType($clientMediaType)
}

/**
* Return true if there is no upload error.
*
* @return bool
* @return bool Return true if there is no upload error.
*/
private function isOk()
{
return $this->error === UPLOAD_ERR_OK;
}

/**
* @return bool
*/
public function isMoved()
{
return $this->moved;
}

/**
* @throws RuntimeException if is moved or not ok
*/
Expand All @@ -216,16 +184,11 @@ private function validateActive()
throw new RuntimeException('Cannot retrieve stream due to upload error');
}

if ($this->isMoved()) {
if ($this->moved) {
throw new RuntimeException('Cannot retrieve stream after it has already been moved');
}
}

/**
* {@inheritdoc}
*
* @throws RuntimeException if the upload was not successful
*/
public function getStream()
{
$this->validateActive();
Expand All @@ -239,19 +202,6 @@ public function getStream()
return Stream::createFromResource($resource);
}

/**
* {@inheritdoc}
*
* @see http://php.net/is_uploaded_file
* @see http://php.net/move_uploaded_file
*
* @param string $targetPath Path to which to move the uploaded file
*
* @throws RuntimeException if the upload was not successful
* @throws InvalidArgumentException if the $path specified is invalid
* @throws RuntimeException on any error during the move operation, or on
* the second or subsequent call to the method
*/
public function moveTo($targetPath)
{
$this->validateActive();
Expand Down Expand Up @@ -282,34 +232,16 @@ public function moveTo($targetPath)
}
}

/**
* {@inheritdoc}
*
* @return int|null The file size in bytes or null if unknown
*/
public function getSize()
{
return $this->size;
}

/**
* {@inheritdoc}
*
* @see http://php.net/manual/en/features.file-upload.errors.php
*
* @return int One of PHP's UPLOAD_ERR_XXX constants
*/
public function getError()
{
return $this->error;
}

/**
* {@inheritdoc}
*
* @return string|null The filename sent by the client or null if none
* was provided
*/
public function getClientFilename()
{
return $this->clientFilename;
Expand Down
1 change: 0 additions & 1 deletion src/Uri.php
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,6 @@ private function applyParts(array $parts)
private static function createUriString($scheme, $authority, $path, $query, $fragment): string
{
$uri = '';

if ($scheme != '') {
$uri .= $scheme.':';
}
Expand Down

0 comments on commit c532ca4

Please sign in to comment.