@@ -37,7 +37,7 @@ |
||
| 37 | 37 | $options = explode(':', $validation); |
| 38 | 38 | $validationName = array_shift($options); |
| 39 | 39 | if (!array_key_exists($validationName, $this->map)) { |
| 40 | - throw new InvalidValidationNameException('unknown validation name ' . $validationName); |
|
| 40 | + throw new InvalidValidationNameException('unknown validation name '.$validationName); |
|
| 41 | 41 | } |
| 42 | 42 | return new $this->map[$validationName]($options); |
| 43 | 43 | } |
@@ -23,7 +23,9 @@ |
||
| 23 | 23 | $name = $key; |
| 24 | 24 | $alias = $key; |
| 25 | 25 | } |
| 26 | - if (!isset($this->data[$name])) return new NullValueObject($name, null); |
|
| 26 | + if (!isset($this->data[$name])) { |
|
| 27 | + return new NullValueObject($name, null); |
|
| 28 | + } |
|
| 27 | 29 | |
| 28 | 30 | $value = new ValueObject($name, $this->data[$name]); |
| 29 | 31 | $value->setAlias($alias); |
@@ -32,7 +32,7 @@ |
||
| 32 | 32 | |
| 33 | 33 | public function setType($type) |
| 34 | 34 | { |
| 35 | - if (!in_array($type, $this->types())) throw new ValueObjectInvalidTypeException('Wrong type: ' . $type); |
|
| 35 | + if (!in_array($type, $this->types())) throw new ValueObjectInvalidTypeException('Wrong type: '.$type); |
|
| 36 | 36 | $this->type = $type; |
| 37 | 37 | } |
| 38 | 38 | |
@@ -32,7 +32,9 @@ |
||
| 32 | 32 | |
| 33 | 33 | public function setType($type) |
| 34 | 34 | { |
| 35 | - if (!in_array($type, $this->types())) throw new ValueObjectInvalidTypeException('Wrong type: ' . $type); |
|
| 35 | + if (!in_array($type, $this->types())) { |
|
| 36 | + throw new ValueObjectInvalidTypeException('Wrong type: ' . $type); |
|
| 37 | + } |
|
| 36 | 38 | $this->type = $type; |
| 37 | 39 | } |
| 38 | 40 | |
@@ -14,7 +14,9 @@ |
||
| 14 | 14 | |
| 15 | 15 | public function isValid(ValueObject $data) |
| 16 | 16 | { |
| 17 | - if (is_bool($data->value())) return false; |
|
| 17 | + if (is_bool($data->value())) { |
|
| 18 | + return false; |
|
| 19 | + } |
|
| 18 | 20 | return is_int($data->value()) || preg_match('/^\d+$/', $data->value()); |
| 19 | 21 | } |
| 20 | 22 | |
@@ -17,7 +17,7 @@ |
||
| 17 | 17 | |
| 18 | 18 | public function getErrorMessage() |
| 19 | 19 | { |
| 20 | - if(!is_null($this->errorMessage)) return parent::getErrorMessage(); |
|
| 20 | + if (!is_null($this->errorMessage)) return parent::getErrorMessage(); |
|
| 21 | 21 | |
| 22 | 22 | return "{$this->data->name()} is too short (minimum {$this->options[0]} characters"; |
| 23 | 23 | } |
@@ -17,7 +17,9 @@ |
||
| 17 | 17 | |
| 18 | 18 | public function getErrorMessage() |
| 19 | 19 | { |
| 20 | - if(!is_null($this->errorMessage)) return parent::getErrorMessage(); |
|
| 20 | + if(!is_null($this->errorMessage)) { |
|
| 21 | + return parent::getErrorMessage(); |
|
| 22 | + } |
|
| 21 | 23 | |
| 22 | 24 | return "{$this->data->name()} is too short (minimum {$this->options[0]} characters"; |
| 23 | 25 | } |
@@ -14,7 +14,7 @@ |
||
| 14 | 14 | |
| 15 | 15 | public function isValid(ValueObject $data) |
| 16 | 16 | { |
| 17 | - if ( is_bool($data->value()) ) return false; |
|
| 17 | + if (is_bool($data->value())) return false; |
|
| 18 | 18 | return is_float($data->value()) || preg_match('/^[\d\.]+$/', $data->value()); |
| 19 | 19 | } |
| 20 | 20 | |
@@ -14,7 +14,9 @@ |
||
| 14 | 14 | |
| 15 | 15 | public function isValid(ValueObject $data) |
| 16 | 16 | { |
| 17 | - if ( is_bool($data->value()) ) return false; |
|
| 17 | + if ( is_bool($data->value()) ) { |
|
| 18 | + return false; |
|
| 19 | + } |
|
| 18 | 20 | return is_float($data->value()) || preg_match('/^[\d\.]+$/', $data->value()); |
| 19 | 21 | } |
| 20 | 22 | |
@@ -17,7 +17,7 @@ |
||
| 17 | 17 | |
| 18 | 18 | public function getErrorMessage() |
| 19 | 19 | { |
| 20 | - if(!is_null($this->errorMessage)) return parent::getErrorMessage(); |
|
| 20 | + if (!is_null($this->errorMessage)) return parent::getErrorMessage(); |
|
| 21 | 21 | |
| 22 | 22 | return "{$this->data->name()} is too big (maximum {$this->options[0]})"; |
| 23 | 23 | } |
@@ -17,7 +17,9 @@ |
||
| 17 | 17 | |
| 18 | 18 | public function getErrorMessage() |
| 19 | 19 | { |
| 20 | - if(!is_null($this->errorMessage)) return parent::getErrorMessage(); |
|
| 20 | + if(!is_null($this->errorMessage)) { |
|
| 21 | + return parent::getErrorMessage(); |
|
| 22 | + } |
|
| 21 | 23 | |
| 22 | 24 | return "{$this->data->name()} is too big (maximum {$this->options[0]})"; |
| 23 | 25 | } |
@@ -22,7 +22,7 @@ discard block |
||
| 22 | 22 | $this->options = $options; |
| 23 | 23 | } |
| 24 | 24 | |
| 25 | - public function setErrorMessage($message){ |
|
| 25 | + public function setErrorMessage($message) { |
|
| 26 | 26 | $this->errorMessage = $message; |
| 27 | 27 | } |
| 28 | 28 | |
@@ -31,9 +31,9 @@ discard block |
||
| 31 | 31 | return $this->error; |
| 32 | 32 | } |
| 33 | 33 | |
| 34 | - public function validate(ValueObject $data){ |
|
| 34 | + public function validate(ValueObject $data) { |
|
| 35 | 35 | $this->data = $data; |
| 36 | - if (! $this->isValid($data) ) { |
|
| 36 | + if (!$this->isValid($data)) { |
|
| 37 | 37 | $this->error = $this->getErrorMessage(); |
| 38 | 38 | $this->afterFailedValidation(); |
| 39 | 39 | return false; |
@@ -41,17 +41,17 @@ discard block |
||
| 41 | 41 | $this->afterSuccessValidation(); |
| 42 | 42 | return true; |
| 43 | 43 | } |
| 44 | - public function getErrorMessage(){ |
|
| 44 | + public function getErrorMessage() { |
|
| 45 | 45 | return str_replace("{name}", $this->data->name(), $this->errorMessage); |
| 46 | 46 | } |
| 47 | 47 | |
| 48 | 48 | abstract public function isValid(ValueObject $data); |
| 49 | 49 | |
| 50 | - protected function afterSuccessValidation(){ |
|
| 50 | + protected function afterSuccessValidation() { |
|
| 51 | 51 | |
| 52 | 52 | } |
| 53 | 53 | |
| 54 | - protected function afterFailedValidation(){ |
|
| 54 | + protected function afterFailedValidation() { |
|
| 55 | 55 | |
| 56 | 56 | } |
| 57 | 57 | |
@@ -16,7 +16,7 @@ |
||
| 16 | 16 | |
| 17 | 17 | public function getErrorMessage() |
| 18 | 18 | { |
| 19 | - if(!is_null($this->errorMessage)) return parent::getErrorMessage(); |
|
| 19 | + if (!is_null($this->errorMessage)) return parent::getErrorMessage(); |
|
| 20 | 20 | |
| 21 | 21 | return "{$this->data->name()} is too long (maximum {$this->options[0]} characters"; |
| 22 | 22 | } |
@@ -16,7 +16,9 @@ |
||
| 16 | 16 | |
| 17 | 17 | public function getErrorMessage() |
| 18 | 18 | { |
| 19 | - if(!is_null($this->errorMessage)) return parent::getErrorMessage(); |
|
| 19 | + if(!is_null($this->errorMessage)) { |
|
| 20 | + return parent::getErrorMessage(); |
|
| 21 | + } |
|
| 20 | 22 | |
| 21 | 23 | return "{$this->data->name()} is too long (maximum {$this->options[0]} characters"; |
| 22 | 24 | } |