Completed
Push — master ( 734525...97c065 )
by Owen
02:29
created

KeyedCollection::getByKey()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 6
rs 9.4285
cc 3
eloc 3
nc 3
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 hasKey($key)
17
    {
18
        return array_key_exists($key, $this->data);
19
    }
20
21
22
    /**
23
     * {@inheritdoc}
24
     *
25
     */
26
    public function getByKey($key)
27
    {
28
        if ($this->hasKey($key)) {
29
            return is_object($this->data[$key]) ? clone $this->data[$key] : $this->data[$key];
30
        }
31
    }
32
}
33