DataCollector::set()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 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
     * @return void
28
     */
29
    public function reset()
30
    {
31
        $this->data = [];
0 ignored issues
show
Documentation Bug introduced by
It seems like array() of type array is incompatible with the declared type object<Understand\UnderstandLaravel5\type> of property $data.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
32
    }
33
34
    /**
35
     * @param $key
36
     * @param $value
37
     */
38
    public function set($key, $value)
39
    {
40
        $this->data[$key] = $value;
41
    }
42
43
    /**
44
     * @param $key
45
     * @param $value
46
     */
47
    public function setInArray($key, $value)
48
    {
49
        if (isset($this->data[$key]) && count($this->data[$key]) > ($this->limit - 1))
50
        {
51
            array_shift($this->data[$key]);
52
        }
53
54
        $this->data[$key][] = $value;
55
    }
56
57
    /**
58
     * @param $key
59
     * @return mixed
60
     */
61
    public function getByKey($key)
62
    {
63
        if (isset($this->data[$key]))
64
        {
65
            return $this->data[$key];
66
        }
67
    }
68
}
69