Laravel version update

Laravel version update
This commit is contained in:
Manish Verma
2018-08-06 18:48:58 +05:30
parent d143048413
commit 126fbb0255
13678 changed files with 1031482 additions and 778530 deletions

View File

@@ -185,7 +185,7 @@ class Count extends AbstractValidator
if (is_array($file)) {
foreach ($file as $name) {
if (!isset($this->files[$name]) && !empty($name)) {
if (! isset($this->files[$name]) && ! empty($name)) {
$this->files[$name] = $name;
}
}
@@ -205,7 +205,7 @@ class Count extends AbstractValidator
*/
public function isValid($value, $file = null)
{
if (($file !== null) && !array_key_exists('destination', $file)) {
if (($file !== null) && ! array_key_exists('destination', $file)) {
$file['destination'] = dirname($value);
}
@@ -213,7 +213,7 @@ class Count extends AbstractValidator
$value = $file['destination'] . DIRECTORY_SEPARATOR . $file['name'];
}
if (($file === null) || !empty($file['tmp_name'])) {
if (($file === null) || ! empty($file['tmp_name'])) {
$this->addFile($value);
}

View File

@@ -56,7 +56,7 @@ class Crc32 extends Hash
* Sets the crc32 hash for one or multiple files
*
* @param string|array $options
* @return Crc32 Provides a fluent interface
* @return self Provides a fluent interface
*/
public function setCrc32($options)
{
@@ -68,7 +68,7 @@ class Crc32 extends Hash
* Adds the crc32 hash for one or multiple files
*
* @param string|array $options
* @return Crc32 Provides a fluent interface
* @return self Provides a fluent interface
*/
public function addCrc32($options)
{
@@ -90,7 +90,7 @@ class Crc32 extends Hash
$filename = $file['name'];
$file = $file['tmp_name'];
} elseif (is_array($value)) {
if (!isset($value['tmp_name']) || !isset($value['name'])) {
if (! isset($value['tmp_name']) || ! isset($value['name'])) {
throw new Exception\InvalidArgumentException(
'Value array must be in $_FILES format'
);
@@ -104,12 +104,12 @@ class Crc32 extends Hash
$this->setValue($filename);
// Is file readable ?
if (empty($file) || false === stream_resolve_include_path($file)) {
if (empty($file) || false === is_readable($file)) {
$this->error(self::NOT_FOUND);
return false;
}
$hashes = array_unique(array_keys($this->getHash()));
$hashes = array_unique(array_keys($this->getHash()));
$filehash = hash_file('crc32', $file);
if ($filehash === false) {
$this->error(self::NOT_DETECTED);

View File

@@ -45,7 +45,7 @@ class ExcludeExtension extends Extension
$filename = $file['name'];
$file = $file['tmp_name'];
} elseif (is_array($value)) {
if (!isset($value['tmp_name']) || !isset($value['name'])) {
if (! isset($value['tmp_name']) || ! isset($value['name'])) {
throw new Exception\InvalidArgumentException(
'Value array must be in $_FILES format'
);
@@ -59,7 +59,7 @@ class ExcludeExtension extends Extension
$this->setValue($filename);
// Is file readable ?
if (empty($file) || false === stream_resolve_include_path($file)) {
if (empty($file) || false === is_readable($file)) {
$this->error(self::NOT_FOUND);
return false;
}
@@ -67,9 +67,9 @@ class ExcludeExtension extends Extension
$extension = substr($filename, strrpos($filename, '.') + 1);
$extensions = $this->getExtension();
if ($this->getCase() && (!in_array($extension, $extensions))) {
if ($this->getCase() && (! in_array($extension, $extensions))) {
return true;
} elseif (!$this->getCase()) {
} elseif (! $this->getCase()) {
foreach ($extensions as $ext) {
if (strtolower($ext) == strtolower($extension)) {
$this->error(self::FALSE_EXTENSION);

View File

@@ -47,7 +47,7 @@ class ExcludeMimeType extends MimeType
$filetype = $file['type'];
$file = $file['tmp_name'];
} elseif (is_array($value)) {
if (!isset($value['tmp_name']) || !isset($value['name']) || !isset($value['type'])) {
if (! isset($value['tmp_name']) || ! isset($value['name']) || ! isset($value['type'])) {
throw new Exception\InvalidArgumentException(
'Value array must be in $_FILES format'
);
@@ -63,14 +63,14 @@ class ExcludeMimeType extends MimeType
$this->setValue($filename);
// Is file readable ?
if (empty($file) || false === stream_resolve_include_path($file)) {
if (empty($file) || false === is_readable($file)) {
$this->error(self::NOT_READABLE);
return false;
}
$mimefile = $this->getMagicFile();
if (class_exists('finfo', false)) {
if (!$this->isMagicFileDisabled() && (!empty($mimefile) && empty($this->finfo))) {
if (! $this->isMagicFileDisabled() && (! empty($mimefile) && empty($this->finfo))) {
$this->finfo = finfo_open(FILEINFO_MIME_TYPE, $mimefile);
}
@@ -79,7 +79,7 @@ class ExcludeMimeType extends MimeType
}
$this->type = null;
if (!empty($this->finfo)) {
if (! empty($this->finfo)) {
$this->type = finfo_file($this->finfo, $file);
}
}

View File

@@ -56,7 +56,7 @@ class Exists extends AbstractValidator
$options = explode(',', $options);
}
if (is_array($options) && !array_key_exists('directory', $options)) {
if (is_array($options) && ! array_key_exists('directory', $options)) {
$options = ['directory' => $options];
}
@@ -103,18 +103,18 @@ class Exists extends AbstractValidator
public function addDirectory($directory)
{
$directories = $this->getDirectory(true);
if (!isset($directories)) {
if (! isset($directories)) {
$directories = [];
}
if (is_string($directory)) {
$directory = explode(',', $directory);
} elseif (!is_array($directory)) {
} elseif (! is_array($directory)) {
throw new Exception\InvalidArgumentException('Invalid options to validator provided');
}
foreach ($directory as $content) {
if (empty($content) || !is_string($content)) {
if (empty($content) || ! is_string($content)) {
continue;
}
@@ -129,7 +129,7 @@ class Exists extends AbstractValidator
}
}
$this->options['directory'] = (!empty($directory))
$this->options['directory'] = (! empty($directory))
? implode(',', $directories) : null;
return $this;
@@ -150,7 +150,7 @@ class Exists extends AbstractValidator
$file = $file['tmp_name'];
$this->setValue($filename);
} elseif (is_array($value)) {
if (!isset($value['tmp_name']) || !isset($value['name'])) {
if (! isset($value['tmp_name']) || ! isset($value['name'])) {
throw new Exception\InvalidArgumentException(
'Value array must be in $_FILES format'
);
@@ -166,27 +166,27 @@ class Exists extends AbstractValidator
$check = false;
$directories = $this->getDirectory(true);
if (!isset($directories)) {
if (! isset($directories)) {
$check = true;
if (!file_exists($file)) {
if (! file_exists($file)) {
$this->error(self::DOES_NOT_EXIST);
return false;
}
} else {
foreach ($directories as $directory) {
if (!isset($directory) || '' === $directory) {
if (! isset($directory) || '' === $directory) {
continue;
}
$check = true;
if (!file_exists($directory . DIRECTORY_SEPARATOR . $filename)) {
if (! file_exists($directory . DIRECTORY_SEPARATOR . $filename)) {
$this->error(self::DOES_NOT_EXIST);
return false;
}
}
}
if (!$check) {
if (! $check) {
$this->error(self::DOES_NOT_EXIST);
return false;
}

View File

@@ -72,7 +72,7 @@ class Extension extends AbstractValidator
unset($options['case']);
}
if (!array_key_exists('extension', $options)) {
if (! array_key_exists('extension', $options)) {
$options = ['extension' => $options];
}
} else {
@@ -100,7 +100,7 @@ class Extension extends AbstractValidator
* Sets the case to use
*
* @param bool $case
* @return Extension Provides a fluent interface
* @return self Provides a fluent interface
*/
public function setCase($case)
{
@@ -124,7 +124,7 @@ class Extension extends AbstractValidator
* Sets the file extensions
*
* @param string|array $extension The extensions to validate
* @return Extension Provides a fluent interface
* @return self Provides a fluent interface
*/
public function setExtension($extension)
{
@@ -137,7 +137,7 @@ class Extension extends AbstractValidator
* Adds the file extensions
*
* @param string|array $extension The extensions to add for validation
* @return Extension Provides a fluent interface
* @return self Provides a fluent interface
*/
public function addExtension($extension)
{
@@ -147,7 +147,7 @@ class Extension extends AbstractValidator
}
foreach ($extension as $content) {
if (empty($content) || !is_string($content)) {
if (empty($content) || ! is_string($content)) {
continue;
}
@@ -182,7 +182,7 @@ class Extension extends AbstractValidator
$filename = $file['name'];
$file = $file['tmp_name'];
} elseif (is_array($value)) {
if (!isset($value['tmp_name']) || !isset($value['name'])) {
if (! isset($value['tmp_name']) || ! isset($value['name'])) {
throw new Exception\InvalidArgumentException(
'Value array must be in $_FILES format'
);
@@ -196,7 +196,7 @@ class Extension extends AbstractValidator
$this->setValue($filename);
// Is file readable ?
if (empty($file) || false === stream_resolve_include_path($file)) {
if (empty($file) || false === is_readable($file)) {
$this->error(self::NOT_FOUND);
return false;
}
@@ -206,7 +206,7 @@ class Extension extends AbstractValidator
if ($this->getCase() && (in_array($extension, $extensions))) {
return true;
} elseif (!$this->getCase()) {
} elseif (! $this->getCase()) {
foreach ($extensions as $ext) {
if (strtolower($ext) == strtolower($extension)) {
return true;

View File

@@ -61,7 +61,7 @@ class FilesSize extends Size
$options = ArrayUtils::iteratorToArray($options);
} elseif (is_scalar($options)) {
$options = ['max' => $options];
} elseif (!is_array($options)) {
} elseif (! is_array($options)) {
throw new Exception\InvalidArgumentException('Invalid options to validator provided');
}
@@ -69,7 +69,7 @@ class FilesSize extends Size
$argv = func_get_args();
array_shift($argv);
$options['max'] = array_shift($argv);
if (!empty($argv)) {
if (! empty($argv)) {
$options['useByteString'] = array_shift($argv);
}
}
@@ -98,22 +98,22 @@ class FilesSize extends Size
$size = $this->getSize();
foreach ($value as $files) {
if (is_array($files)) {
if (!isset($files['tmp_name']) || !isset($files['name'])) {
if (! isset($files['tmp_name']) || ! isset($files['name'])) {
throw new Exception\InvalidArgumentException(
'Value array must be in $_FILES format'
);
}
$file = $files;
$file = $files;
$files = $files['tmp_name'];
}
// Is file readable ?
if (empty($files) || false === stream_resolve_include_path($files)) {
if (empty($files) || false === is_readable($files)) {
$this->throwError($file, self::NOT_READABLE);
continue;
}
if (!isset($this->files[$files])) {
if (! isset($this->files[$files])) {
$this->files[$files] = $files;
} else {
// file already counted... do not count twice
@@ -128,10 +128,10 @@ class FilesSize extends Size
if (($max !== null) && ($max < $size)) {
if ($this->getByteString()) {
$this->options['max'] = $this->toByteString($max);
$this->size = $this->toByteString($size);
$this->size = $this->toByteString($size);
$this->throwError($file, self::TOO_BIG);
$this->options['max'] = $max;
$this->size = $size;
$this->size = $size;
} else {
$this->throwError($file, self::TOO_BIG);
}
@@ -142,10 +142,10 @@ class FilesSize extends Size
if (($min !== null) && ($size < $min)) {
if ($this->getByteString()) {
$this->options['min'] = $this->toByteString($min);
$this->size = $this->toByteString($size);
$this->size = $this->toByteString($size);
$this->throwError($file, self::TOO_SMALL);
$this->options['min'] = $min;
$this->size = $size;
$this->size = $size;
} else {
$this->throwError($file, self::TOO_SMALL);
}

View File

@@ -51,7 +51,7 @@ class Hash extends AbstractValidator
public function __construct($options = null)
{
if (is_scalar($options) ||
(is_array($options) && !array_key_exists('hash', $options))) {
(is_array($options) && ! array_key_exists('hash', $options))) {
$options = ['hash' => $options];
}
@@ -76,7 +76,7 @@ class Hash extends AbstractValidator
* Sets the hash for one or multiple files
*
* @param string|array $options
* @return Hash Provides a fluent interface
* @return self Provides a fluent interface
*/
public function setHash($options)
{
@@ -90,26 +90,26 @@ class Hash extends AbstractValidator
* Adds the hash for one or multiple files
*
* @param string|array $options
* @return Hash Provides a fluent interface
* @throws Exception\InvalidArgumentException
* @return self Provides a fluent interface
*/
public function addHash($options)
{
if (is_string($options)) {
$options = [$options];
} elseif (!is_array($options)) {
} elseif (! is_array($options)) {
throw new Exception\InvalidArgumentException("False parameter given");
}
$known = hash_algos();
if (!isset($options['algorithm'])) {
if (! isset($options['algorithm'])) {
$algorithm = $this->options['algorithm'];
} else {
$algorithm = $options['algorithm'];
unset($options['algorithm']);
}
if (!in_array($algorithm, $known)) {
if (! in_array($algorithm, $known)) {
throw new Exception\InvalidArgumentException("Unknown algorithm '{$algorithm}'");
}
@@ -134,7 +134,7 @@ class Hash extends AbstractValidator
$filename = $file['name'];
$file = $file['tmp_name'];
} elseif (is_array($value)) {
if (!isset($value['tmp_name']) || !isset($value['name'])) {
if (! isset($value['tmp_name']) || ! isset($value['name'])) {
throw new Exception\InvalidArgumentException(
'Value array must be in $_FILES format'
);
@@ -148,7 +148,7 @@ class Hash extends AbstractValidator
$this->setValue($filename);
// Is file readable ?
if (empty($file) || false === stream_resolve_include_path($file)) {
if (empty($file) || false === is_readable($file)) {
$this->error(self::NOT_FOUND);
return false;
}

View File

@@ -92,16 +92,16 @@ class ImageSize extends AbstractValidator
public function __construct($options = null)
{
if (1 < func_num_args()) {
if (!is_array($options)) {
if (! is_array($options)) {
$options = ['minWidth' => $options];
}
$argv = func_get_args();
array_shift($argv);
$options['minHeight'] = array_shift($argv);
if (!empty($argv)) {
if (! empty($argv)) {
$options['maxWidth'] = array_shift($argv);
if (!empty($argv)) {
if (! empty($argv)) {
$options['maxHeight'] = array_shift($argv);
}
}
@@ -124,8 +124,8 @@ class ImageSize extends AbstractValidator
* Sets the minimum allowed width
*
* @param int $minWidth
* @return ImageSize Provides a fluid interface
* @throws Exception\InvalidArgumentException When minwidth is greater than maxwidth
* @return self Provides a fluid interface
*/
public function setMinWidth($minWidth)
{
@@ -154,8 +154,8 @@ class ImageSize extends AbstractValidator
* Sets the maximum allowed width
*
* @param int $maxWidth
* @return ImageSize Provides a fluid interface
* @throws Exception\InvalidArgumentException When maxwidth is less than minwidth
* @return self Provides a fluid interface
*/
public function setMaxWidth($maxWidth)
{
@@ -184,8 +184,8 @@ class ImageSize extends AbstractValidator
* Sets the minimum allowed height
*
* @param int $minHeight
* @return ImageSize Provides a fluid interface
* @throws Exception\InvalidArgumentException When minheight is greater than maxheight
* @return self Provides a fluid interface
*/
public function setMinHeight($minHeight)
{
@@ -214,8 +214,8 @@ class ImageSize extends AbstractValidator
* Sets the maximum allowed height
*
* @param int $maxHeight
* @return ImageSize Provides a fluid interface
* @throws Exception\InvalidArgumentException When maxheight is less than minheight
* @return self Provides a fluid interface
*/
public function setMaxHeight($maxHeight)
{
@@ -274,7 +274,7 @@ class ImageSize extends AbstractValidator
* Sets the minimum image size
*
* @param array $options The minimum image dimensions
* @return ImageSize Provides a fluent interface
* @return self Provides a fluent interface
*/
public function setImageMin($options)
{
@@ -286,7 +286,7 @@ class ImageSize extends AbstractValidator
* Sets the maximum image size
*
* @param array|\Traversable $options The maximum image dimensions
* @return ImageSize Provides a fluent interface
* @return self Provides a fluent interface
*/
public function setImageMax($options)
{
@@ -298,7 +298,7 @@ class ImageSize extends AbstractValidator
* Sets the minimum and maximum image width
*
* @param array $options The image width dimensions
* @return ImageSize Provides a fluent interface
* @return self Provides a fluent interface
*/
public function setImageWidth($options)
{
@@ -312,7 +312,7 @@ class ImageSize extends AbstractValidator
* Sets the minimum and maximum image height
*
* @param array $options The image height dimensions
* @return ImageSize Provides a fluent interface
* @return self Provides a fluent interface
*/
public function setImageHeight($options)
{
@@ -337,7 +337,7 @@ class ImageSize extends AbstractValidator
$filename = $file['name'];
$file = $file['tmp_name'];
} elseif (is_array($value)) {
if (!isset($value['tmp_name']) || !isset($value['name'])) {
if (! isset($value['tmp_name']) || ! isset($value['name'])) {
throw new Exception\InvalidArgumentException(
'Value array must be in $_FILES format'
);
@@ -351,7 +351,7 @@ class ImageSize extends AbstractValidator
$this->setValue($filename);
// Is file readable ?
if (empty($file) || false === stream_resolve_include_path($file)) {
if (empty($file) || false === is_readable($file)) {
$this->error(self::NOT_READABLE);
return false;
}

View File

@@ -86,7 +86,7 @@ class IsCompressed extends MimeType
parent::__construct($options);
if (!$this->getMimeType()) {
if (! $this->getMimeType()) {
$this->setMimeType($default);
}
}

View File

@@ -109,7 +109,7 @@ class IsImage extends MimeType
parent::__construct($options);
if (!$this->getMimeType()) {
if (! $this->getMimeType()) {
$this->setMimeType($default);
}
}

View File

@@ -90,7 +90,7 @@ class Md5 extends Hash
$filename = $file['name'];
$file = $file['tmp_name'];
} elseif (is_array($value)) {
if (!isset($value['tmp_name']) || !isset($value['name'])) {
if (! isset($value['tmp_name']) || ! isset($value['name'])) {
throw new Exception\InvalidArgumentException(
'Value array must be in $_FILES format'
);
@@ -104,12 +104,12 @@ class Md5 extends Hash
$this->setValue($filename);
// Is file readable ?
if (empty($file) || false === stream_resolve_include_path($file)) {
if (empty($file) || false === is_readable($file)) {
$this->error(self::NOT_FOUND);
return false;
}
$hashes = array_unique(array_keys($this->getHash()));
$hashes = array_unique(array_keys($this->getHash()));
$filehash = hash_file('md5', $file);
if ($filehash === false) {
$this->error(self::NOT_DETECTED);

View File

@@ -120,7 +120,7 @@ class MimeType extends AbstractValidator
// Handle cases where mimetypes are interspersed with options, or
// options are simply an array of mime types
foreach (array_keys($options) as $key) {
if (!is_int($key)) {
if (! is_int($key)) {
continue;
}
$this->addMimeType($options[$key]);
@@ -140,7 +140,7 @@ class MimeType extends AbstractValidator
{
if (null === $this->options['magicFile']) {
$magic = getenv('magic');
if (!empty($magic)) {
if (! empty($magic)) {
$this->setMagicFile($magic);
if ($this->options['magicFile'] === null) {
$this->options['magicFile'] = false;
@@ -176,10 +176,10 @@ class MimeType extends AbstractValidator
* if false, the default MAGIC file from PHP will be used
*
* @param string $file
* @return MimeType Provides fluid interface
* @throws Exception\RuntimeException When finfo can not read the magicfile
* @throws Exception\InvalidArgumentException
* @throws Exception\InvalidMagicMimeFileException
* @return self Provides fluid interface
*/
public function setMagicFile($file)
{
@@ -187,16 +187,16 @@ class MimeType extends AbstractValidator
$this->options['magicFile'] = false;
} elseif (empty($file)) {
$this->options['magicFile'] = null;
} elseif (!(class_exists('finfo', false))) {
} elseif (! (class_exists('finfo', false))) {
$this->options['magicFile'] = null;
throw new Exception\RuntimeException('Magicfile can not be set; there is no finfo extension installed');
} elseif (!is_file($file) || !is_readable($file)) {
} elseif (! is_file($file) || ! is_readable($file)) {
throw new Exception\InvalidArgumentException(sprintf(
'The given magicfile ("%s") could not be read',
$file
));
} else {
ErrorHandler::start(E_NOTICE|E_WARNING);
ErrorHandler::start(E_NOTICE | E_WARNING);
$this->finfo = finfo_open(FILEINFO_MIME_TYPE, $file);
$error = ErrorHandler::stop();
if (empty($this->finfo)) {
@@ -216,7 +216,7 @@ class MimeType extends AbstractValidator
* Disables usage of MagicFile
*
* @param $disable boolean False disables usage of magic file
* @return MimeType Provides fluid interface
* @return self Provides fluid interface
*/
public function disableMagicFile($disable)
{
@@ -249,7 +249,7 @@ class MimeType extends AbstractValidator
* Note that this is unsafe and therefor the default value is false
*
* @param bool $headerCheck
* @return MimeType Provides fluid interface
* @return self Provides fluid interface
*/
public function enableHeaderCheck($headerCheck = true)
{
@@ -278,7 +278,7 @@ class MimeType extends AbstractValidator
* Sets the mimetypes
*
* @param string|array $mimetype The mimetypes to validate
* @return MimeType Provides a fluent interface
* @return self Provides a fluent interface
*/
public function setMimeType($mimetype)
{
@@ -291,8 +291,8 @@ class MimeType extends AbstractValidator
* Adds the mimetypes
*
* @param string|array $mimetype The mimetypes to add for validation
* @return MimeType Provides a fluent interface
* @throws Exception\InvalidArgumentException
* @return self Provides a fluent interface
*/
public function addMimeType($mimetype)
{
@@ -300,7 +300,7 @@ class MimeType extends AbstractValidator
if (is_string($mimetype)) {
$mimetype = explode(',', $mimetype);
} elseif (!is_array($mimetype)) {
} elseif (! is_array($mimetype)) {
throw new Exception\InvalidArgumentException("Invalid options to validator provided");
}
@@ -309,7 +309,7 @@ class MimeType extends AbstractValidator
}
foreach ($mimetype as $content) {
if (empty($content) || !is_string($content)) {
if (empty($content) || ! is_string($content)) {
continue;
}
$mimetypes[] = trim($content);
@@ -347,7 +347,7 @@ class MimeType extends AbstractValidator
$filetype = $file['type'];
$file = $file['tmp_name'];
} elseif (is_array($value)) {
if (!isset($value['tmp_name']) || !isset($value['name']) || !isset($value['type'])) {
if (! isset($value['tmp_name']) || ! isset($value['name']) || ! isset($value['type'])) {
throw new Exception\InvalidArgumentException(
'Value array must be in $_FILES format'
);
@@ -363,28 +363,29 @@ class MimeType extends AbstractValidator
$this->setValue($filename);
// Is file readable ?
if (empty($file) || false === stream_resolve_include_path($file)) {
if (empty($file) || false === is_readable($file)) {
$this->error(static::NOT_READABLE);
return false;
}
$mimefile = $this->getMagicFile();
if (class_exists('finfo', false)) {
if (!$this->isMagicFileDisabled() && (!empty($mimefile) && empty($this->finfo))) {
ErrorHandler::start(E_NOTICE|E_WARNING);
if (! $this->isMagicFileDisabled() && (! empty($mimefile) && empty($this->finfo))) {
ErrorHandler::start(E_NOTICE | E_WARNING);
$this->finfo = finfo_open(FILEINFO_MIME_TYPE, $mimefile);
ErrorHandler::stop();
}
if (empty($this->finfo)) {
ErrorHandler::start(E_NOTICE|E_WARNING);
ErrorHandler::start(E_NOTICE | E_WARNING);
$this->finfo = finfo_open(FILEINFO_MIME_TYPE);
ErrorHandler::stop();
}
$this->type = null;
if (!empty($this->finfo)) {
if (! empty($this->finfo)) {
$this->type = finfo_file($this->finfo, $file);
unset($this->finfo);
}
}

View File

@@ -43,7 +43,7 @@ class NotExists extends Exists
$file = $file['tmp_name'];
$this->setValue($filename);
} elseif (is_array($value)) {
if (!isset($value['tmp_name']) || !isset($value['name'])) {
if (! isset($value['tmp_name']) || ! isset($value['name'])) {
throw new Exception\InvalidArgumentException(
'Value array must be in $_FILES format'
);
@@ -59,7 +59,7 @@ class NotExists extends Exists
$check = false;
$directories = $this->getDirectory(true);
if (!isset($directories)) {
if (! isset($directories)) {
$check = true;
if (file_exists($file)) {
$this->error(self::DOES_EXIST);
@@ -67,7 +67,7 @@ class NotExists extends Exists
}
} else {
foreach ($directories as $directory) {
if (!isset($directory) || '' === $directory) {
if (! isset($directory) || '' === $directory) {
continue;
}
@@ -79,7 +79,7 @@ class NotExists extends Exists
}
}
if (!$check) {
if (! $check) {
$this->error(self::DOES_EXIST);
return false;
}

View File

@@ -90,7 +90,7 @@ class Sha1 extends Hash
$filename = $file['name'];
$file = $file['tmp_name'];
} elseif (is_array($value)) {
if (!isset($value['tmp_name']) || !isset($value['name'])) {
if (! isset($value['tmp_name']) || ! isset($value['name'])) {
throw new Exception\InvalidArgumentException(
'Value array must be in $_FILES format'
);
@@ -104,12 +104,12 @@ class Sha1 extends Hash
$this->setValue($filename);
// Is file readable ?
if (empty($file) || false === stream_resolve_include_path($file)) {
if (empty($file) || false === is_readable($file)) {
$this->error(self::NOT_FOUND);
return false;
}
$hashes = array_unique(array_keys($this->getHash()));
$hashes = array_unique(array_keys($this->getHash()));
$filehash = hash_file('sha1', $file);
if ($filehash === false) {
$this->error(self::NOT_DETECTED);

View File

@@ -82,7 +82,7 @@ class Size extends AbstractValidator
$argv = func_get_args();
array_shift($argv);
$options['max'] = array_shift($argv);
if (!empty($argv)) {
if (! empty($argv)) {
$options['useByteString'] = array_shift($argv);
}
}
@@ -121,7 +121,7 @@ class Size extends AbstractValidator
public function getMin($raw = false)
{
$min = $this->options['min'];
if (!$raw && $this->getByteString()) {
if (! $raw && $this->getByteString()) {
$min = $this->toByteString($min);
}
@@ -136,8 +136,8 @@ class Size extends AbstractValidator
* For example: 2000, 2MB, 0.2GB
*
* @param int|string $min The minimum file size
* @return Size Provides a fluent interface
* @throws Exception\InvalidArgumentException When min is greater than max
* @return self Provides a fluent interface
*/
public function setMin($min)
{
@@ -166,7 +166,7 @@ class Size extends AbstractValidator
public function getMax($raw = false)
{
$max = $this->options['max'];
if (!$raw && $this->getByteString()) {
if (! $raw && $this->getByteString()) {
$max = $this->toByteString($max);
}
@@ -181,8 +181,8 @@ class Size extends AbstractValidator
* For example: 2000, 2MB, 0.2GB
*
* @param int|string $max The maximum file size
* @return Size Provides a fluent interface
* @throws Exception\InvalidArgumentException When max is smaller than min
* @return self Provides a fluent interface
*/
public function setMax($max)
{
@@ -216,7 +216,7 @@ class Size extends AbstractValidator
* Set current size
*
* @param int $size
* @return Size
* @return self
*/
protected function setSize($size)
{
@@ -239,7 +239,7 @@ class Size extends AbstractValidator
$filename = $file['name'];
$file = $file['tmp_name'];
} elseif (is_array($value)) {
if (!isset($value['tmp_name']) || !isset($value['name'])) {
if (! isset($value['tmp_name']) || ! isset($value['name'])) {
throw new Exception\InvalidArgumentException(
'Value array must be in $_FILES format'
);
@@ -253,7 +253,7 @@ class Size extends AbstractValidator
$this->setValue($filename);
// Is file readable ?
if (empty($file) || false === stream_resolve_include_path($file)) {
if (empty($file) || false === is_readable($file)) {
$this->error(self::NOT_FOUND);
return false;
}
@@ -270,10 +270,10 @@ class Size extends AbstractValidator
if (($min !== null) && ($size < $min)) {
if ($this->getByteString()) {
$this->options['min'] = $this->toByteString($min);
$this->size = $this->toByteString($size);
$this->size = $this->toByteString($size);
$this->error(self::TOO_SMALL);
$this->options['min'] = $min;
$this->size = $size;
$this->size = $size;
} else {
$this->error(self::TOO_SMALL);
}
@@ -283,10 +283,10 @@ class Size extends AbstractValidator
if (($max !== null) && ($max < $size)) {
if ($this->getByteString()) {
$this->options['max'] = $this->toByteString($max);
$this->size = $this->toByteString($size);
$this->size = $this->toByteString($size);
$this->error(self::TOO_BIG);
$this->options['max'] = $max;
$this->size = $size;
$this->size = $size;
} else {
$this->error(self::TOO_BIG);
}
@@ -308,7 +308,7 @@ class Size extends AbstractValidator
protected function toByteString($size)
{
$sizes = ['B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
for ($i=0; $size >= 1024 && $i < 9; $i++) {
for ($i = 0; $size >= 1024 && $i < 9; $i++) {
$size /= 1024;
}
@@ -330,8 +330,8 @@ class Size extends AbstractValidator
$type = trim(substr($size, -2, 1));
$value = substr($size, 0, -1);
if (!is_numeric($value)) {
$value = substr($value, 0, -1);
if (! is_numeric($value)) {
$value = trim(substr($value, 0, -1));
}
switch (strtoupper($type)) {

View File

@@ -9,6 +9,7 @@
namespace Zend\Validator\File;
use Countable;
use Zend\Validator\AbstractValidator;
use Zend\Validator\Exception;
@@ -63,7 +64,7 @@ class Upload extends AbstractValidator
*/
public function __construct($options = [])
{
if (is_array($options) && !array_key_exists('files', $options)) {
if (is_array($options) && ! array_key_exists('files', $options)) {
$options = ['files' => $options];
}
@@ -109,7 +110,10 @@ class Upload extends AbstractValidator
*/
public function setFiles($files = [])
{
if (count($files) === 0) {
if (null === $files
|| ((is_array($files) || $files instanceof Countable)
&& count($files) === 0)
) {
$this->options['files'] = $_FILES;
} else {
$this->options['files'] = $files;
@@ -120,7 +124,7 @@ class Upload extends AbstractValidator
}
foreach ($this->options['files'] as $file => $content) {
if (!isset($content['error'])) {
if (! isset($content['error'])) {
unset($this->options['files'][$file]);
}
}
@@ -162,7 +166,7 @@ class Upload extends AbstractValidator
$this->value = $file;
switch ($content['error']) {
case 0:
if (!is_uploaded_file($content['tmp_name'])) {
if (! is_uploaded_file($content['tmp_name'])) {
$this->throwError($content, self::ATTACK);
}
break;

View File

@@ -57,7 +57,7 @@ class UploadFile extends AbstractValidator
public function isValid($value)
{
if (is_array($value)) {
if (!isset($value['tmp_name']) || !isset($value['name']) || !isset($value['error'])) {
if (! isset($value['tmp_name']) || ! isset($value['name']) || ! isset($value['error'])) {
throw new Exception\InvalidArgumentException(
'Value array must be in $_FILES format'
);

View File

@@ -28,8 +28,8 @@ class WordCount extends AbstractValidator
* @var array Error message templates
*/
protected $messageTemplates = [
self::TOO_MUCH => "Too many words, maximum '%max%' are allowed but '%count%' were counted",
self::TOO_LESS => "Too few words, minimum '%min%' are expected but '%count%' were counted",
self::TOO_MUCH => "Too many words, maximum '%max%' are allowed but '%count%' were counted",
self::TOO_LESS => "Too few words, minimum '%min%' are expected but '%count%' were counted",
self::NOT_FOUND => "File is not readable or does not exist",
];
@@ -75,7 +75,7 @@ class WordCount extends AbstractValidator
public function __construct($options = null)
{
if (1 < func_num_args()) {
$args = func_get_args();
$args = func_get_args();
$options = [
'min' => array_shift($args),
'max' => array_shift($args),
@@ -103,8 +103,8 @@ class WordCount extends AbstractValidator
* Sets the minimum word count
*
* @param int|array $min The minimum word count
* @return WordCount Provides a fluent interface
* @throws Exception\InvalidArgumentException When min is greater than max
* @return self Provides a fluent interface
*/
public function setMin($min)
{
@@ -141,8 +141,8 @@ class WordCount extends AbstractValidator
* Sets the maximum file count
*
* @param int|array $max The maximum word count
* @return WordCount Provides a fluent interface
* @throws Exception\InvalidArgumentException When max is smaller than min
* @return self Provides a fluent interface
*/
public function setMax($max)
{
@@ -180,7 +180,7 @@ class WordCount extends AbstractValidator
$filename = $file['name'];
$file = $file['tmp_name'];
} elseif (is_array($value)) {
if (!isset($value['tmp_name']) || !isset($value['name'])) {
if (! isset($value['tmp_name']) || ! isset($value['name'])) {
throw new Exception\InvalidArgumentException(
'Value array must be in $_FILES format'
);
@@ -194,7 +194,7 @@ class WordCount extends AbstractValidator
$this->setValue($filename);
// Is file readable ?
if (empty($file) || false === stream_resolve_include_path($file)) {
if (empty($file) || false === is_readable($file)) {
$this->error(self::NOT_FOUND);
return false;
}