Log   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Test Coverage

Coverage 100%

Importance

Changes 6
Bugs 0 Features 1
Metric Value
wmc 3
c 6
b 0
f 1
lcom 1
cbo 6
dl 0
loc 43
ccs 12
cts 12
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A registerListeners() 0 7 1
A getPath() 0 4 1
A stream() 0 6 1
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: arnaud
5
 * Date: 01/11/15
6
 * Time: 23:17
7
 */
8
9
namespace Ndrx\Profiler\Collectors\Data;
10
11
use Ndrx\Profiler\Collectors\StreamCollector;
12
use \Ndrx\Profiler\Events\Log as LogEvent;
13
use Ndrx\Profiler\JsonPatch;
14
use Ndrx\Profiler\Renderer\BarRenderableInterface;
15
16
class Log extends StreamCollector implements BarRenderableInterface
17
{
18
    /**
19
     * @author LAHAXE Arnaud
20
     *
21
     *
22
     */
23
    protected function registerListeners()
24
    {
25 96
        $this->process->getDispatcher()->addListener(LogEvent::EVENT_NAME, function (LogEvent $event) {
26 4
            $this->data = $event->toArray();
27 4
            $this->stream();
28 96
        });
29 96
    }
30
31
    /**
32
     * The path in the final json
33
     * @example
34
     *  path /aa/bb
35
     *  will be transformed to
36
     *  {
37
     *     aa : {
38
     *              bb: <VALUE OF RESOLVE>
39
     *       }
40
     *  }
41
     * @return mixed
42
     */
43 96
    public function getPath()
44
    {
45 96
        return 'logs';
46
    }
47
48
    /**
49
     * Write data in the datasource and clean current buffer
50
     * @return mixed
51
     */
52 4
    public function stream()
53
    {
54 4
        $patch = $this->jsonPatch->generate($this->getPath(), JsonPatch::ACTION_ADD, $this->data, true);
55 4
        $this->dataSource->save($this->process, [$patch]);
56 4
        $this->data = [];
57 4
    }
58
}
59