DocumentData   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
c 1
b 0
f 0
lcom 1
cbo 1
dl 0
loc 54
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A offsetExists() 0 4 1
A offsetGet() 0 4 1
A offsetSet() 0 4 1
A offsetUnset() 0 4 1
A getData() 0 4 1
1
<?php
2
3
/*
4
 * This file is part of the xAPI package.
5
 *
6
 * (c) Christian Flothmann <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Xabbuh\XApi\Model;
13
14
use Xabbuh\XApi\Common\Exception\UnsupportedOperationException;
15
16
/**
17
 * An xAPI document's data.
18
 *
19
 * Document data are immutable. This means that they can be accessed like an array.
20
 * But you can only do this to read data. Thus an {@link UnsupportedOperationException}
21
 * is thrown when you try to unset data or to manipulate them.
22
 *
23
 * @author Christian Flothmann <[email protected]>
24
 */
25
final class DocumentData implements \ArrayAccess
26
{
27
    /**
28
     * @var array The data
29
     */
30
    private $data = array();
31
32
    public function __construct(array $data = array())
33
    {
34
        $this->data = $data;
35
    }
36
37
    /**
38
     * {@inheritDoc}
39
     */
40
    public function offsetExists($offset)
41
    {
42
        return isset($this->data[$offset]);
43
    }
44
45
    /**
46
     * {@inheritDoc}
47
     */
48
    public function offsetGet($offset)
49
    {
50
        return $this->data[$offset];
51
    }
52
53
    /**
54
     * {@inheritDoc}
55
     */
56
    public function offsetSet($offset, $value)
57
    {
58
        throw new UnsupportedOperationException('A document is immutable.');
59
    }
60
61
    /**
62
     * {@inheritDoc}
63
     */
64
    public function offsetUnset($offset)
65
    {
66
        throw new UnsupportedOperationException('A document is immutable.');
67
    }
68
69
    /**
70
     * Returns all data as an array.
71
     *
72
     * @return array The data
73
     */
74
    public function getData()
75
    {
76
        return $this->data;
77
    }
78
}
79