ConstCollection   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 7
c 1
b 0
f 1
lcom 1
cbo 1
dl 0
loc 64
ccs 15
cts 15
cp 1
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A offsetGet() 0 4 1
A offsetSet() 0 4 1
A offsetUnset() 0 4 1
A offsetExists() 0 4 1
A getIterator() 0 4 1
A count() 0 4 1
1
<?php
2
/**
3
 * spindle/types
4
 *
5
 * @license CC0-1.0 (Public Domain) https://creativecommons.org/publicdomain/zero/1.0/
6
 */
7
namespace Spindle\Types;
8
9
/**
10
 * Collection型を書き換え不能にデコレートします。
11
 * ただし、内包するCollection自体は書き換え可能のままなので、
12
 * ConstCollectionを経由せずに編集することは可能です。
13
 */
14
class ConstCollection implements
15
    \ArrayAccess,
16
    \Countable,
17
    \IteratorAggregate
18
{
19
    private $collection;
20
21 3
    function __construct(Collection $c)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
22
    {
23 3
        $this->collection = $c;
24 3
    }
25
26
    /**
27
     * 内部のCollectionのデータを読み出します
28
     * @param int $offset
29
     * @return mixed
30
     */
31 1
    function offsetGet($offset)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
32
    {
33 1
        return $this->collection[$offset];
34
    }
35
36
    /**
37
     * 書き換えは禁止されています
38
     */
39 1
    final function offsetSet($offset, $value)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
40
    {
41 1
        throw new \RuntimeException('ConstCollection is frozen.');
42
    }
43
44
    /**
45
     * 書き換えは禁止されています
46
     */
47 1
    final function offsetUnset($offset)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
48
    {
49 1
        throw new \RuntimeException('ConstCollection is frozen.');
50
    }
51
52
    /**
53
     * 要素が実在するかを調べます
54
     * @param int $offset
55
     * @return bool
56
     */
57 1
    function offsetExists($offset)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
58
    {
59 1
        return $this->collection->offsetExists($offset);
60
    }
61
62
    /**
63
     * @return \ArrayIterator
64
     */
65 1
    function getIterator()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
66
    {
67 1
        return new \ArrayIterator((array)$this->collection);
68
    }
69
70
    /**
71
     * @return int
72
     */
73 1
    function count()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
74
    {
75 1
        return count($this->collection);
76
    }
77
}
78