Conditions | 4 |
Paths | 4 |
Total Lines | 13 |
Code Lines | 8 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
21 | public function initFromArray(array $data) |
||
22 | { |
||
23 | foreach ($data as $name => $value) { |
||
24 | $method = 'set' . ucfirst($name); |
||
25 | if (method_exists($this, $method)) { |
||
26 | call_user_func_array([$this, $method], [$value]); |
||
27 | } else { |
||
28 | if (property_exists(get_called_class(), $name)) { |
||
29 | $this->$name = $value; |
||
30 | } |
||
31 | } |
||
32 | } |
||
33 | } |
||
34 | |||
48 | } |
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: