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

Included   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 49
Duplicated Lines 6.12 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 93.33%

Importance

Changes 4
Bugs 0 Features 1
Metric Value
wmc 5
c 4
b 0
f 1
lcom 1
cbo 3
dl 3
loc 49
ccs 14
cts 15
cp 0.9333
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getPath() 0 4 1
A validate() 3 6 2
A persist() 0 9 1
A resolve() 0 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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