Completed
Push — master ( 0decdc...293236 )
by Aivis
22s queued 11s
created

DataCollector   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 0
dl 0
loc 58
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setLimit() 0 4 1
A set() 0 4 1
A setInArray() 0 9 3
A getByKey() 0 7 2
1
<?php namespace Understand\UnderstandLaravel5;
2
3
class DataCollector
4
{
5
6
    /**
7
     * Current token
8
     *
9
     * @var type
10
     */
11
    protected $data = [];
12
13
    /**
14
     * @var int
15
     */
16
    protected $limit = 50;
17
18
    /**
19
     * @param $limit
20
     */
21
    public function setLimit($limit)
22
    {
23
        $this->limit = $limit;
24
    }
25
26
    /**
27
     * @param $key
28
     * @param $value
29
     */
30
    public function set($key, $value)
31
    {
32
        $this->data[$key] = $value;
33
    }
34
35
    /**
36
     * @param $key
37
     * @param $value
38
     */
39
    public function setInArray($key, $value)
40
    {
41
        if (isset($this->data[$key]) && count($this->data[$key]) > ($this->limit - 1))
42
        {
43
            array_shift($this->data[$key]);
44
        }
45
46
        $this->data[$key][] = $value;
47
    }
48
49
    /**
50
     * @param $key
51
     * @return mixed
52
     */
53
    public function getByKey($key)
54
    {
55
        if (isset($this->data[$key]))
56
        {
57
            return $this->data[$key];
58
        }
59
    }
60
}
61