Completed
Push — master ( fe261e...a53c69 )
by Chad
06:26 queued 04:36
created

ImmutableArrayObject::createFromMutable()   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 1
1
<?php
2
3
namespace Chadicus\Spl\DataStructures;
4
5
/**
6
 * This class behaves the same as ArrayObject disallowing modifications.
7
 */
8
final class ImmutableArrayObject extends \ArrayObject
9
{
10
    /**
11
     * @see \ArrayObject::offsetSet
12
     *
13
     * @throws \LogicException
14
     */
15
    public function offsetSet($index, $newval)
16
    {
17
        throw new \LogicException('Attempting to write to an immutable array');
18
    }
19
20
    /**
21
     * @see \ArrayObject::offsetUnset
22
     *
23
     * @throws \LogicException
24
     */
25
    public function offsetUnset($index)
26
    {
27
        throw new \LogicException('Attempting to write to an immutable array');
28
    }
29
30
    /**
31
     * @see \ArrayObject::append
32
     *
33
     * @throws \LogicException
34
     */
35
    public function append($value)
36
    {
37
        throw new \LogicException('Attempting to write to an immutable array');
38
    }
39
40
    /**
41
     * @see \ArrayObject::exchangeArray
42
     *
43
     * @throws \LogicException
44
     */
45
    public function exchangeArray($array)
46
    {
47
        throw new \LogicException('Attempting to write to an immutable array');
48
    }
49
50
    /**
51
     * Creates a new ImmutableArrayObject from the given mutable ArrayObject instance.
52
     *
53
     * @param \ArrayObject The mutable array object.
54
     *
55
     * @return ImmutableArrayObject
56
     */
57
    public static function createFromMutable(\ArrayObject $arrayObject)
58
    {
59
        return new static($arrayObject->getArrayCopy(), $arrayObject->getFlags(), $arrayObject->getIteratorClass());
60
    }
61
}
62