minor #11140 [Validator] smaller CS fixes (Tobion)

This PR was merged into the 2.3-dev branch.

Discussion
----------

[Validator] smaller CS fixes

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | -
| License       | MIT

First commit fixes some CS of #11027
Second one removes `null` initialization from Validator as we don't do it.

Commits
-------

2025778 [Validator] no need to initialize properties with null
967576a [Validator] smaller fixes for binary format
This commit is contained in:
Fabien Potencier 2014-06-17 21:59:41 +02:00
commit 5febbb27f5
9 changed files with 32 additions and 32 deletions

View File

@ -27,8 +27,8 @@ class Choice extends Constraint
public $callback;
public $multiple = false;
public $strict = false;
public $min = null;
public $max = null;
public $min;
public $max;
public $message = 'The value you selected is not a valid choice.';
public $multipleMessage = 'One or more of the given values is invalid.';
public $minMessage = 'You must select at least {{ limit }} choice.|You must select at least {{ limit }} choices.';

View File

@ -26,5 +26,5 @@ class Email extends Constraint
public $message = 'This value is not a valid email address.';
public $checkMX = false;
public $checkHost = false;
public $strict = null;
public $strict;
}

View File

@ -24,8 +24,8 @@ use Symfony\Component\Validator\Exception\ConstraintDefinitionException;
*/
class File extends Constraint
{
public $maxSize = null;
public $binaryFormat = null;
public $maxSize;
public $binaryFormat;
public $mimeTypes = array();
public $notFoundMessage = 'The file could not be found.';
public $notReadableMessage = 'The file is not readable.';
@ -49,19 +49,19 @@ class File extends Constraint
if ($this->maxSize) {
if (ctype_digit((string) $this->maxSize)) {
$this->maxSize = (int) $this->maxSize;
$this->binaryFormat = $this->binaryFormat === null ? false : $this->binaryFormat;
$this->binaryFormat = null === $this->binaryFormat ? false : $this->binaryFormat;
} elseif (preg_match('/^\d++k$/i', $this->maxSize)) {
$this->maxSize = $this->maxSize * 1000;
$this->binaryFormat = $this->binaryFormat === null ? false : $this->binaryFormat;
$this->binaryFormat = null === $this->binaryFormat ? false : $this->binaryFormat;
} elseif (preg_match('/^\d++M$/i', $this->maxSize)) {
$this->maxSize = $this->maxSize * 1000000;
$this->binaryFormat = $this->binaryFormat === null ? false : $this->binaryFormat;
} elseif (preg_match('/^\d++ki$/i', $this->maxSize)) {
$this->binaryFormat = null === $this->binaryFormat ? false : $this->binaryFormat;
} elseif (preg_match('/^\d++Ki$/i', $this->maxSize)) {
$this->maxSize = $this->maxSize << 10;
$this->binaryFormat = $this->binaryFormat === null ? true : $this->binaryFormat;
$this->binaryFormat = null === $this->binaryFormat ? true : $this->binaryFormat;
} elseif (preg_match('/^\d++Mi$/i', $this->maxSize)) {
$this->maxSize = $this->maxSize << 20;
$this->binaryFormat = $this->binaryFormat === null ? true : $this->binaryFormat;
$this->binaryFormat = null === $this->binaryFormat ? true : $this->binaryFormat;
} else {
throw new ConstraintDefinitionException(sprintf('"%s" is not a valid maximum size', $this->maxSize));
}

View File

@ -54,7 +54,7 @@ class FileValidator extends ConstraintValidator
switch ($value->getError()) {
case UPLOAD_ERR_INI_SIZE:
if ($constraint->maxSize) {
$limitInBytes = min(UploadedFile::getMaxFilesize(), (int) $constraint->maxSize);
$limitInBytes = min(UploadedFile::getMaxFilesize(), $constraint->maxSize);
} else {
$limitInBytes = UploadedFile::getMaxFilesize();
}
@ -118,7 +118,7 @@ class FileValidator extends ConstraintValidator
if (0 === $sizeInBytes) {
$this->context->addViolation($constraint->disallowEmptyMessage);
} elseif ($constraint->maxSize) {
$limitInBytes = (int) $constraint->maxSize;
$limitInBytes = $constraint->maxSize;
if ($sizeInBytes > $limitInBytes) {
// Convert the limit to the smallest possible number

View File

@ -20,12 +20,12 @@ namespace Symfony\Component\Validator\Constraints;
class Image extends File
{
public $mimeTypes = 'image/*';
public $minWidth = null;
public $maxWidth = null;
public $maxHeight = null;
public $minHeight = null;
public $maxRatio = null;
public $minRatio = null;
public $minWidth;
public $maxWidth;
public $maxHeight;
public $minHeight;
public $maxRatio;
public $minRatio;
public $allowSquare = true;
public $allowLandscape = true;
public $allowPortrait = true;

View File

@ -25,7 +25,7 @@ class Regex extends Constraint
{
public $message = 'This value is not valid.';
public $pattern;
public $htmlPattern = null;
public $htmlPattern;
public $match = true;
/**

View File

@ -42,14 +42,14 @@ class LazyLoadingMetadataFactory implements MetadataFactoryInterface
/**
* The loader for loading the class metadata
*
* @var LoaderInterface
* @var LoaderInterface|null
*/
protected $loader;
/**
* The cache for caching class metadata
*
* @var CacheInterface
* @var CacheInterface|null
*/
protected $cache;

View File

@ -20,9 +20,9 @@ class XmlFileLoader extends FileLoader
/**
* An array of SimpleXMLElement instances.
*
* @var \SimpleXMLElement[]
* @var \SimpleXMLElement[]|null
*/
protected $classes = null;
protected $classes;
/**
* {@inheritdoc}

View File

@ -62,27 +62,27 @@ class ValidatorBuilder implements ValidatorBuilderInterface
private $methodMappings = array();
/**
* @var Reader
* @var Reader|null
*/
private $annotationReader = null;
private $annotationReader;
/**
* @var MetadataFactoryInterface
* @var MetadataFactoryInterface|null
*/
private $metadataFactory;
/**
* @var ConstraintValidatorFactoryInterface
* @var ConstraintValidatorFactoryInterface|null
*/
private $validatorFactory;
/**
* @var CacheInterface
* @var CacheInterface|null
*/
private $metadataCache;
/**
* @var TranslatorInterface
* @var TranslatorInterface|null
*/
private $translator;
@ -92,12 +92,12 @@ class ValidatorBuilder implements ValidatorBuilderInterface
private $translationDomain;
/**
* @var PropertyAccessorInterface
* @var PropertyAccessorInterface|null
*/
private $propertyAccessor;
/**
* @var int
* @var int|null
*/
private $apiVersion;