Completed
Pull Request — master (#4)
by Nick
14:23
created

Goal::getRuleIds()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
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 The Name of the Goal
75
     */
76
    public function getName()
77
    {
78
        return $this->getEntityValue('name', '');
79
    }
80
81
    /**
82
     * Sets the 'description' parameter.
83
     *
84
     * @param string $description
85
     *
86
     * @throws \Acquia\LiftClient\Exception\LiftSdkException
87
     *
88
     * @return \Acquia\LiftClient\Entity\Goal
89
     */
90 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...
91
    {
92
        if (!is_string($description)) {
93
            throw new LiftSdkException('Argument must be an instance of string.');
94
        }
95
        $this['description'] = $description;
96
97
        return $this;
98
    }
99
100
    /**
101
     * Gets the 'description' parameter.
102
     *
103
     * @return string The Description of the Goal
104
     */
105
    public function getDescription()
106
    {
107
        return $this->getEntityValue('description', '');
108
    }
109
110
    /**
111
     * Sets the 'rule_ids' parameter.
112
     *
113
     * @param array $ruleIds
114
     *
115
     * @throws \Acquia\LiftClient\Exception\LiftSdkException
116
     *
117
     * @return \Acquia\LiftClient\Entity\Goal
118
     */
119 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...
120
    {
121
        if (Utility::arrayDepth($ruleIds) > 1) {
122
            throw new LiftSdkException('Rule Ids argument is more than 1 level deep.');
123
        }
124
125
        // Set only the array values to the rule_ids property.
126
        $this['rule_ids'] = array_values($ruleIds);
127
128
        return $this;
129
    }
130
131
    /**
132
     * Gets the 'rule_ids' parameter.
133
     *
134
     * @return array The Rule Identifiers
135
     */
136
    public function getRuleIds()
137
    {
138
        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...
139
    }
140
141
    /**
142
     * Sets the 'site_ids' parameter.
143
     *
144
     * @param array $siteIds
145
     *
146
     * @throws \Acquia\LiftClient\Exception\LiftSdkException
147
     *
148
     * @return \Acquia\LiftClient\Entity\Goal
149
     */
150 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...
151
    {
152
        if (Utility::arrayDepth($siteIds) > 1) {
153
            throw new LiftSdkException('site_ids argument is more than 1 level deep.');
154
        }
155
156
        // Set only the array values to the site_ids property.
157
        $this['site_ids'] = array_values($siteIds);
158
159
        return $this;
160
    }
161
162
    /**
163
     * Gets the 'site_ids' parameter.
164
     *
165
     * @return array The Site Identifiers
166
     */
167
    public function getSiteIds()
168
    {
169
        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...
170
    }
171
172
    /**
173
     * Sets the 'event_names' parameter.
174
     *
175
     * @param array $eventNames
176
     *
177
     * @throws \Acquia\LiftClient\Exception\LiftSdkException
178
     *
179
     * @return \Acquia\LiftClient\Entity\Goal
180
     */
181 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...
182
    {
183
        if (Utility::arrayDepth($eventNames) > 1) {
184
            throw new LiftSdkException('Event Names argument is more than 1 level deep.');
185
        }
186
187
        // Set only the array values to the event_names property.
188
        $this['event_names'] = array_values($eventNames);
189
190
        return $this;
191
    }
192
193
    /**
194
     * Gets the 'rule_ids' parameter.
195
     *
196
     * @return array The Rule Identifiers
197
     */
198
    public function getEventNames()
199
    {
200
        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...
201
    }
202
203
    /**
204
     * Sets the 'global' parameter.
205
     *
206
     * @param bool $global
207
     *
208
     * @return \Acquia\LiftClient\Entity\Slot
209
     */
210
    public function setGlobal($global)
211
    {
212
        $this['global'] = $global;
213
214
        return $this;
215
    }
216
217
    /**
218
     * Gets the 'global' parameter.
219
     *
220
     * @return bool
221
     */
222
    public function getGlobal()
223
    {
224
        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...
225
    }
226
227
    /**
228
     * Sets the 'value' parameter.
229
     *
230
     * @param float|int $value
231
     *
232
     * @throws \Acquia\LiftClient\Exception\LiftSdkException
233
     *
234
     * @return \Acquia\LiftClient\Entity\Goal
235
     */
236
    public function setValue($value)
237
    {
238
        if (!is_float($value) && !is_int($value)) {
239
            throw new LiftSdkException('Argument must be an instance of float or int.');
240
        }
241
        $this['value'] = $value;
242
243
        return $this;
244
    }
245
246
    /**
247
     * Gets the 'value' parameter.
248
     *
249
     * @return float
250
     */
251
    public function getValue()
252
    {
253
        return $this->getEntityValue('value', '');
254
    }
255
256
    /**
257
     * Returns the json representation of the current object.
258
     *
259
     * @return string
260
     */
261 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...
262
    {
263
        $encoders = array(new JsonEncoder());
264
        $normalizers = array(new CustomNormalizer());
265
        $serializer = new Serializer($normalizers, $encoders);
266
267
        return $serializer->serialize($this, 'json');
268
    }
269
}
270