| Total Complexity | 13 |
| Total Lines | 65 |
| Duplicated Lines | 0 % |
| Coverage | 92.86% |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 9 | class ValueObject |
||
| 10 | { |
||
| 11 | const STRING = 'string'; |
||
| 12 | const INT = 'int'; |
||
| 13 | const FLOAT = 'float'; |
||
| 14 | const BOOL = 'bool'; |
||
| 15 | |||
| 16 | private $value; |
||
| 17 | /** |
||
| 18 | * @var null |
||
| 19 | */ |
||
| 20 | private $type; |
||
| 21 | private $name; |
||
| 22 | |||
| 23 | 51 | public function __construct($name, $value, $type = null) |
|
| 24 | { |
||
| 25 | 51 | $this->name = $name; |
|
| 26 | 51 | $this->value = $value; |
|
| 27 | 51 | if(!in_array($type, $this->types())) throw new ValueObjectInvalidTypeException('Wrong type: '. $type); |
|
| 28 | 50 | $this->type = $type; |
|
| 29 | 50 | } |
|
| 30 | |||
| 31 | 1 | public function __invoke(){ |
|
| 33 | } |
||
| 34 | |||
| 35 | 41 | public function name(){ |
|
| 36 | 41 | return $this->name; |
|
| 37 | } |
||
| 38 | |||
| 39 | 39 | public function value(){ |
|
| 40 | 39 | return $this->value; |
|
| 41 | } |
||
| 42 | |||
| 43 | 1 | public function type(){ |
|
| 44 | 1 | return $this->type; |
|
| 45 | } |
||
| 46 | |||
| 47 | 4 | public function isInt(){ |
|
| 48 | 4 | return $this->type === self::INT; |
|
| 49 | } |
||
| 50 | |||
| 51 | |||
| 52 | 2 | public function isString(){ |
|
| 53 | 2 | return $this->type === self::STRING; |
|
| 54 | } |
||
| 55 | |||
| 56 | 2 | public function isBool(){ |
|
| 57 | 2 | return $this->type === self::BOOL; |
|
| 58 | } |
||
| 59 | |||
| 60 | 1 | public function isFloat(){ |
|
| 61 | 1 | return $this->type === self::FLOAT; |
|
| 62 | } |
||
| 63 | |||
| 64 | 1 | public function isUndefinedType(){ |
|
| 65 | 1 | return is_null($this->type); |
|
| 66 | } |
||
| 67 | |||
| 68 | 51 | protected function types(){ |
|
| 69 | 51 | return [null, self::BOOL, self::FLOAT, self::INT, self::STRING]; |
|
| 70 | } |
||
| 71 | |||
| 72 | public static function get($value, $type = null){ |
||
| 74 | } |
||
| 75 | |||
| 76 | |||
| 77 | } |