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

KeyedCollection   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 4
c 2
b 0
f 1
lcom 1
cbo 1
dl 0
loc 23
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A hasKey() 0 4 1
A getByKey() 0 6 3
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