| Total Complexity | 7 |
| Total Lines | 47 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 0 | ||
| 1 | <?php |
||
| 15 | abstract class ArrayList |
||
| 16 | { |
||
| 17 | |||
| 18 | /** |
||
| 19 | * List of supported fields. |
||
| 20 | * |
||
| 21 | * @var array |
||
| 22 | */ |
||
| 23 | protected $fields = array(); |
||
| 24 | |||
| 25 | 17 | public function __construct($values = array()) |
|
| 26 | { |
||
| 27 | 17 | foreach ($values as $key => $value) { |
|
| 28 | 3 | $method = 'set' . ucfirst($key); |
|
| 29 | 3 | $this->$method($value); |
|
| 30 | } |
||
| 31 | 17 | } |
|
| 32 | |||
| 33 | 15 | public function __call($name, $values) |
|
| 34 | { |
||
| 35 | 15 | $method = substr($name, 0, 3); |
|
| 36 | 15 | $nameField = lcfirst(substr($name, 3)); |
|
| 37 | 15 | if (!array_key_exists($nameField, $this->fields)) { |
|
| 38 | 1 | throw new UndefinedMethodException('Call to undefined method ' . $name); |
|
| 39 | } |
||
| 40 | 15 | return $this->$method($nameField, $values); |
|
| 41 | } |
||
| 42 | |||
| 43 | 15 | private function set($name, $values) |
|
| 44 | { |
||
| 45 | 15 | $this->fields[$name] = $values[0]; |
|
| 46 | 15 | return $this; |
|
| 47 | } |
||
| 48 | |||
| 49 | 8 | private function get($name) |
|
| 52 | } |
||
| 53 | |||
| 54 | /** |
||
| 55 | * Returns the field list as an array. |
||
| 56 | * |
||
| 57 | * @return array |
||
| 58 | */ |
||
| 59 | 8 | public function toArray() |
|
| 62 | } |
||
| 63 | } |
||
| 64 |