Conditions | 5 |
Paths | 6 |
Total Lines | 16 |
Code Lines | 8 |
Lines | 0 |
Ratio | 0 % |
Tests | 10 |
CRAP Score | 5 |
Changes | 1 | ||
Bugs | 0 | Features | 1 |
1 | <?php |
||
11 | 12 | public function __construct($value, $regex = null) |
|
12 | { |
||
13 | 12 | if ($value === null) { |
|
14 | 1 | $value = ''; |
|
15 | 1 | } |
|
16 | |||
17 | 12 | if (!is_string($value)) { |
|
18 | 5 | throw new InvalidArgumentException('Value must be a string'); |
|
19 | } |
||
20 | |||
21 | 7 | if ($regex && !preg_match($regex, $value)) { |
|
22 | 2 | throw new InvalidArgumentException('Value must match the expected format'); |
|
23 | } |
||
24 | |||
25 | 5 | $this->value = $value; |
|
26 | 5 | } |
|
27 | |||
33 |