Log::getPath()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 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