Prototype   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 79.17%

Importance

Changes 4
Bugs 0 Features 0
Metric Value
wmc 10
c 4
b 0
f 0
lcom 1
cbo 0
dl 0
loc 56
ccs 19
cts 24
cp 0.7917
rs 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
A extend() 0 6 1
A hasDriver() 0 4 1
A __call() 0 10 2
A __toString() 0 8 2
A offsetExists() 0 4 1
A offsetGet() 0 4 1
A offsetSet() 0 4 1
A offsetUnset() 0 4 1
1
<?php namespace Rde;
2
3
class Prototype implements \ArrayAccess
4
{
5
    private $drivers = array();
6
7 3
    final public function extend($name, $callable)
8
    {
9 3
        $this->drivers[$name] = $callable;
10
11 3
        return $this;
12
    }
13
14 4
    final public function hasDriver($name)
15
    {
16 4
        return isset($this->drivers[$name]);
17
    }
18
19 4
    final public function __call($name, $args)
20
    {
21 4
        if ($this->hasDriver($name)) {
22 3
            array_unshift($args, $this);
23
24 3
            return \Rde\call($this->drivers[$name], $args);
25
        }
26
27 1
        throw new \BadMethodCallException("沒有安裝[{$name}]處理驅動");
28
    }
29
30 1
    public function __toString()
31
    {
32 1
        if ($this->hasDriver('__toString')) {
33 1
            return $this->__call('__toString', array());
34
        }
35
36 1
        return '['.get_called_class().']';
37
    }
38
39 2
    final public function offsetExists($key)
40
    {
41 2
        return isset($this->drivers[$key]);
42
    }
43
44
    final public function offsetGet($key)
45
    {
46
        return $this->drivers[$key];
47
    }
48
49 2
    final public function offsetSet($key, $val)
50
    {
51 2
        $this->extend($key, $val);
52 2
    }
53
54
    final public function offsetUnset($key)
55
    {
56
        unset($this->drivers[$key]);
57
    }
58
}
59