Skip to content

Commit

Permalink
🐛 FIX: Do not change value on error #8
Browse files Browse the repository at this point in the history
  • Loading branch information
elie29 committed Feb 23, 2019
1 parent eba7efe commit 42b3fda
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 6 deletions.
7 changes: 4 additions & 3 deletions src/Rule/ArrayRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,11 @@ public function __construct(string $key, $value, array $params = [])

public function getValue()
{
if (! $this->value) {
return [];
// don't change value on error or if it is not empty
if ($this->value || $this->error) {
return $this->value;
}
return $this->value;
return [];
}

public function validate(): int
Expand Down
2 changes: 1 addition & 1 deletion src/Rule/BicRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class BicRule extends AbstractRule
* Params could have the following structure:
* [
* 'required' => {bool:optional:false by default},
* 'trim' => {bool:optional:true by default},
* 'trim' => {bool:optional:true by default},
* 'messages' => {array:optional:key/value message patterns}
* ]
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Rule/BooleanRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function __construct(string $key, $value, array $params = [])

public function getValue()
{
if ($this->cast) {
if ($this->cast && ! $this->error) {
return (bool) $this->value;
}
return $this->value;
Expand Down
2 changes: 1 addition & 1 deletion src/Rule/NumericRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public function __construct(string $key, $value, array $params = [])

public function getValue()
{
if ($this->cast) {
if ($this->cast && ! $this->error) {
// float or int and empty value
return $this->value ? 0 + $this->value : 0;
}
Expand Down

0 comments on commit 42b3fda

Please sign in to comment.