Collection   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 1 Features 1
Metric Value
wmc 6
c 3
b 1
f 1
lcom 0
cbo 0
dl 0
loc 54
ccs 19
cts 19
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __get() 0 4 1
A __set() 0 4 1
A offsetSet() 0 10 2
A fromArray() 0 11 2
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
 * 厳密な配列を実現するクラス。
11
 * 添え字は0から始まり、必ず順番が守られる。
12
 * 文字列の添え字は許可されない。
13
 */
14
abstract class Collection extends \SplFixedArray
15
{
16
    /**
17
     * SplFixedArrayは固定長になってしまうため、自動伸長機能を追加
18
     * @param int $offset
19
     * @param mixed $value
20
     * @return void
21
     */
22 5
    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...
23
    {
24 5
        if ($offset === null) {
25 1
            $cnt = count($this);
26 1
            $this->setSize($cnt + 1);
27 1
            $offset = $cnt;
28 1
        }
29
30 5
        return parent::offsetSet($offset, $value);
31
    }
32
33
    /**
34
     * SplFixedArray固定ではなく、継承した子クラスを返すように拡張
35
     *
36
     * @param array $array 元にする配列
37
     * @param bool $save_indexes なるべく元の添え字を保持しようとするかどうか
38
     * @return static
39
     */
40 4
    static function fromArray($array, $save_indexes=true)
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...
41
    {
42 4
        $splFixedArray = \SplFixedArray::fromArray($array, $save_indexes);
43 4
        $cnt = count($array);
44 4
        $self = new static($cnt);
45 4
        foreach ($splFixedArray as $i => $v) {
46 4
            $self[$i] = $v;
47 4
        }
48
49 4
        return $self;
50
    }
51
52
    /**
53
     * getterは許可しない
54
     */
55 1
    function __get($name)
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...
56
    {
57 1
        throw new \RuntimeException(__CLASS__ . "->$name is not allowed");
58
    }
59
60
    /**
61
     * setterは許可しない
62
     */
63 1
    function __set($name, $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...
64
    {
65 1
        throw new \RuntimeException(__CLASS__ . "->$name = $value is not allowed");
66
    }
67
}
68