GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( b21c26...dc2a23 )
by
unknown
21s queued 17s
created

ContactField   A

Complexity

Total Complexity 16

Size/Duplication

Total Lines 157
Duplicated Lines 8.92 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 16
lcom 1
cbo 2
dl 14
loc 157
rs 10
c 0
b 0
f 0

9 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 18 6
A validate() 0 8 2
A getAllTypes() 0 9 1
A toArray() 14 14 2
A getId() 0 4 1
A getName() 0 4 1
A getType() 0 4 1
A getValue() 0 4 1
A setValue() 0 6 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: andy
5
 * Date: 19.06.17
6
 * Time: 17:55
7
 */
8
9
namespace LPTracker\models;
10
11
use LPTracker\exceptions\LPTrackerSDKException;
12
13
class ContactField extends Model
14
{
15
16
    const TYPE_STRING = 'string';
17
18
    const TYPE_TEXT = 'text';
19
20
    const TYPE_DATE = 'date';
21
22
    const TYPE_NUMBER = 'number';
23
24
    /**
25
     * @var integer
26
     */
27
    protected $id;
28
29
    /**
30
     * @var integer
31
     */
32
    protected $contactId;
33
34
    /**
35
     * @var string
36
     */
37
    protected $name;
38
39
    /**
40
     * @var string
41
     */
42
    protected $type;
43
44
    /**
45
     * @var mixed
46
     */
47
    protected $value;
48
49
50
    /**
51
     * ContactField constructor.
52
     *
53
     * @param array $fieldData
54
     */
55
    public function __construct(array $fieldData = [])
56
    {
57
        if (isset($fieldData['id'])) {
58
            $this->id = $fieldData['id'];
59
        }
60
        if (isset($fieldData['contact_id'])) {
61
            $this->contactId = $fieldData['contact_id'];
62
        }
63
        if (isset($fieldData['name'])) {
64
            $this->name = $fieldData['name'];
65
        }
66
        if (isset($fieldData['type'])) {
67
            $this->type = $fieldData['type'];
68
        }
69
        if (isset($fieldData['value'])) {
70
            $this->value = $fieldData['value'];
71
        }
72
    }
73
74
75
    /**
76
     * @return bool
77
     * @throws LPTrackerSDKException
78
     */
79
    public function validate()
80
    {
81
        if (empty($this->id)) {
82
            throw new LPTrackerSDKException('Field id can not be null: '.$this->__toString());
83
        }
84
85
        return true;
86
    }
87
88
89
    /**
90
     * @return array
91
     */
92
    public static function getAllTypes()
93
    {
94
        return [
95
            self::TYPE_STRING,
96
            self::TYPE_TEXT,
97
            self::TYPE_DATE,
98
            self::TYPE_NUMBER
99
        ];
100
    }
101
102
103
    /**
104
     * @return array
105
     */
106 View Code Duplication
    public function toArray()
0 ignored issues
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...
107
    {
108
        $result = [
109
            'id'   => $this->id,
110
            'name' => $this->name,
111
            'type' => $this->type
112
        ];
113
114
        if ( ! empty($this->value)) {
115
            $result['value'] = $this->getValue();
116
        }
117
118
        return $result;
119
    }
120
121
122
    /**
123
     * @return int
124
     */
125
    public function getId()
126
    {
127
        return $this->id;
128
    }
129
130
131
    /**
132
     * @return string
133
     */
134
    public function getName()
135
    {
136
        return $this->name;
137
    }
138
139
140
    /**
141
     * @return string
142
     */
143
    public function getType()
144
    {
145
        return $this->type;
146
    }
147
148
149
    /**
150
     * @return mixed
151
     */
152
    public function getValue()
153
    {
154
        return $this->value;
155
    }
156
157
158
    /**
159
     * @param mixed $value
160
     *
161
     * @return $this
162
     */
163
    public function setValue($value)
164
    {
165
        $this->value = $value;
166
167
        return $this;
168
    }
169
}