Completed
Push — master ( ff21ca...f317b4 )
by Konstantin
02:12
created

CustomField   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 51
Duplicated Lines 29.41 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 1
dl 15
loc 51
ccs 16
cts 16
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A addValue() 0 4 1
A get() 15 15 3

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
namespace linkprofit\AmoCRM\entities;
4
5
use linkprofit\AmoCRM\traits\FieldsTrait;
6
7
/**
8
 * Class CustomField
9
 * @package linkprofit\AmoCRM
10
 */
11
class CustomField implements EntityInterface
12
{
13
    public $id;
14
    public $name;
15
    public $code;
16
17
    use FieldsTrait;
18
19
    /**
20
     * @var array Value
21
     */
22
    protected $values = [];
23
24
    protected $fieldList = [
25
        'id', 'name', 'code'
26
    ];
27
28 4
    public function __construct($id, $name, $code)
29
    {
30 4
        $this->id = $id;
31 4
        $this->name = $name;
32 4
        $this->code = $code;
33 4
    }
34
35
    /**
36
     * @param Value $value
37
     */
38 3
    public function addValue(Value $value)
39
    {
40 3
        $this->values[] = $value;
41 3
    }
42
43
    /**
44
     * @return array
45
     */
46 4 View Code Duplication
    public function get()
1 ignored issue
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...
47
    {
48 4
        $fields = $this->getExistedValues($this->fieldList);
49
50 4
        $values = [];
51 4
        foreach ($this->values as $value) {
52 3
            $values[] = $value->get();
53
        }
54
55 4
        if (count($values)) {
56 3
            $fields['values'] = $values;
57
        }
58
59 4
        return $fields;
60
    }
61
}