Row   A
last analyzed

Complexity

Total Complexity 14

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 61
rs 10
c 0
b 0
f 0
wmc 14
lcom 1
cbo 1

9 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 3
A __get() 0 4 1
A offsetSet() 0 4 1
A offsetExists() 0 4 2
A offsetUnset() 0 4 1
A offsetGet() 0 9 3
A getIterator() 0 4 1
A count() 0 4 1
A toArray() 0 4 1
1
<?php
2
3
namespace Scriptotek\Alma\Analytics;
4
5
use Danmichaelo\QuiteSimpleXMLElement\QuiteSimpleXMLElement;
6
7
/**
8
 * A single Row belonging to some Report.
9
 */
10
class Row implements \ArrayAccess, \IteratorAggregate, \Countable
11
{
12
    protected $byIndex = [];
13
    protected $byHeader = [];
14
    protected $headers;
15
16
    public function __construct(QuiteSimpleXMLElement $data, $headers)
17
    {
18
        $this->headers = $headers;
19
        foreach ($headers as $idx => $header) {
20
            $value = $data->text('rowset:Column' . ($idx + 1)) ?: null;
21
            $this->byIndex[$idx] = $value;
22
            $this->byHeader[$header] = $value;
23
        }
24
    }
25
26
    public function __get($name)
27
    {
28
        return $this->byHeader[$name];
29
    }
30
31
    public function offsetSet($offset, $value)
32
    {
33
        throw new \RuntimeException('Sorry, column values cannot be modified.');
34
    }
35
36
    public function offsetExists($offset)
37
    {
38
        return isset($this->byIndex[$offset]) || isset($this->byHeader[$offset]);
39
    }
40
41
    public function offsetUnset($offset)
42
    {
43
        throw new \RuntimeException('Sorry, column values cannot be modified.');
44
    }
45
46
    public function offsetGet($offset)
47
    {
48
        if (isset($this->byIndex[$offset])) {
49
            return $this->byIndex[$offset];
50
        }
51
        if (isset($this->byHeader[$offset])) {
52
            return $this->byHeader[$offset];
53
        }
54
    }
55
56
    public function getIterator()
57
    {
58
        return new \ArrayIterator($this->byHeader);
59
    }
60
61
    public function count()
62
    {
63
        return count($this->byIndex);
64
    }
65
66
    public function toArray()
67
    {
68
        return $this->byHeader;
69
    }
70
}
71