Completed
Pull Request — master (#15)
by Christian
02: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
/*
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
 * xAPI statement extensions.
18
 *
19
 * @author Christian Flothmann <[email protected]>
20
 */
21
final class Extensions implements \ArrayAccess
22
{
23
    private $extensions;
24
25
    public function __construct(array $extensions)
26
    {
27
        $this->extensions = $extensions;
28
    }
29
30
    /**
31
     * {@inheritdoc}
32
     */
33
    public function offsetExists($offset)
34
    {
35
        return isset($this->extensions[$offset]);
36
    }
37
38
    /**
39
     * {@inheritdoc}
40
     */
41
    public function offsetGet($offset)
42
    {
43
        if (!isset($this->extensions[$offset])) {
44
            throw new \InvalidArgumentException(sprintf('No extension for key "%s" registered.', $offset));
45
        }
46
47
        return $this->extensions[$offset];
48
    }
49
50
    /**
51
     * {@inheritdoc}
52
     */
53
    public function offsetSet($offset, $value)
54
    {
55
        throw new UnsupportedOperationException('xAPI statement extensions are immutable.');
56
    }
57
58
    /**
59
     * {@inheritdoc}
60
     */
61
    public function offsetUnset($offset)
62
    {
63
        throw new UnsupportedOperationException('xAPI statement extensions are immutable.');
64
    }
65
}
66