Completed
Push — master ( d085b4...8770d9 )
by Dennis
06:04 queued 03:00
created

AresRecords::count()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php
2
3
namespace Defr\Ares;
4
5
use ArrayIterator;
6
7
/**
8
 * Class AresRecords.
9
 *
10
 * @author Dennis Fridrich <[email protected]>
11
 */
12
final class AresRecords implements \ArrayAccess, \IteratorAggregate, \Countable
13
{
14
    /**
15
     * @var AresRecord[]
16
     */
17
    private $array = [];
18
19
    /**
20
     * @param mixed $offset
21
     *
22
     * @return bool
23
     */
24
    public function offsetExists($offset)
25
    {
26
        if (isset($this->array[$offset])) {
27
            return true;
28
        } else {
29
            return false;
30
        }
31
    }
32
33
    /**
34
     * @param mixed $offset
35
     *
36
     * @return bool|AresRecord
37
     */
38
    public function offsetGet($offset)
39
    {
40
        if ($this->offsetExists($offset)) {
41
            return $this->array[$offset];
42
        } else {
43
            return false;
44
        }
45
    }
46
47
    /**
48
     * @param mixed $offset
49
     * @param AresRecord $value
50
     */
51
    public function offsetSet($offset, $value)
52
    {
53
        if ($offset) {
54
            $this->array[$offset] = $value;
55
        } else {
56
            $this->array[] = $value;
57
        }
58
    }
59
60
    /**
61
     * @param mixed $offset
62
     */
63
    public function offsetUnset($offset)
64
    {
65
        unset($this->array[$offset]);
66
    }
67
68
    /**
69
     * @return ArrayIterator
70
     */
71
    public function getIterator()
72
    {
73
        return new ArrayIterator($this->array);
74
    }
75
76
    /**
77
     * {@inheritdoc}
78
     */
79
    public function count()
80
    {
81
        return count($this->array);
82
    }
83
}
84