Completed
Push — wip-platform ( 03cba6...2999ab )
by
unknown
05:53 queued 02:49
created

Collector::handleDataKey()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
3
/*
4
 *
5
 * Copyright (C) 2015-2017 Libre Informatique
6
 *
7
 * This file is licenced under the GNU LGPL v3.
8
 * For the full copyright and license information, please view the LICENSE.md
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Blast\Bundle\CoreBundle\Profiler;
13
14
class Collector
15
{
16
    /**
17
     * @var mixed
18
     */
19
    private $data;
20
21
    /**
22
     * @var array
23
     */
24
    private $collectedKeys;
25
26
    public function __construct()
27
    {
28
        $this->data = [];
29
        $this->collectedKeys = [];
30
    }
31
32
    /**
33
     * @param string $name
34
     * @param mixed  $data
35
     * @param string $destination
36
     * @param string $type
37
     *
38
     * @return $this
39
     */
40 View Code Duplication
    public function collect($name, $data, $destination = DataCollection::DESTINATION_PROFILER, $type = null)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
41
    {
42
        $this->collectedKeys[] = $name;
43
44
        $dataCollection = new DataCollection($name, $data, $destination, $type);
45
        $this->data[$this->handleDataKey($name)] = $dataCollection;
46
47
        return $this;
48
    }
49
50
    /**
51
     * @param string $name
52
     * @param mixed  $data
53
     * @param string $destination
54
     * @param string $type
55
     *
56
     * @return $this
57
     */
58 View Code Duplication
    public function collectOnce($name, $data, $destination = DataCollection::DESTINATION_PROFILER, $type = null)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
59
    {
60
        if (!in_array($name, $this->collectedKeys)) {
61
            $this->collectedKeys[] = $name;
62
            $dataCollection = new DataCollection($name, $data, $destination, $type);
63
            $this->data[$this->handleDataKey($name)] = $dataCollection;
64
        }
65
66
        return $this;
67
    }
68
69
    /**
70
     * @return mixed
71
     */
72
    public function getData()
73
    {
74
        return $this->data;
75
    }
76
77
    private function handleDataKey($name)
78
    {
79
        $keyStrucure = '#%d %s';
80
81
        return sprintf($keyStrucure, count($this->data) + 1, $name);
82
    }
83
}
84