10000 [Validator] smaller CS fixes by Tobion · Pull Request #11140 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Validator] smaller CS fixes #11140

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 17, 2014
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
[Validator] smaller fixes for binary format
  • Loading branch information
Tobion committed Jun 17, 2014
commit 967576aaa9817dfdd9c068174502cac0f88cdb63
12 changes: 6 additions & 6 deletions src/Symfony/Component/Validator/Constraints/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,19 @@ public function __construct($options = null)
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));
}
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Component/Validator/Constraints/FileValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function validate($value, Constraint $constraint)
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();
}
Expand Down Expand Up @@ -118,7 +118,7 @@ public function validate($value, Constraint $constraint)
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
Expand Down
0