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

Extensions   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A offsetExists() 0 4 1
A offsetGet() 0 8 2
A offsetSet() 0 4 1
A offsetUnset() 0 4 1
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