ArrayList   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 47
ccs 18
cts 18
cp 1
rs 10
c 0
b 0
f 0
wmc 7

5 Methods

Rating   Name   Duplication   Size   Complexity  
A get() 0 3 1
A set() 0 4 1
A __construct() 0 5 2
A toArray() 0 3 1
A __call() 0 8 2
1
<?php
2
/**
3
 * @category    Brownie/CartsGuru
4
 * @author      Brownie <[email protected]>
5
 * @license     http://www.gnu.org/copyleft/lesser.html
6
 */
7
8
namespace Brownie\CartsGuru\Model\Base;
9
10
use Brownie\CartsGuru\Exception\UndefinedMethodException;
11
12
/**
13
 * Storage array.
14
 */
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)
50
    {
51 8
        return $this->fields[$name];
52
    }
53
54
    /**
55
     * Returns the field list as an array.
56
     *
57
     * @return array
58
     */
59 8
    public function toArray()
60
    {
61 8
        return $this->fields;
62
    }
63
}
64