Completed
Pull Request — master (#1)
by Roman
03:56
created

KeyedCollection::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace Mundanity\Collection;
4
5
6
/**
7
 * A keyed collection.
8
 *
9
 */
10
class KeyedCollection extends Collection implements KeyedCollectionInterface
11
{
12
    /**
13
     * {@inheritdoc}
14
     *
15
     */
16
    public function getAtIndex($index)
17
    {
18
        if (!is_numeric($index)) {
19
            return;
20
        }
21
22
        $values = array_values($this->data);
23
        return isset($values[$index]) ? $values[$index] : null;
24
    }
25
26
27
    /**
28
     * {@inheritdoc}
29
     *
30
     */
31
    public function hasKey($key)
32
    {
33
        return array_key_exists($key, $this->data);
34
    }
35
36
37
    /**
38
     * {@inheritdoc}
39
     *
40
     */
41
    public function getByKey($key)
42
    {
43
        if ($this->hasKey($key)) {
44
            return is_object($this->data[$key]) ? clone $this->data[$key] : $this->data[$key];
45
        }
46
    }
47
}
48