Skip to content

Commit 8f7388a

Browse files
committed
[Validator] fix option handling
1 parent beca070 commit 8f7388a

File tree

4 files changed

+48
-40
lines changed

4 files changed

+48
-40
lines changed

src/Symfony/Component/Validator/Constraints/Negative.php

+12-10
Original file line numberDiff line numberDiff line change
@@ -27,23 +27,25 @@ public function __construct($options = null)
2727
{
2828
if (null === $options) {
2929
$options = array();
30+
} elseif (!is_array($options)) {
31+
$options = array($this->getDefaultOption() => $options);
3032
}
3133

32-
if (\is_array($options)) {
33-
if (isset($options['propertyPath'])) {
34-
throw new ConstraintDefinitionException(sprintf('The "propertyPath" option of the "%s" constraint cannot be set.', \get_class($this)));
35-
}
34+
if (isset($options['propertyPath'])) {
35+
throw new ConstraintDefinitionException(sprintf('The "propertyPath" option of the "%s" constraint cannot be set.', \get_class($this)));
36+
}
3637

37-
if (isset($options['value'])) {
38-
throw new ConstraintDefinitionException(sprintf('The "value" option of the "%s" constraint cannot be set.', \get_class($this)));
39-
}
38+
if (isset($options['value'])) {
39+
throw new ConstraintDefinitionException(sprintf('The "value" option of the "%s" constraint cannot be set.', \get_class($this)));
4040
}
4141

42-
parent::__construct($options = array_merge((array) $options, array('value' => 0)));
42+
$options['value'] = 0;
43+
44+
parent::__construct($options);
4345
}
4446

45-
public function validatedBy()
47+
public function validatedBy(): string
4648
{
47-
return 'LessThanValidator';
49+
return LessThanValidator::class;
4850
}
4951
}

src/Symfony/Component/Validator/Constraints/NegativeOrZero.php

+12-10
Original file line numberDiff line numberDiff line change
@@ -27,23 +27,25 @@ public function __construct($options = null)
2727
{
2828
if (null === $options) {
2929
$options = array();
30+
} elseif (!is_array($options)) {
31+
$options = array($this->getDefaultOption() => $options);
3032
}
3133

32-
if (\is_array($options)) {
33-
if (isset($options['propertyPath'])) {
34-
throw new ConstraintDefinitionException(sprintf('The "propertyPath" option of the "%s" constraint cannot be set.', \get_class($this)));
35-
}
34+
if (isset($options['propertyPath'])) {
35+
throw new ConstraintDefinitionException(sprintf('The "propertyPath" option of the "%s" constraint cannot be set.', \get_class($this)));
36+
}
3637

37-
if (isset($options['value'])) {
38-
throw new ConstraintDefinitionException(sprintf('The "value" option of the "%s" constraint cannot be set.', \get_class($this)));
39-
}
38+
if (isset($options['value'])) {
39+
throw new ConstraintDefinitionException(sprintf('The "value" option of the "%s" constraint cannot be set.', \get_class($this)));
4040
}
4141

42-
parent::__construct($options = array_merge((array) $options, array('value' => 0)));
42+
$options['value'] = 0;
43+
44+
parent::__construct($options);
4345
}
4446

45-
public function validatedBy()
47+
public function validatedBy(): string
4648
{
47-
return 'LessThanOrEqualValidator';
49+
return LessThanOrEqualValidator::class;
4850
}
4951
}

src/Symfony/Component/Validator/Constraints/Positive.php

+12-10
Original file line numberDiff line numberDiff line change
@@ -27,23 +27,25 @@ public function __construct($options = null)
2727
{
2828
if (null === $options) {
2929
$options = array();
30+
} elseif (!is_array($options)) {
31+
$options = array($this->getDefaultOption() => $options);
3032
}
3133

32-
if (\is_array($options)) {
33-
if (isset($options['propertyPath'])) {
34-
throw new ConstraintDefinitionException(sprintf('The "propertyPath" option of the "%s" constraint cannot be set.', \get_class($this)));
35-
}
34+
if (isset($options['propertyPath'])) {
35+
throw new ConstraintDefinitionException(sprintf('The "propertyPath" option of the "%s" constraint cannot be set.', \get_class($this)));
36+
}
3637

37-
if (isset($options['value'])) {
38-
throw new ConstraintDefinitionException(sprintf('The "value" option of the "%s" constraint cannot be set.', \get_class($this)));
39-
}
38+
if (isset($options['value'])) {
39+
throw new ConstraintDefinitionException(sprintf('The "value" option of the "%s" constraint cannot be set.', \get_class($this)));
4040
}
4141

42-
parent::__construct($options = array_merge((array) $options, array('value' => 0)));
42+
$options['value'] = 0;
43+
44+
parent::__construct($options);
4345
}
4446

45-
public function validatedBy()
47+
public function validatedBy(): string
4648
{
47-
return 'GreaterThanValidator';
49+
return GreaterThanValidator::class;
4850
}
4951
}

src/Symfony/Component/Validator/Constraints/PositiveOrZero.php

+12-10
Original file line numberDiff line numberDiff line change
@@ -27,23 +27,25 @@ public function __construct($options = null)
2727
{
2828
if (null === $options) {
2929
$options = array();
30+
} elseif (!is_array($options)) {
31+
$options = array($this->getDefaultOption() => $options);
3032
}
3133

32-
if (\is_array($options)) {
33-
if (isset($options['propertyPath'])) {
34-
throw new ConstraintDefinitionException(sprintf('The "propertyPath" option of the "%s" constraint cannot be set.', \get_class($this)));
35-
}
34+
if (isset($options['propertyPath'])) {
35+
throw new ConstraintDefinitionException(sprintf('The "propertyPath" option of the "%s" constraint cannot be set.', \get_class($this)));
36+
}
3637

37-
if (isset($options['value'])) {
38-
throw new ConstraintDefinitionException(sprintf('The "value" option of the "%s" constraint cannot be set.', \get_class($this)));
39-
}
38+
if (isset($options['value'])) {
39+
throw new ConstraintDefinitionException(sprintf('The "value" option of the "%s" constraint cannot be set.', \get_class($this)));
4040
}
4141

42-
parent::__construct($options = array_merge((array) $options, array('value' => 0)));
42+
$options['value'] = 0;
43+
44+
parent::__construct($options);
4345
}
4446

45-
public function validatedBy()
47+
public function validatedBy(): string
4648
{
47-
return 'GreaterThanOrEqualValidator';
49+
return GreaterThanOrEqualValidator::class;
4850
}
4951
}

0 commit comments

Comments
 (0)