Completed
Push — master ( b699ea...a3fc91 )
by Vladimir
02:30
created

PulseBoard::getSubscribers()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 6
rs 9.4286
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
3
/**
4
 * This file contains the PulseBoard class
5
 *
6
 * @copyright 2015 Vladimir Jimenez
7
 * @license   https://github.com/allejo/PhpPulse/blob/master/LICENSE.md MIT
8
 */
9
10
namespace allejo\DaPulse;
11
12
use allejo\DaPulse\Exceptions\ArgumentMismatchException;
13
use allejo\DaPulse\Exceptions\InvalidArraySizeException;
14
use allejo\DaPulse\Objects\ApiObject;
15
use allejo\DaPulse\Utilities\ArrayUtilities;
16
17
/**
18
 * This class contains all of the respective functionality for working a board on DaPulse
19
 *
20
 * @api
21
 * @package allejo\DaPulse
22
 * @since   0.1.0
23
 */
24
class PulseBoard extends ApiObject
0 ignored issues
show
Coding Style introduced by
The property $created_at is not named in camelCase.

This check marks property names that have not been written in camelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection string becomes databaseConnectionString.

Loading history...
Coding Style introduced by
The property $updated_at is not named in camelCase.

This check marks property names that have not been written in camelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection string becomes databaseConnectionString.

Loading history...
25
{
26
    /**
27
     * The suffix that is appended to the URL to access functionality for certain objects
28
     *
29
     * @internal
30
     */
31
    const API_PREFIX = "boards";
32
33
    // ================================================================================================================
34
    //   Instance Variables
35
    // ================================================================================================================
36
37
    /**
38
     * The resource's URL.
39
     *
40
     * @var string
41
     */
42
    protected $url;
43
44
    /**
45
     * The board's unique identifier.
46
     *
47
     * @var int
48
     */
49
    protected $id;
50
51
    /**
52
     * The board's name.
53
     *
54
     * @var string
55
     */
56
    protected $name;
57
58
    /**
59
     * The board's description.
60
     *
61
     * @var string
62
     */
63
    protected $description;
64
65
    /**
66
     * The board's visible columns.
67
     *
68
     * @var array
69
     */
70
    protected $columns;
71
72
    /**
73
     * The board's visible groups.
74
     *
75
     * @var array
76
     */
77
    protected $groups;
78
79
    /**
80
     * Creation time.
81
     *
82
     * @var \DateTime
83
     */
84
    protected $created_at;
85
86
    /**
87
     * Last update time.
88
     *
89
     * @var \DateTime
90
     */
91
    protected $updated_at;
92
93
    /**
94
     * Whether or not groups have been fetched. Group data comes from both a unique API call and from the initial call
95
     * of getting the board data, so this data is merged; this boolean is to avoid fetching this data twice.
96
     *
97
     * @var bool
98
     */
99
    private $groupsFetched = false;
100
101
    // ================================================================================================================
102
    //   Getter functions
103
    // ================================================================================================================
104
105
    /**
106
     * The resource's URL.
107
     *
108
     * @api
109
     * @since  0.1.0
110
     * @return string
111
     */
112
    public function getUrl()
113
    {
114
        return $this->url;
115
    }
116
117
    /**
118
     * The board's unique identifier.
119
     *
120
     * @api
121
     * @since  0.1.0
122
     * @return int
123
     */
124
    public function getId()
125
    {
126
        return $this->id;
127
    }
128
129
    /**
130
     * The board's name.
131
     *
132
     * @api
133
     * @since  0.1.0
134
     * @return string
135
     */
136
    public function getName()
137
    {
138
        return $this->name;
139
    }
140
141
    /**
142
     * The board's description.
143
     *
144
     * @api
145
     * @since  0.1.0
146
     * @return string
147
     */
148
    public function getDescription()
149
    {
150
        return $this->description;
151
    }
152
153
    /**
154
     * The board's visible columns.
155
     *
156
     * @api
157
     * @since  0.1.0
158
     * @return PulseColumn[]
159
     */
160
    public function getColumns()
161
    {
162
        self::lazyInject($this->columns, array(
163
            "board_id" => $this->getId()
164
        ));
165
        self::lazyArray($this->columns, "PulseColumn");
166
167
        return $this->columns;
168
    }
169
170
    /**
171
     * Creation time.
172
     *
173
     * @api
174
     * @since  0.1.0
175
     * @return \DateTime
176
     */
177
    public function getCreatedAt()
178
    {
179
        self::lazyLoad($this->created_at, "DateTime");
180
181
        return $this->created_at;
182
    }
183
184
    /**
185
     * Last update time.
186
     *
187
     * @api
188
     * @since  0.1.0
189
     * @return \DateTime
190
     */
191
    public function getUpdatedAt()
192
    {
193
        self::lazyLoad($this->updated_at, "DateTime");
194
195
        return $this->updated_at;
196
    }
197
198
    // ================================================================================================================
199
    //   Subscriber functions
200
    // ================================================================================================================
201
202
    /**
203
     * Get the users who are subscribed to this board
204
     *
205
     * @param  array $params
206
     *
207
     * @return PulseUser[]
208
     */
209
    public function getSubscribers ($params = array())
210
    {
211
        $url = sprintf("%s/%d/subscribers.json", parent::apiEndpoint(), $this->getId());
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (apiEndpoint() instead of getSubscribers()). Are you sure this is correct? If so, you might want to change this to $this->apiEndpoint().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
212
213
        return parent::fetchJsonArrayToObjectArray($url, "PulseUser", $params);
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (fetchJsonArrayToObjectArray() instead of getSubscribers()). Are you sure this is correct? If so, you might want to change this to $this->fetchJsonArrayToObjectArray().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
214
    }
215
216
    /**
217
     * Subscriber a user to a board
218
     *
219
     * @param int|PulseUser $user_id  The user that will be subscribed to the board
220
     * @param bool|null     $as_admin Set to true if the user will be an admin of the board
221
     */
222 View Code Duplication
    public function addSubscriber ($user_id, $as_admin = NULL)
0 ignored issues
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...
Coding Style Naming introduced by
The parameter $user_id is not named in camelCase.

This check marks parameter names that have not been written in camelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection string becomes databaseConnectionString.

Loading history...
Coding Style Naming introduced by
The parameter $as_admin is not named in camelCase.

This check marks parameter names that have not been written in camelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection string becomes databaseConnectionString.

Loading history...
223
    {
224
        if ($user_id instanceof PulseUser)
225
        {
226
            $user_id = $user_id->getId();
227
        }
228
229
        $url = sprintf("%s/%d/subscribers.json", parent::apiEndpoint(), $this->getId());
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (apiEndpoint() instead of addSubscriber()). Are you sure this is correct? If so, you might want to change this to $this->apiEndpoint().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
230
        $params = array(
231
            "user_id" => $user_id
232
        );
233
234
        parent::setIfNotNullOrEmpty($params, "as_admin", $as_admin);
0 ignored issues
show
Documentation introduced by
$as_admin is of type boolean|null, 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...
Comprehensibility Bug introduced by
It seems like you call parent on a different method (setIfNotNullOrEmpty() instead of addSubscriber()). Are you sure this is correct? If so, you might want to change this to $this->setIfNotNullOrEmpty().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
235
        parent::sendPut($url, $params);
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (sendPut() instead of addSubscriber()). Are you sure this is correct? If so, you might want to change this to $this->sendPut().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
236
    }
237
238
    /**
239
     * Unsubscribe a user from this board
240
     *
241
     * @param int|PulseUser $user_id The user that will be unsubscribed from the board
242
     */
243 View Code Duplication
    public function removeSubscriber ($user_id)
0 ignored issues
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...
Coding Style Naming introduced by
The parameter $user_id is not named in camelCase.

This check marks parameter names that have not been written in camelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection string becomes databaseConnectionString.

Loading history...
244
    {
245
        if ($user_id instanceof PulseUser)
246
        {
247
            $user_id = $user_id->getId();
248
        }
249
250
        $url = sprintf("%s/%d/subscribers/%d.json", parent::apiEndpoint(), $this->getId(), $user_id);
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (apiEndpoint() instead of removeSubscriber()). Are you sure this is correct? If so, you might want to change this to $this->apiEndpoint().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
251
252
        parent::sendDelete($url);
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (sendDelete() instead of removeSubscriber()). Are you sure this is correct? If so, you might want to change this to $this->sendDelete().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
253
    }
254
255
    // ================================================================================================================
256
    //   Columns functions
257
    // ================================================================================================================
258
259
    /**
260
     * Create a new column for the current board.
261
     *
262
     * If you are creating a status column, use the constants available in the **PulseColumnColorValue** class to match the
263
     * colors. Keep in mind this array cannot have a key higher than 11 nor can it be an associative array. Here's an
264
     * example of how to match statuses with specific colors.
265
     *
266
     * ```php
267
     * $labels = array(
268
     *     PulseColumnColorValue::Orange  => "Working on it",
269
     *     PulseColumnColorValue::L_Green => "Done",
270
     *     PulseColumnColorValue::Red     => "Delayed"
271
     * );
272
     * ```
273
     *
274
     * @api
275
     *
276
     * @param string $title  The title of the column. This title will automatically be "slugified" and become the ID
277
     *                       of the column.
278
     * @param string $type   The type of value that this column will use. Either use the available constants in the
279
     *                       PulseColumn class or use the following strings: "date", "person", "status", "text".
280
     * @param array  $labels If the column type will be "status," then this array will be the values for each of the
281
     *                       colors.
282
     *
283
     * @see PulseColumn::Date   PulseColumn::Date
284
     * @see PulseColumn::Person PulseColumn::Person
285
     * @see PulseColumn::Status PulseColumn::Status
286
     * @see PulseColumn::Text   PulseColumn::Text
287
     * @see PulseColumnColorValue::Orange  PulseColumnColorValue::Orange
288
     * @see PulseColumnColorValue::L_Green PulseColumnColorValue::L_Green
289
     * @see PulseColumnColorValue::Red     PulseColumnColorValue::Red
290
     * @see PulseColumnColorValue::Blue    PulseColumnColorValue::Blue
291
     * @see PulseColumnColorValue::Purple  PulseColumnColorValue::Purple
292
     * @see PulseColumnColorValue::Grey    PulseColumnColorValue::Grey
293
     * @see PulseColumnColorValue::Green   PulseColumnColorValue::Green
294
     * @see PulseColumnColorValue::L_Blue  PulseColumnColorValue::L_Blue
295
     * @see PulseColumnColorValue::Gold    PulseColumnColorValue::Gold
296
     * @see PulseColumnColorValue::Yellow  PulseColumnColorValue::Yellow
297
     * @see PulseColumnColorValue::Black   PulseColumnColorValue::Black
298
     *
299
     * @since 0.1.0
300
     *
301
     * @throws ArgumentMismatchException Status definitions were defined yet the type of the column was not a status
302
     *                                   type column
303
     * @throws InvalidArraySizeException The array containing the value of statuses has a key larger than the
304
     *                                   supported 10 indices
305
     *
306
     * @return $this This instance will be updated to have updated information to reflect the new column that was
307
     *               created
308
     */
309
    public function createColumn ($title, $type, $labels = array())
310
    {
311
        if ($type !== PulseColumn::Status && !empty($labels))
312
        {
313
            throw new ArgumentMismatchException("No color definitions are required for a non-color column.");
314
        }
315
316
        if ($type === PulseColumn::Status && count($labels) > 0 && max(array_keys($labels)) > 10)
317
        {
318
            throw new InvalidArraySizeException("The range of status can only be from 0-10.");
319
        }
320
321
        $url        = sprintf("%s/%d/columns.json", parent::apiEndpoint(), $this->getId());
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (apiEndpoint() instead of createColumn()). Are you sure this is correct? If so, you might want to change this to $this->apiEndpoint().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
322
        $postParams = array(
323
            "title" => $title,
324
            "type"  => $type
325
        );
326
327
        self::setIfNotNullOrEmpty($postParams, "labels", $labels);
0 ignored issues
show
Documentation introduced by
$labels 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...
328
329
        $this->jsonResponse = self::sendPost($url, $postParams);
0 ignored issues
show
Documentation Bug introduced by
It seems like self::sendPost($url, $postParams) of type * is incompatible with the declared type array of property $jsonResponse.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
330
        $this->assignResults();
331
332
        return $this;
333
    }
334
335
    // ================================================================================================================
336
    //   Group functions
337
    // ================================================================================================================
338
339
    /**
340
     * Get all of the groups belonging to a board.
341
     *
342
     * A group is defined as the colorful headers that split up pulses into categories.
343
     *
344
     * @api
345
     *
346
     * @param bool $showArchived Set to true if you would like to get archived groups in a board as well
347
     *
348
     * @since 0.1.0
349
     *
350
     * @return PulseGroup[]
351
     */
352
    public function getGroups ($showArchived = false)
353
    {
354
        if (!$this->groupsFetched)
355
        {
356
            $fetchedGroups = $this->fetchGroups($showArchived);
357
358
            $this->groups = ArrayUtilities::array_merge_recursive_distinct($this->groups, $fetchedGroups);
359
            $this->groupsFetched = true;
360
        }
361
362
        self::lazyArray($this->groups, "PulseGroup");
363
364
        return $this->groups;
365
    }
366
367
    public function createGroup ($title)
368
    {
369
        $url        = sprintf("%s/%s/groups.json", parent::apiEndpoint(), $this->getId());
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (apiEndpoint() instead of createGroup()). Are you sure this is correct? If so, you might want to change this to $this->apiEndpoint().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
370
        $postParams = array("title" => $title);
371
372
        // The API doesn't return the board ID, so since we have access to it here: set it manually
373
        $groupResult             = self::sendPost($url, $postParams);
374
        $groupResult["board_id"] = $this->getId();
375
376
        return (new PulseGroup($groupResult));
377
    }
378
379
    private function fetchGroups ($showArchived)
380
    {
381
        $url = sprintf("%s/%s/groups.json", parent::apiEndpoint(), $this->getId());
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (apiEndpoint() instead of fetchGroups()). Are you sure this is correct? If so, you might want to change this to $this->apiEndpoint().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
382
383
        $this->groupsFetched = true;
384
385
        return self::sendGet($url, array("show_archived" => $showArchived));
386
    }
387
388
    // ================================================================================================================
389
    //   Pulse functions
390
    // ================================================================================================================
391
392
    /**
393
     * @return Pulse[]
394
     */
395
    public function getPulses ()
396
    {
397
        $url = sprintf("%s/%d/pulses.json", parent::apiEndpoint(), $this->getId());
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (apiEndpoint() instead of getPulses()). Are you sure this is correct? If so, you might want to change this to $this->apiEndpoint().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
398
        $data = self::sendGet($url);
399
        $pulses = array();
400
401
        foreach ($data as $entry)
402
        {
403
            $this->pulseInjection($entry);
404
405
            $pulses[] = new Pulse($entry["pulse"]);
406
        }
407
408
        return $pulses;
409
    }
410
411
    public function createPulse ($name, $owner, $group_id = null)
0 ignored issues
show
Coding Style Naming introduced by
The parameter $group_id is not named in camelCase.

This check marks parameter names that have not been written in camelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection string becomes databaseConnectionString.

Loading history...
412
    {
413
        $url = sprintf("%s/%d/pulses.json", parent::apiEndpoint(), $this->getId());
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (apiEndpoint() instead of createPulse()). Are you sure this is correct? If so, you might want to change this to $this->apiEndpoint().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
414
        $postParams = array(
415
            "user_id" => $owner,
416
            "pulse" => array(
417
                "name" => $name
418
            )
419
        );
420
421
        self::setIfNotNullOrEmpty($postParams, "group_id", $group_id);
422
423
        $result = self::sendPost($url, $postParams);
424
        $this->pulseInjection($result);
425
426
        return (new Pulse($result["pulse"]));
427
    }
428
429 View Code Duplication
    private function pulseInjection (&$result)
0 ignored issues
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...
430
    {
431
        // Inject some information so a Pulse object can survive on its own
432
        $result["pulse"]["group_id"] = $result["board_meta"]["group_id"];
433
        $result["pulse"]["column_structure"] = $this->getColumns();
434
        $result["pulse"]["raw_column_values"] = $result["column_values"];
435
    }
436
437
    // ================================================================================================================
438
    //   Board functions
439
    // ================================================================================================================
440
441 View Code Duplication
    public function archiveBoard ()
0 ignored issues
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...
442
    {
443
        $this->checkInvalid();
444
445
        $url = sprintf("%s/%s.json", parent::apiEndpoint(), $this->getId());
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (apiEndpoint() instead of archiveBoard()). Are you sure this is correct? If so, you might want to change this to $this->apiEndpoint().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
446
        self::sendDelete($url);
447
448
        $this->deletedObject = true;
449
    }
450
451
    public static function createBoard ($name, $user_id, $description = NULL)
0 ignored issues
show
Coding Style Naming introduced by
The parameter $user_id is not named in camelCase.

This check marks parameter names that have not been written in camelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection string becomes databaseConnectionString.

Loading history...
452
    {
453
        $url        = sprintf("%s.json", parent::apiEndpoint());
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (apiEndpoint() instead of createBoard()). Are you sure this is correct? If so, you might want to change this to $this->apiEndpoint().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
454
        $postParams = array(
455
            "user_id" => $user_id,
456
            "name"    => $name
457
        );
458
459
        self::setIfNotNullOrEmpty($postParams, "description", $description);
460
461
        $boardResult = self::sendPost($url, $postParams);
462
463
        return (new PulseBoard($boardResult));
464
    }
465
466
    public static function getBoards ($params = array())
467
    {
468
        $url = sprintf("%s.json", parent::apiEndpoint());
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (apiEndpoint() instead of getBoards()). Are you sure this is correct? If so, you might want to change this to $this->apiEndpoint().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
469
470
        return parent::fetchJsonArrayToObjectArray($url, "PulseBoard", $params);
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (fetchJsonArrayToObjectArray() instead of getBoards()). Are you sure this is correct? If so, you might want to change this to $this->fetchJsonArrayToObjectArray().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
471
    }
472
}