| Conditions | 4 |
| Paths | 4 |
| Total Lines | 23 |
| Code Lines | 11 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 13 |
| CRAP Score | 4 |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 20 | 65 | public function __construct(array $properties = []) |
|
| 21 | { |
||
| 22 | 65 | foreach ($properties as $key => $value) { |
|
| 23 | |||
| 24 | 35 | $method = 'set' . $key; |
|
| 25 | |||
| 26 | 35 | if (!is_scalar($value)) { |
|
| 27 | 1 | throw new InvalidArgumentException( |
|
| 28 | 1 | 'Invalid value ' . var_export($value, true) . |
|
| 29 | 1 | ' for ' . $key . ' in ' . __CLASS__ |
|
| 30 | 1 | ); |
|
| 31 | } |
||
| 32 | |||
| 33 | 34 | $callable = [$this, $method]; |
|
| 34 | 34 | if (!is_callable($callable)) { |
|
| 35 | // From now on, we support setting properties where no setters are defined for. |
||
| 36 | // This is because the context settings can vary per version. In this way we can support new |
||
| 37 | // non-existing properties. |
||
| 38 | 2 | $this->properties[$key] = $value; |
|
| 39 | 2 | continue; |
|
| 40 | } |
||
| 41 | |||
| 42 | 32 | call_user_func($callable, $value); |
|
| 43 | } |
||
| 55 | } |