Completed
Pull Request — master (#4)
by Nick
04:08 queued 01:55
created

Goal::setId()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 9
Ratio 100 %

Importance

Changes 0
Metric Value
dl 9
loc 9
rs 9.6666
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 1
1
<?php
2
3
namespace Acquia\LiftClient\Entity;
4
5
use Acquia\LiftClient\Exception\LiftSdkException;
6
use Acquia\LiftClient\Utility\Utility;
7
use foo\bar\Exception;
8
use Symfony\Component\Serializer\Serializer;
9
use Symfony\Component\Serializer\Encoder\JsonEncoder;
10
use Symfony\Component\Serializer\Normalizer\CustomNormalizer;
11
12
class Goal extends \ArrayObject
13
{
14
    use EntityValueTrait;
15
16
    /**
17
     * @param array $array
18
     */
19
    public function __construct(array $array = [])
20
    {
21
        parent::__construct($array);
22
    }
23
24
    /**
25
     * Sets the 'id' parameter.
26
     *
27
     * @param string $id
28
     *                   The identifier of the Goal
29
     *
30
     * @return \Acquia\LiftClient\Entity\Goal
31
     *                                        The Goal Entity
32
     *
33
     * @throws \Acquia\LiftClient\Exception\LiftSdkException
34
     *                                                       Throws an exception if the argument given does not match the expected set of
35
     *                                                       values
36
     */
37 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...
38
    {
39
        if (!is_string($id)) {
40
            throw new LiftSdkException('Argument must be an instance of string.');
41
        }
42
        $this['id'] = $id;
43
44
        return $this;
45
    }
46
47
    /**
48
     * Gets the 'id' parameter.
49
     *
50
     * @return string
51
     *                The Identifier of the Goal
52
     */
53
    public function getId()
54
    {
55
        return $this->getEntityValue('id', '');
56
    }
57
58
    /**
59
     * Sets the 'name' parameter.
60
     *
61
     * @param string $name
62
     *                     The Name of the Goal
63
     *
64
     * @return \Acquia\LiftClient\Entity\Goal
65
     *                                        The Goal Entity
66
     *
67
     * @throws \Acquia\LiftClient\Exception\LiftSdkException
68
     *                                                       Throws an exception if the argument given does not match the expected set of
69
     *                                                       values
70
     */
71 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...
72
    {
73
        if (!is_string($name)) {
74
            throw new LiftSdkException('Argument must be an instance of string.');
75
        }
76
        $this['name'] = $name;
77
78
        return $this;
79
    }
80
81
    /**
82
     * Gets the 'name' parameter.
83
     *
84
     * @return string
85
     *                The Name of the Goal
86
     */
87
    public function getName()
88
    {
89
        return $this->getEntityValue('name', '');
90
    }
91
92
    /**
93
     * Sets the 'description' parameter.
94
     *
95
     * @param string $description
96
     *                            The Description of the Goal
97
     *
98
     * @return \Acquia\LiftClient\Entity\Goal
99
     *                                        The Goal Entity
100
     *
101
     * @throws \Acquia\LiftClient\Exception\LiftSdkException
102
     *                                                       Throws an exception if the argument given does not match the expected set of
103
     *                                                       values
104
     */
105 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...
106
    {
107
        if (!is_string($description)) {
108
            throw new LiftSdkException('Argument must be an instance of string.');
109
        }
110
        $this['description'] = $description;
111
112
        return $this;
113
    }
114
115
    /**
116
     * Gets the 'description' parameter.
117
     *
118
     * @return string
119
     *                The Description of the Goal
120
     */
121
    public function getDescription()
122
    {
123
        return $this->getEntityValue('description', '');
124
    }
125
126
    /**
127
     * Sets the 'rule_ids' parameter.
128
     *
129
     * @param array $ruleIds
130
     *                       An array of rule identifiers
131
     *
132
     * @return \Acquia\LiftClient\Entity\Goal
133
     *                                        The Goal Entity
134
     *
135
     * @throws \Acquia\LiftClient\Exception\LiftSdkException
136
     *                                                       Throws an exception if the argument given does not match the expected set of
137
     *                                                       values
138
     */
139 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...
140
    {
141
        if (Utility::arrayDepth($ruleIds) > 1) {
142
            throw new LiftSdkException('Rule Ids argument is more than 1 level deep.');
143
        }
144
145
        // Set only the array values to the rule_ids property.
146
        $this['rule_ids'] = array_values($ruleIds);
147
148
        return $this;
149
    }
150
151
    /**
152
     * Gets the 'rule_ids' parameter.
153
     *
154
     * @return array
155
     *               The Rule Identifiers
156
     */
157
    public function getRuleIds()
158
    {
159
        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...
160
    }
161
162
    /**
163
     * Sets the 'site_ids' parameter.
164
     *
165
     * @param array $siteIds
166
     *                       An array of site identifiers
167
     *
168
     * @return \Acquia\LiftClient\Entity\Goal
169
     *                                        The Goal Entity
170
     *
171
     * @throws \Acquia\LiftClient\Exception\LiftSdkException
172
     *                                                       Throws an exception if the argument given does not match the expected set of
173
     *                                                       values
174
     */
175 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...
176
    {
177
        if (Utility::arrayDepth($siteIds) > 1) {
178
            throw new LiftSdkException('site_ids argument is more than 1 level deep.');
179
        }
180
181
        // Set only the array values to the rule_ids property.
182
        $this['site_ids'] = array_values($siteIds);
183
184
        return $this;
185
    }
186
187
    /**
188
     * Gets the 'site_ids' parameter.
189
     *
190
     * @return array
191
     *               The Site Identifiers
192
     */
193
    public function getSiteIds()
194
    {
195
        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...
196
    }
197
198
    /**
199
     * Sets the 'event_names' parameter.
200
     *
201
     * @param array $eventNames
202
     *                          An array of event names
203
     *
204
     * @return \Acquia\LiftClient\Entity\Goal
205
     *                                        The Goal Entity
206
     *
207
     * @throws \Acquia\LiftClient\Exception\LiftSdkException
208
     *                                                       Throws an exception if the argument given does not match the expected set of
209
     *                                                       values
210
     */
211 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...
212
    {
213
        if (Utility::arrayDepth($eventNames) > 1) {
214
            throw new LiftSdkException('Event Names argument is more than 1 level deep.');
215
        }
216
217
        // Set only the array values to the event_names property.
218
        $this['event_names'] = array_values($eventNames);
219
220
        return $this;
221
    }
222
223
    /**
224
     * Gets the 'rule_ids' parameter.
225
     *
226
     * @return array
227
     *               The Rule Identifiers
228
     */
229
    public function getEventNames()
230
    {
231
        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...
232
    }
233
234
    /**
235
     * Sets the 'global' parameter.
236
     *
237
     * @param bool $global
238
     *
239
     * @return \Acquia\LiftClient\Entity\Slot
240
     */
241
    public function setGlobal($global)
242
    {
243
        $this['global'] = $global;
244
245
        return $this;
246
    }
247
248
    /**
249
     * Gets the 'global' parameter.
250
     *
251
     * @return bool
252
     */
253
    public function getGlobal()
254
    {
255
        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...
256
    }
257
258
    /**
259
     * Sets the 'value' parameter.
260
     *
261
     * @param float|int $value
262
     *                         The value of the Goal
263
     *
264
     * @return \Acquia\LiftClient\Entity\Goal
265
     *                                        The Goal Entity
266
     *
267
     * @throws \Acquia\LiftClient\Exception\LiftSdkException
268
     *                                                       Throws an exception if the argument given does not match the expected set of
269
     *                                                       values
270
     */
271
    public function setValue($value)
272
    {
273
        if (!is_float($value) && !is_int($value)) {
274
            throw new LiftSdkException('Argument must be an instance of float or int.');
275
        }
276
        $this['value'] = $value;
277
278
        return $this;
279
    }
280
281
    /**
282
     * Gets the 'value' parameter.
283
     *
284
     * @return float
285
     */
286
    public function getValue()
287
    {
288
        return $this->getEntityValue('value', '');
289
    }
290
291
    /**
292
     * Returns the json representation of the current object.
293
     *
294
     * @return string
295
     */
296 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...
297
    {
298
        $encoders = array(new JsonEncoder());
299
        $normalizers = array(new CustomNormalizer());
300
        $serializer = new Serializer($normalizers, $encoders);
301
302
        return $serializer->serialize($this, 'json');
303
    }
304
}
305