Completed
Pull Request — master (#4)
by Nick
02:27
created

Goal   A

Complexity

Total Complexity 26

Size/Duplication

Total Lines 260
Duplicated Lines 26.15 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 0
Metric Value
wmc 26
lcom 1
cbo 6
dl 68
loc 260
rs 10
c 0
b 0
f 0

18 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A setId() 9 9 2
A getId() 0 4 1
A setName() 9 9 2
A getName() 0 4 1
A setDescription() 9 9 2
A getDescription() 0 4 1
A setRuleIds() 11 11 2
A getRuleIds() 0 4 1
A setSiteIds() 11 11 2
A getSiteIds() 0 4 1
A setEventNames() 11 11 2
A getEventNames() 0 4 1
A setGlobal() 0 6 1
A getGlobal() 0 4 1
A setValue() 0 9 3
A getValue() 0 4 1
A json() 8 8 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
namespace Acquia\LiftClient\Entity;
4
5
use Acquia\LiftClient\Exception\LiftSdkException;
6
use Acquia\LiftClient\Utility\Utility;
7
use Symfony\Component\Serializer\Serializer;
8
use Symfony\Component\Serializer\Encoder\JsonEncoder;
9
use Symfony\Component\Serializer\Normalizer\CustomNormalizer;
10
11
class Goal extends \ArrayObject
12
{
13
    use EntityValueTrait;
14
15
    /**
16
     * @param array $array
17
     */
18
    public function __construct(array $array = [])
19
    {
20
        parent::__construct($array);
21
    }
22
23
    /**
24
     * Sets the 'id' parameter.
25
     *
26
     * @param string $id
27
     *
28
     * @throws \Acquia\LiftClient\Exception\LiftSdkException
29
     *
30
     * @return \Acquia\LiftClient\Entity\Goal
31
     */
32 View Code Duplication
    public function setId($id)
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...
33
    {
34
        if (!is_string($id)) {
35
            throw new LiftSdkException('Argument must be an instance of string.');
36
        }
37
        $this['id'] = $id;
38
39
        return $this;
40
    }
41
42
    /**
43
     * Gets the 'id' parameter.
44
     *
45
     * @return string The Identifier of the Goal
46
     */
47
    public function getId()
48
    {
49
        return $this->getEntityValue('id', '');
50
    }
51
52
    /**
53
     * Sets the 'name' parameter.
54
     *
55
     * @param string $name
56
     *
57
     * @throws \Acquia\LiftClient\Exception\LiftSdkException
58
     *
59
     * @return \Acquia\LiftClient\Entity\Goal
60
     */
61 View Code Duplication
    public function setName($name)
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...
62
    {
63
        if (!is_string($name)) {
64
            throw new LiftSdkException('Argument must be an instance of string.');
65
        }
66
        $this['name'] = $name;
67
68
        return $this;
69
    }
70
71
    /**
72
     * Gets the 'name' parameter.
73
     *
74
     * @return string
75
     *                The Name of the Goal
76
     */
77
    public function getName()
78
    {
79
        return $this->getEntityValue('name', '');
80
    }
81
82
    /**
83
     * Sets the 'description' parameter.
84
     *
85
     * @param string $description
86
     *
87
     * @throws \Acquia\LiftClient\Exception\LiftSdkException
88
     *
89
     * @return \Acquia\LiftClient\Entity\Goal
90
     */
91 View Code Duplication
    public function setDescription($description)
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...
92
    {
93
        if (!is_string($description)) {
94
            throw new LiftSdkException('Argument must be an instance of string.');
95
        }
96
        $this['description'] = $description;
97
98
        return $this;
99
    }
100
101
    /**
102
     * Gets the 'description' parameter.
103
     *
104
     * @return string The Description of the Goal
105
     */
106
    public function getDescription()
107
    {
108
        return $this->getEntityValue('description', '');
109
    }
110
111
    /**
112
     * Sets the 'rule_ids' parameter.
113
     *
114
     * @param array $ruleIds
115
     *
116
     * @throws \Acquia\LiftClient\Exception\LiftSdkException
117
     *
118
     * @return \Acquia\LiftClient\Entity\Goal
119
     */
120 View Code Duplication
    public function setRuleIds(array $ruleIds)
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...
121
    {
122
        if (Utility::arrayDepth($ruleIds) > 1) {
123
            throw new LiftSdkException('Rule Ids argument is more than 1 level deep.');
124
        }
125
126
        // Set only the array values to the rule_ids property.
127
        $this['rule_ids'] = array_values($ruleIds);
128
129
        return $this;
130
    }
131
132
    /**
133
     * Gets the 'rule_ids' parameter.
134
     *
135
     * @return array The Rule Identifiers
136
     */
137
    public function getRuleIds()
138
    {
139
        return $this->getEntityValue('rule_ids', array());
0 ignored issues
show
Documentation introduced by
array() is of type array, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
140
    }
141
142
    /**
143
     * Sets the 'site_ids' parameter.
144
     *
145
     * @param array $siteIds
146
     *
147
     * @throws \Acquia\LiftClient\Exception\LiftSdkException
148
     *
149
     * @return \Acquia\LiftClient\Entity\Goal
150
     */
151 View Code Duplication
    public function setSiteIds(array $siteIds)
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...
152
    {
153
        if (Utility::arrayDepth($siteIds) > 1) {
154
            throw new LiftSdkException('site_ids argument is more than 1 level deep.');
155
        }
156
157
        // Set only the array values to the rule_ids property.
158
        $this['site_ids'] = array_values($siteIds);
159
160
        return $this;
161
    }
162
163
    /**
164
     * Gets the 'site_ids' parameter.
165
     *
166
     * @return array The Site Identifiers
167
     */
168
    public function getSiteIds()
169
    {
170
        return $this->getEntityValue('site_ids', array());
0 ignored issues
show
Documentation introduced by
array() is of type array, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
171
    }
172
173
    /**
174
     * Sets the 'event_names' parameter.
175
     *
176
     * @param array $eventNames
177
     *
178
     * @throws \Acquia\LiftClient\Exception\LiftSdkException
179
     *
180
     * @return \Acquia\LiftClient\Entity\Goal
181
     */
182 View Code Duplication
    public function setEventNames(array $eventNames)
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...
183
    {
184
        if (Utility::arrayDepth($eventNames) > 1) {
185
            throw new LiftSdkException('Event Names argument is more than 1 level deep.');
186
        }
187
188
        // Set only the array values to the event_names property.
189
        $this['event_names'] = array_values($eventNames);
190
191
        return $this;
192
    }
193
194
    /**
195
     * Gets the 'rule_ids' parameter.
196
     *
197
     * @return array The Rule Identifiers
198
     */
199
    public function getEventNames()
200
    {
201
        return $this->getEntityValue('event_names', array());
0 ignored issues
show
Documentation introduced by
array() is of type array, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
202
    }
203
204
    /**
205
     * Sets the 'global' parameter.
206
     *
207
     * @param bool $global
208
     *
209
     * @return \Acquia\LiftClient\Entity\Slot
210
     */
211
    public function setGlobal($global)
212
    {
213
        $this['global'] = $global;
214
215
        return $this;
216
    }
217
218
    /**
219
     * Gets the 'global' parameter.
220
     *
221
     * @return bool
222
     */
223
    public function getGlobal()
224
    {
225
        return $this->getEntityValue('global', false);
0 ignored issues
show
Documentation introduced by
false is of type boolean, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
226
    }
227
228
    /**
229
     * Sets the 'value' parameter.
230
     *
231
     * @param float|int $value
232
     *
233
     * @throws \Acquia\LiftClient\Exception\LiftSdkException
234
     *
235
     * @return \Acquia\LiftClient\Entity\Goal
236
     */
237
    public function setValue($value)
238
    {
239
        if (!is_float($value) && !is_int($value)) {
240
            throw new LiftSdkException('Argument must be an instance of float or int.');
241
        }
242
        $this['value'] = $value;
243
244
        return $this;
245
    }
246
247
    /**
248
     * Gets the 'value' parameter.
249
     *
250
     * @return float
251
     */
252
    public function getValue()
253
    {
254
        return $this->getEntityValue('value', '');
255
    }
256
257
    /**
258
     * Returns the json representation of the current object.
259
     *
260
     * @return string
261
     */
262 View Code Duplication
    public function json()
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...
263
    {
264
        $encoders = array(new JsonEncoder());
265
        $normalizers = array(new CustomNormalizer());
266
        $serializer = new Serializer($normalizers, $encoders);
267
268
        return $serializer->serialize($this, 'json');
269
    }
270
}
271