Conditions | 6 |
Paths | 9 |
Total Lines | 25 |
Code Lines | 13 |
Lines | 0 |
Ratio | 0 % |
Tests | 10 |
CRAP Score | 6.4425 |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
11 | 7 | public function __construct(array $properties = []) |
|
12 | { |
||
13 | /* Validate required */ |
||
14 | |||
15 | 7 | foreach ($this->getRequiredProperties() as $property) { |
|
16 | 5 | if (!isset($properties[$property])) { |
|
17 | 1 | throw new InvalidArgumentException( |
|
18 | 1 | sprintf('Property "%s" is required.', $property) |
|
19 | ); |
||
20 | } |
||
21 | } |
||
22 | |||
23 | /** |
||
24 | * @var string $option |
||
25 | * @var mixed $value |
||
26 | */ |
||
27 | 7 | foreach ($properties as $option => $value) { |
|
28 | 7 | $setter = 'set' . ucfirst($option); |
|
29 | 7 | if (method_exists($this, $setter)) { |
|
30 | call_user_func([$this, $setter], $value); |
||
31 | 7 | } elseif (property_exists($this, $option)) { |
|
32 | 7 | $this->$option = $value; |
|
33 | } else { |
||
34 | throw new InvalidArgumentException( |
||
35 | sprintf('Property "%s" not found in class "%s".', $option, static::class) |
||
36 | ); |
||
58 |