Completed
Pull Request — master (#15)
by Christian
03:51
created

Extensions::offsetSet()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 2
1
<?php
2
3
namespace Xabbuh\XApi\Model;
4
5
use Xabbuh\XApi\Common\Exception\UnsupportedOperationException;
6
7
/**
8
 * xAPI statement extensions.
9
 *
10
 * @author Christian Flothmann <[email protected]>
11
 */
12
final class Extensions implements \ArrayAccess
13
{
14
    private $extensions;
15
16
    public function __construct(array $extensions)
17
    {
18
        $this->extensions = $extensions;
19
    }
20
21
    /**
22
     * {@inheritdoc}
23
     */
24
    public function offsetExists($offset)
25
    {
26
        return isset($this->extensions[$offset]);
27
    }
28
29
    /**
30
     * {@inheritdoc}
31
     */
32
    public function offsetGet($offset)
33
    {
34
        if (!isset($this->extensions[$offset])) {
35
            throw new \InvalidArgumentException(sprintf('No extension for key "%s" registered.', $offset));
36
        }
37
38
        return $this->extensions[$offset];
39
    }
40
41
    /**
42
     * {@inheritdoc}
43
     */
44
    public function offsetSet($offset, $value)
45
    {
46
        throw new UnsupportedOperationException('xAPI statement extensions are immutable.');
47
    }
48
49
    /**
50
     * {@inheritdoc}
51
     */
52
    public function offsetUnset($offset)
53
    {
54
        throw new UnsupportedOperationException('xAPI statement extensions are immutable.');
55
    }
56
}
57