Passed
Pull Request — master (#40)
by
unknown
02:04
created

HasDataTrait::offsetSet()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
crap 2
1
<?php
2
3
namespace GuzzleHttp\Command;
4
5
/**
6
 * Basic collection behavior for Command and Result objects.
7
 *
8
 * The methods in the class are primarily for implementing the ArrayAccess,
9
 * Countable, and IteratorAggregate interfaces.
10
 */
11
trait HasDataTrait
12
{
13
    /** @var array Data stored in the collection. */
14
    protected $data;
15
16
    public function __toString()
17
    {
18
        return print_r($this, true);
19
    }
20
21
    public function __debugInfo()
22
    {
23
        return $this->data;
24
    }
25
26
    public function offsetExists($offset)
27
    {
28
        return array_key_exists($offset, $this->data);
29
    }
30
31
    public function offsetGet($offset)
32
    {
33
        return isset($this->data[$offset]) ? $this->data[$offset] : null;
34
    }
35
36
    public function offsetSet($offset, $value)
37
    {
38
        $this->data[$offset] = $value;
39
    }
40
41
    public function offsetUnset($offset)
42
    {
43
        unset($this->data[$offset]);
44
    }
45
46
    public function count()
47
    {
48
        return count($this->data);
49
    }
50
51
    public function getIterator()
52
    {
53
        return new \ArrayIterator($this->data);
54
    }
55
56
    public function toArray()
57
    {
58
        return $this->data;
59
    }
60
}
61