Completed
Push — master ( 22c75c...8b01ec )
by LAHAXE
02:39
created

Included::persist()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 9
ccs 6
cts 6
cp 1
rs 9.6667
cc 1
eloc 5
nc 1
nop 0
crap 1
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: arnaud
5
 * Date: 01/11/15
6
 * Time: 20:43
7
 */
8
9
namespace Ndrx\Profiler\Collectors\Data;
10
11
use Ndrx\Profiler\Collectors\Collector;
12
use Ndrx\Profiler\Collectors\Contracts\FinalCollectorInterface;
13
14
class Included extends Collector implements FinalCollectorInterface
15
{
16
    /**
17
     * The path in the final json
18
     * @example
19
     *  path /aa/bb
20
     *  will be transformed to
21
     *  {
22
     *     aa : {
23
     *              bb: <VALUE OF RESOLVE>
24
     *       }
25
     *  }
26
     * @return string
27
     */
28 2
    public function getPath()
29
    {
30 2
        return 'files';
31
    }
32
33 2
    public function validate()
34
    {
35 2 View Code Duplication
        if (!is_array($this->data)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
36
            throw new \LogicException('Files must be an array ' . json_encode($this->data) . ' given');
37
        }
38 2
    }
39
40
    /**
41
     * Convert data into jsonpatch query and save it in the data source
42
     * @return mixed
43
     */
44 2
    public function persist()
45
    {
46 2
        $this->validate();
47
48 2
        $patches = $this->jsonPatch->generateArrayAdd($this->getPath(), $this->data, true);
49 2
        $this->dataSource->save($this->process, $patches);
50
51 2
        $this->data = [];
52 2
    }
53
54
    /**
55
     * Fetch data
56
     * @return void
57
     */
58 4
    public function resolve()
59
    {
60 4
        $this->data = get_included_files();
61 4
    }
62
}
63