@@ -14,15 +14,15 @@ |
||
| 14 | 14 | $this->data = $data; |
| 15 | 15 | } |
| 16 | 16 | |
| 17 | - public function get($key){ |
|
| 18 | - if(preg_match("/^(\S*)\s*as\s*(\S*)$/",$key, $matches)){ |
|
| 17 | + public function get($key) { |
|
| 18 | + if (preg_match("/^(\S*)\s*as\s*(\S*)$/", $key, $matches)) { |
|
| 19 | 19 | $name = $matches[1]; |
| 20 | 20 | $alias = $matches[2]; |
| 21 | 21 | } else { |
| 22 | 22 | $name = $key; |
| 23 | 23 | $alias = $key; |
| 24 | 24 | } |
| 25 | - if(!isset($this->data[$name])) return new NullValueObject($name, null); |
|
| 25 | + if (!isset($this->data[$name])) return new NullValueObject($name, null); |
|
| 26 | 26 | |
| 27 | 27 | $value = new ValueObject($name, $this->data[$name]); |
| 28 | 28 | $value->setAlias($alias); |
@@ -22,7 +22,9 @@ |
||
| 22 | 22 | $name = $key; |
| 23 | 23 | $alias = $key; |
| 24 | 24 | } |
| 25 | - if(!isset($this->data[$name])) return new NullValueObject($name, null); |
|
| 25 | + if(!isset($this->data[$name])) { |
|
| 26 | + return new NullValueObject($name, null); |
|
| 27 | + } |
|
| 26 | 28 | |
| 27 | 29 | $value = new ValueObject($name, $this->data[$name]); |
| 28 | 30 | $value->setAlias($alias); |
@@ -26,16 +26,16 @@ discard block |
||
| 26 | 26 | $this->name = $name; |
| 27 | 27 | $this->alias = $name; |
| 28 | 28 | $this->value = $value; |
| 29 | - if(!in_array($type, $this->types())) throw new ValueObjectInvalidTypeException('Wrong type: '. $type); |
|
| 29 | + if (!in_array($type, $this->types())) throw new ValueObjectInvalidTypeException('Wrong type: '.$type); |
|
| 30 | 30 | $this->type = $type; |
| 31 | 31 | } |
| 32 | 32 | |
| 33 | - public function setAlias($alias){ |
|
| 33 | + public function setAlias($alias) { |
|
| 34 | 34 | $this->alias = $alias; |
| 35 | 35 | } |
| 36 | 36 | |
| 37 | - protected function setName($name){ |
|
| 38 | - if(preg_match("/^(\S*)\s*as\s*(\S*)$/",$name, $matches)){ |
|
| 37 | + protected function setName($name) { |
|
| 38 | + if (preg_match("/^(\S*)\s*as\s*(\S*)$/", $name, $matches)) { |
|
| 39 | 39 | $this->name = $matches[1]; |
| 40 | 40 | $this->alias = $matches[2]; |
| 41 | 41 | } else { |
@@ -46,52 +46,52 @@ discard block |
||
| 46 | 46 | } |
| 47 | 47 | |
| 48 | 48 | |
| 49 | - public function __invoke(){ |
|
| 49 | + public function __invoke() { |
|
| 50 | 50 | return $this->value; |
| 51 | 51 | } |
| 52 | 52 | |
| 53 | - public function name(){ |
|
| 53 | + public function name() { |
|
| 54 | 54 | return $this->name; |
| 55 | 55 | } |
| 56 | 56 | |
| 57 | - public function alias(){ |
|
| 57 | + public function alias() { |
|
| 58 | 58 | return $this->alias; |
| 59 | 59 | } |
| 60 | 60 | |
| 61 | - public function value(){ |
|
| 61 | + public function value() { |
|
| 62 | 62 | return $this->value; |
| 63 | 63 | } |
| 64 | 64 | |
| 65 | - public function type(){ |
|
| 65 | + public function type() { |
|
| 66 | 66 | return $this->type; |
| 67 | 67 | } |
| 68 | 68 | |
| 69 | - public function isInt(){ |
|
| 69 | + public function isInt() { |
|
| 70 | 70 | return $this->type === self::INT; |
| 71 | 71 | } |
| 72 | 72 | |
| 73 | 73 | |
| 74 | - public function isString(){ |
|
| 74 | + public function isString() { |
|
| 75 | 75 | return $this->type === self::STRING; |
| 76 | 76 | } |
| 77 | 77 | |
| 78 | - public function isBool(){ |
|
| 78 | + public function isBool() { |
|
| 79 | 79 | return $this->type === self::BOOL; |
| 80 | 80 | } |
| 81 | 81 | |
| 82 | - public function isFloat(){ |
|
| 82 | + public function isFloat() { |
|
| 83 | 83 | return $this->type === self::FLOAT; |
| 84 | 84 | } |
| 85 | 85 | |
| 86 | - public function isUndefinedType(){ |
|
| 86 | + public function isUndefinedType() { |
|
| 87 | 87 | return is_null($this->type); |
| 88 | 88 | } |
| 89 | 89 | |
| 90 | - protected function types(){ |
|
| 90 | + protected function types() { |
|
| 91 | 91 | return [null, self::BOOL, self::FLOAT, self::INT, self::STRING]; |
| 92 | 92 | } |
| 93 | 93 | |
| 94 | - public static function get($value, $type = null){ |
|
| 94 | + public static function get($value, $type = null) { |
|
| 95 | 95 | return new static($value, $type); |
| 96 | 96 | } |
| 97 | 97 | |
@@ -26,7 +26,9 @@ |
||
| 26 | 26 | $this->name = $name; |
| 27 | 27 | $this->alias = $name; |
| 28 | 28 | $this->value = $value; |
| 29 | - if(!in_array($type, $this->types())) throw new ValueObjectInvalidTypeException('Wrong type: '. $type); |
|
| 29 | + if(!in_array($type, $this->types())) { |
|
| 30 | + throw new ValueObjectInvalidTypeException('Wrong type: '. $type); |
|
| 31 | + } |
|
| 30 | 32 | $this->type = $type; |
| 31 | 33 | } |
| 32 | 34 | |
@@ -14,15 +14,15 @@ discard block |
||
| 14 | 14 | |
| 15 | 15 | public function __construct($options, ValidationFactory $validationFactory) |
| 16 | 16 | { |
| 17 | - $this->validations = explode(" ",$options); |
|
| 17 | + $this->validations = explode(" ", $options); |
|
| 18 | 18 | $this->factory = $validationFactory; |
| 19 | 19 | } |
| 20 | 20 | |
| 21 | - public function process(ValueObject $data){ |
|
| 21 | + public function process(ValueObject $data) { |
|
| 22 | 22 | $dataIsValid = true; |
| 23 | - foreach ($this->validations as $validation){ |
|
| 23 | + foreach ($this->validations as $validation) { |
|
| 24 | 24 | $validation = $this->factory->get($validation); |
| 25 | - if(!$validation->validate($data)){ |
|
| 25 | + if (!$validation->validate($data)) { |
|
| 26 | 26 | $this->errors[] = $validation->error(); |
| 27 | 27 | $dataIsValid = false; |
| 28 | 28 | } |
@@ -30,7 +30,7 @@ discard block |
||
| 30 | 30 | return $dataIsValid; |
| 31 | 31 | } |
| 32 | 32 | |
| 33 | - public function errors(){ |
|
| 33 | + public function errors() { |
|
| 34 | 34 | return $this->errors; |
| 35 | 35 | } |
| 36 | 36 | } |
| 37 | 37 | \ No newline at end of file |