ImmutableArrayIterator::__get()   A
last analyzed

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 1
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 309
    public function __get(string $key)
13
    {
14 309
        return $this->offsetGet($key);
15
    }
16
17 15
    public function __isset(string $key): bool
18
    {
19 15
        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 9
    public function offsetExists($index) // phpcs:ignore
49
    {
50 9
        if (! \array_key_exists($index, $this->getArrayCopy())) {
51 3
            throw new \OutOfRangeException(\sprintf('Unknown property: %s', $index));
52
        }
53
54 6
        return parent::offsetExists($index);
55
    }
56
57
    /**
58
     * @param string $key
59
     *
60
     * @return mixed|null
61
     */
62 315
    public function offsetGet($key) // phpcs:ignore
63
    {
64 315
        if (\array_key_exists($key, $this->getArrayCopy())) {
65 309
            return parent::offsetExists($key)
66 309
                ? parent::offsetGet($key)
67 309
                : null;
68
        }
69
70 33
        $method = 'get' . \ucfirst(\substr($key, 0, 3) === 'get' ? \substr($key, 3) : $key);
71 33
        if (! \method_exists($this, $method)) {
72 12
            throw new \OutOfRangeException(\sprintf('Unknown property: %s', $key));
73
        }
74
75 21
        return $this->$method();
76
    }
77
78
    /**
79
     * @param string $offset
80
     * @param mixed  $value
81
     */
82 3
    final public function offsetSet($offset, $value): void // phpcs:ignore
83
    {
84 3
        throw new \BadMethodCallException('Unable to modify immutable object.');
85
    }
86
87
    /**
88
     * @param string $offset
89
     */
90 3
    final public function offsetUnset($offset): void // phpcs:ignore
91
    {
92 3
        throw new \BadMethodCallException('Unable to modify immutable object.');
93
    }
94
95
    /**
96
     * @param mixed $flags
97
     */
98 3
    final public function setFlags($flags): void // phpcs:ignore
99
    {
100 3
        throw new \BadMethodCallException('Unable to modify immutable object.');
101
    }
102
}
103