Test Failed
Push — docs ( 541d16...38ea2c )
by Mark
35:24
created

ImmutableArrayIterator::__set()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 2
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace League\Emoji\Util;
6
7
class ImmutableArrayIterator extends \ArrayIterator
8
{
9
    /**
10
     * @return mixed
11
     */
12 84
    public function __get(string $key)
13
    {
14 84
        return $this->offsetGet($key);
15
    }
16
17 54
    public function __isset(string $key): bool
18
    {
19 54
        return $this->__get($key) !== null;
20
    }
21
22
    /**
23
     * @param mixed $value
24
     */
25 3
    public function __set(string $key, $value): void
26
    {
27 3
        throw new \BadMethodCallException('Unable to modify immutable object.');
28
    }
29
30 3
    public function __unset(string $key): void
31
    {
32 3
        throw new \BadMethodCallException('Unable to modify immutable object.');
33
    }
34
35
    /**
36
     * @param mixed $value
37
     */
38 3
    final public function append($value): void
39
    {
40 3
        throw new \BadMethodCallException('Unable to modify immutable object.');
41
    }
42
43
    /**
44
     * @param string $index
45
     *
46
     * @return bool
47
     */
48 6
    public function offsetExists($index) // phpcs:ignore
49
    {
50 6
        if (! \array_key_exists($index, $this->getArrayCopy())) {
51 3
            throw new \OutOfRangeException(\sprintf('Unknown property: %s', $index));
52
        }
53
54 3
        return parent::offsetExists($index);
55
    }
56
57
    /**
58
     * @param string $key
59
     *
60
     * @return mixed|null
61
     */
62 117
    public function offsetGet($key) // phpcs:ignore
63
    {
64 117
        if (\array_key_exists($key, $this->getArrayCopy())) {
65 111
            return parent::offsetExists($key)
66
                ? parent::offsetGet($key)
67
                : null;
68 27
        }
69 27
70 9
        $method = 'get' . \ucfirst(\substr($key, 0, 3) === 'get' ? \substr($key, 3) : $key);
71
        if (! \method_exists($this, $method)) {
72
            throw new \OutOfRangeException(\sprintf('Unknown property: %s', $key));
73 21
        }
74
75
        return $this->$method();
76
    }
77
78
    /**
79
     * @param string $offset
80 3
     * @param mixed  $value
81
     */
82 3
    final public function offsetSet($offset, $value): void // phpcs:ignore
83
    {
84
        throw new \BadMethodCallException('Unable to modify immutable object.');
85
    }
86
87
    /**
88 3
     * @param string $offset
89
     */
90 3
    final public function offsetUnset($offset): void // phpcs:ignore
91
    {
92
        throw new \BadMethodCallException('Unable to modify immutable object.');
93
    }
94
95
    /**
96 3
     * @param mixed $flags
97
     */
98 3
    final public function setFlags($flags): void // phpcs:ignore
99
    {
100
        throw new \BadMethodCallException('Unable to modify immutable object.');
101
    }
102
}
103