Connection   A
last analyzed

Complexity

Total Complexity 12

Size/Duplication

Total Lines 81
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 50%

Importance

Changes 0
Metric Value
wmc 12
lcom 1
cbo 0
dl 0
loc 81
ccs 13
cts 26
cp 0.5
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A offsetSet() 0 8 2
A offsetExists() 0 4 1
A offsetUnset() 0 4 1
A offsetGet() 0 4 2
A toArray() 0 4 1
A getHash() 0 4 1
A __toString() 0 10 3
1
<?php
2
3
namespace TreeHouse\Feeder\Transport;
4
5
class Connection implements \ArrayAccess
6
{
7
    /**
8
     * @var array
9
     */
10
    protected $options;
11
12
    /**
13
     * @param array $options
14
     */
15 132
    public function __construct(array $options)
16
    {
17 132
        $this->options = $options;
18 132
    }
19
20
    /**
21
     * @inheritdoc
22
     */
23 2
    public function offsetSet($offset, $value)
24
    {
25 2
        if (is_null($offset)) {
26
            $this->options[] = $value;
27
        } else {
28 2
            $this->options[$offset] = $value;
29
        }
30 2
    }
31
32
    /**
33
     * @inheritdoc
34
     */
35 90
    public function offsetExists($offset)
36
    {
37 90
        return isset($this->options[$offset]);
38
    }
39
40
    /**
41
     * @inheritdoc
42
     */
43
    public function offsetUnset($offset)
44
    {
45
        unset($this->options[$offset]);
46
    }
47
48
    /**
49
     * @inheritdoc
50
     */
51 86
    public function offsetGet($offset)
52
    {
53 86
        return isset($this->options[$offset]) ? $this->options[$offset] : null;
54
    }
55
56
    /**
57
     * @return array
58
     */
59
    public function toArray()
60
    {
61
        return $this->options;
62
    }
63
64
    /**
65
     * @return string
66
     */
67 16
    public function getHash()
68
    {
69 16
        return md5(json_encode($this->options));
70
    }
71
72
    /**
73
     * @return string
74
     */
75
    public function __toString()
76
    {
77
        foreach (['name', 'url', 'file'] as $attempt) {
78
            if (array_key_exists($attempt, $this->options)) {
79
                return $this->options[$attempt];
80
            }
81
        }
82
83
        return json_encode($this);
84
    }
85
}
86