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 null967576a
[Validator] smaller fixes for binary format
This commit is contained in:
commit
5febbb27f5
@ -27,8 +27,8 @@ class Choice extends Constraint
|
|||||||
public $callback;
|
public $callback;
|
||||||
public $multiple = false;
|
public $multiple = false;
|
||||||
public $strict = false;
|
public $strict = false;
|
||||||
public $min = null;
|
public $min;
|
||||||
public $max = null;
|
public $max;
|
||||||
public $message = 'The value you selected is not a valid choice.';
|
public $message = 'The value you selected is not a valid choice.';
|
||||||
public $multipleMessage = 'One or more of the given values is invalid.';
|
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.';
|
public $minMessage = 'You must select at least {{ limit }} choice.|You must select at least {{ limit }} choices.';
|
||||||
|
@ -26,5 +26,5 @@ class Email extends Constraint
|
|||||||
public $message = 'This value is not a valid email address.';
|
public $message = 'This value is not a valid email address.';
|
||||||
public $checkMX = false;
|
public $checkMX = false;
|
||||||
public $checkHost = false;
|
public $checkHost = false;
|
||||||
public $strict = null;
|
public $strict;
|
||||||
}
|
}
|
||||||
|
@ -24,8 +24,8 @@ use Symfony\Component\Validator\Exception\ConstraintDefinitionException;
|
|||||||
*/
|
*/
|
||||||
class File extends Constraint
|
class File extends Constraint
|
||||||
{
|
{
|
||||||
public $maxSize = null;
|
public $maxSize;
|
||||||
public $binaryFormat = null;
|
public $binaryFormat;
|
||||||
public $mimeTypes = array();
|
public $mimeTypes = array();
|
||||||
public $notFoundMessage = 'The file could not be found.';
|
public $notFoundMessage = 'The file could not be found.';
|
||||||
public $notReadableMessage = 'The file is not readable.';
|
public $notReadableMessage = 'The file is not readable.';
|
||||||
@ -49,19 +49,19 @@ class File extends Constraint
|
|||||||
if ($this->maxSize) {
|
if ($this->maxSize) {
|
||||||
if (ctype_digit((string) $this->maxSize)) {
|
if (ctype_digit((string) $this->maxSize)) {
|
||||||
$this->maxSize = (int) $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)) {
|
} elseif (preg_match('/^\d++k$/i', $this->maxSize)) {
|
||||||
$this->maxSize = $this->maxSize * 1000;
|
$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)) {
|
} elseif (preg_match('/^\d++M$/i', $this->maxSize)) {
|
||||||
$this->maxSize = $this->maxSize * 1000000;
|
$this->maxSize = $this->maxSize * 1000000;
|
||||||
$this->binaryFormat = $this->binaryFormat === null ? false : $this->binaryFormat;
|
$this->binaryFormat = null === $this->binaryFormat ? false : $this->binaryFormat;
|
||||||
} elseif (preg_match('/^\d++ki$/i', $this->maxSize)) {
|
} elseif (preg_match('/^\d++Ki$/i', $this->maxSize)) {
|
||||||
$this->maxSize = $this->maxSize << 10;
|
$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)) {
|
} elseif (preg_match('/^\d++Mi$/i', $this->maxSize)) {
|
||||||
$this->maxSize = $this->maxSize << 20;
|
$this->maxSize = $this->maxSize << 20;
|
||||||
$this->binaryFormat = $this->binaryFormat === null ? true : $this->binaryFormat;
|
$this->binaryFormat = null === $this->binaryFormat ? true : $this->binaryFormat;
|
||||||
} else {
|
} else {
|
||||||
throw new ConstraintDefinitionException(sprintf('"%s" is not a valid maximum size', $this->maxSize));
|
throw new ConstraintDefinitionException(sprintf('"%s" is not a valid maximum size', $this->maxSize));
|
||||||
}
|
}
|
||||||
|
@ -54,7 +54,7 @@ class FileValidator extends ConstraintValidator
|
|||||||
switch ($value->getError()) {
|
switch ($value->getError()) {
|
||||||
case UPLOAD_ERR_INI_SIZE:
|
case UPLOAD_ERR_INI_SIZE:
|
||||||
if ($constraint->maxSize) {
|
if ($constraint->maxSize) {
|
||||||
$limitInBytes = min(UploadedFile::getMaxFilesize(), (int) $constraint->maxSize);
|
$limitInBytes = min(UploadedFile::getMaxFilesize(), $constraint->maxSize);
|
||||||
} else {
|
} else {
|
||||||
$limitInBytes = UploadedFile::getMaxFilesize();
|
$limitInBytes = UploadedFile::getMaxFilesize();
|
||||||
}
|
}
|
||||||
@ -118,7 +118,7 @@ class FileValidator extends ConstraintValidator
|
|||||||
if (0 === $sizeInBytes) {
|
if (0 === $sizeInBytes) {
|
||||||
$this->context->addViolation($constraint->disallowEmptyMessage);
|
$this->context->addViolation($constraint->disallowEmptyMessage);
|
||||||
} elseif ($constraint->maxSize) {
|
} elseif ($constraint->maxSize) {
|
||||||
$limitInBytes = (int) $constraint->maxSize;
|
$limitInBytes = $constraint->maxSize;
|
||||||
|
|
||||||
if ($sizeInBytes > $limitInBytes) {
|
if ($sizeInBytes > $limitInBytes) {
|
||||||
// Convert the limit to the smallest possible number
|
// Convert the limit to the smallest possible number
|
||||||
|
@ -20,12 +20,12 @@ namespace Symfony\Component\Validator\Constraints;
|
|||||||
class Image extends File
|
class Image extends File
|
||||||
{
|
{
|
||||||
public $mimeTypes = 'image/*';
|
public $mimeTypes = 'image/*';
|
||||||
public $minWidth = null;
|
public $minWidth;
|
||||||
public $maxWidth = null;
|
public $maxWidth;
|
||||||
public $maxHeight = null;
|
public $maxHeight;
|
||||||
public $minHeight = null;
|
public $minHeight;
|
||||||
public $maxRatio = null;
|
public $maxRatio;
|
||||||
public $minRatio = null;
|
public $minRatio;
|
||||||
public $allowSquare = true;
|
public $allowSquare = true;
|
||||||
public $allowLandscape = true;
|
public $allowLandscape = true;
|
||||||
public $allowPortrait = true;
|
public $allowPortrait = true;
|
||||||
|
@ -25,7 +25,7 @@ class Regex extends Constraint
|
|||||||
{
|
{
|
||||||
public $message = 'This value is not valid.';
|
public $message = 'This value is not valid.';
|
||||||
public $pattern;
|
public $pattern;
|
||||||
public $htmlPattern = null;
|
public $htmlPattern;
|
||||||
public $match = true;
|
public $match = true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -42,14 +42,14 @@ class LazyLoadingMetadataFactory implements MetadataFactoryInterface
|
|||||||
/**
|
/**
|
||||||
* The loader for loading the class metadata
|
* The loader for loading the class metadata
|
||||||
*
|
*
|
||||||
* @var LoaderInterface
|
* @var LoaderInterface|null
|
||||||
*/
|
*/
|
||||||
protected $loader;
|
protected $loader;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The cache for caching class metadata
|
* The cache for caching class metadata
|
||||||
*
|
*
|
||||||
* @var CacheInterface
|
* @var CacheInterface|null
|
||||||
*/
|
*/
|
||||||
protected $cache;
|
protected $cache;
|
||||||
|
|
||||||
|
@ -20,9 +20,9 @@ class XmlFileLoader extends FileLoader
|
|||||||
/**
|
/**
|
||||||
* An array of SimpleXMLElement instances.
|
* An array of SimpleXMLElement instances.
|
||||||
*
|
*
|
||||||
* @var \SimpleXMLElement[]
|
* @var \SimpleXMLElement[]|null
|
||||||
*/
|
*/
|
||||||
protected $classes = null;
|
protected $classes;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
|
@ -62,27 +62,27 @@ class ValidatorBuilder implements ValidatorBuilderInterface
|
|||||||
private $methodMappings = array();
|
private $methodMappings = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var Reader
|
* @var Reader|null
|
||||||
*/
|
*/
|
||||||
private $annotationReader = null;
|
private $annotationReader;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var MetadataFactoryInterface
|
* @var MetadataFactoryInterface|null
|
||||||
*/
|
*/
|
||||||
private $metadataFactory;
|
private $metadataFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var ConstraintValidatorFactoryInterface
|
* @var ConstraintValidatorFactoryInterface|null
|
||||||
*/
|
*/
|
||||||
private $validatorFactory;
|
private $validatorFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var CacheInterface
|
* @var CacheInterface|null
|
||||||
*/
|
*/
|
||||||
private $metadataCache;
|
private $metadataCache;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var TranslatorInterface
|
* @var TranslatorInterface|null
|
||||||
*/
|
*/
|
||||||
private $translator;
|
private $translator;
|
||||||
|
|
||||||
@ -92,12 +92,12 @@ class ValidatorBuilder implements ValidatorBuilderInterface
|
|||||||
private $translationDomain;
|
private $translationDomain;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var PropertyAccessorInterface
|
* @var PropertyAccessorInterface|null
|
||||||
*/
|
*/
|
||||||
private $propertyAccessor;
|
private $propertyAccessor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var int
|
* @var int|null
|
||||||
*/
|
*/
|
||||||
private $apiVersion;
|
private $apiVersion;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user