Completed
Pull Request — master (#4)
by Nick
05:39
created

Goal::getDescription()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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