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

Goal::setSiteIds()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 5

Duplication

Lines 11
Ratio 100 %

Code Coverage

Tests 4
CRAP Score 2.032

Importance

Changes 0
Metric Value
dl 11
loc 11
ccs 4
cts 5
cp 0.8
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 1
crap 2.032
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 12
    public function __construct(array $array = [])
19
    {
20 12
        parent::__construct($array);
21 12
    }
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 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...
33
    {
34 6
        if (!is_string($id)) {
35 2
            throw new LiftSdkException('Argument must be an instance of string.');
36 2
        }
37 6
        $this['id'] = $id;
38
39 6
        return $this;
40
    }
41
42
    /**
43
     * Gets the 'id' parameter.
44
     *
45
     * @return string The Identifier of the Goal
46
     */
47 9
    public function getId()
48
    {
49 9
        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 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...
62
    {
63 6
        if (!is_string($name)) {
64
            throw new LiftSdkException('Argument must be an instance of string.');
65
        }
66 6
        $this['name'] = $name;
67
68 6
        return $this;
69
    }
70
71
    /**
72
     * Gets the 'name' parameter.
73
     *
74
     * @return string
75
     *                The Name of the Goal
76
     */
77 9
    public function getName()
78
    {
79 9
        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 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...
92
    {
93 6
        if (!is_string($description)) {
94
            throw new LiftSdkException('Argument must be an instance of string.');
95
        }
96 6
        $this['description'] = $description;
97
98 6
        return $this;
99
    }
100
101
    /**
102
     * Gets the 'description' parameter.
103
     *
104
     * @return string The Description of the Goal
105
     */
106 9
    public function getDescription()
107
    {
108 9
        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 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...
121
    {
122 6
        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 6
        $this['rule_ids'] = array_values($ruleIds);
128
129 6
        return $this;
130
    }
131
132
    /**
133
     * Gets the 'rule_ids' parameter.
134
     *
135
     * @return array The Rule Identifiers
136
     */
137 9
    public function getRuleIds()
138
    {
139 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...
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 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...
152
    {
153 6
        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 6
        $this['site_ids'] = array_values($siteIds);
159
160 6
        return $this;
161
    }
162
163
    /**
164
     * Gets the 'site_ids' parameter.
165
     *
166
     * @return array The Site Identifiers
167
     */
168 9
    public function getSiteIds()
169
    {
170 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...
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 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...
183
    {
184 6
        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 6
        $this['event_names'] = array_values($eventNames);
190
191 6
        return $this;
192
    }
193
194
    /**
195
     * Gets the 'rule_ids' parameter.
196
     *
197
     * @return array The Rule Identifiers
198
     */
199 9
    public function getEventNames()
200
    {
201 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...
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 9
    public function getGlobal()
224
    {
225 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...
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 6
    public function getValue()
253
    {
254 6
        return $this->getEntityValue('value', '');
255
    }
256
257
    /**
258
     * Returns the json representation of the current object.
259
     *
260
     * @return string
261
     */
262 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...
263
    {
264 6
        $encoders = array(new JsonEncoder());
265 6
        $normalizers = array(new CustomNormalizer());
266 6
        $serializer = new Serializer($normalizers, $encoders);
267
268 6
        return $serializer->serialize($this, 'json');
269
    }
270
}
271