Completed
Push — master ( eb0343...a75c5d )
by Vladimir
02:34
created

Pulse   B

Complexity

Total Complexity 41

Size/Duplication

Total Lines 641
Duplicated Lines 4.68 %

Coupling/Cohesion

Components 1
Dependencies 7

Importance

Changes 16
Bugs 3 Features 4
Metric Value
wmc 41
c 16
b 3
f 4
lcom 1
cbo 7
dl 30
loc 641
rs 8.1732

25 Methods

Rating   Name   Duplication   Size   Complexity  
A initializeValues() 0 6 1
A getUrl() 0 4 1
A getId() 0 4 1
A getName() 0 4 1
A getUpdatesCount() 0 4 1
A getBoardId() 0 4 1
A getCreatedAt() 0 4 1
A getUpdatedAt() 0 4 1
B getGroupId() 0 19 5
A deletePulse() 10 10 1
A duplicatePulse() 0 18 2
A pulseInjection() 9 9 1
A getColumnValue() 0 18 3
A getStatusColumn() 0 4 1
A getDateColumn() 0 4 1
A getPersonColumn() 0 4 1
A getTextColumn() 0 4 1
B getColumn() 0 49 6
A addSubscriber() 0 15 2
A getSubscribers() 0 6 1
A addNote() 0 22 3
A getNotes() 0 6 1
A getUpdates() 0 6 1
A getPulses() 0 6 1
A removeSubscriber() 11 11 2

How to fix   Duplicated Code    Complexity   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

Complex Class

 Tip:   Before tackling complexity, make sure that you eliminate any duplication first. This often can reduce the size of classes significantly.

Complex classes like Pulse often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use Pulse, and based on these observations, apply Extract Interface, too.

1
<?php
2
3
/**
4
 * This file contains the Pulse 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\HttpException;
13
use allejo\DaPulse\Exceptions\InvalidColumnException;
14
use allejo\DaPulse\Exceptions\InvalidObjectException;
15
use allejo\DaPulse\Objects\ApiObject;
16
use allejo\DaPulse\Objects\PulseColumnStatusValue;
17
use allejo\DaPulse\Objects\PulseColumnDateValue;
18
use allejo\DaPulse\Objects\PulseColumnPersonValue;
19
use allejo\DaPulse\Objects\PulseColumnTextValue;
20
use allejo\DaPulse\Objects\PulseColumnValue;
21
use allejo\DaPulse\Utilities\ArrayUtilities;
22
23
/**
24
 * A class representing a single pulse in a board
25
 *
26
 * @api
27
 * @package allejo\DaPulse
28
 * @since 0.1.0
29
 */
30
class Pulse extends ApiObject
0 ignored issues
show
Coding Style introduced by
The property $updates_count 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 $board_id 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 $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...
Coding Style introduced by
The property $group_id 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 $column_structure 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 $raw_column_values 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 $column_values 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...
31
{
32
    /**
33
     * @ignore
34
     */
35
    const API_PREFIX = "pulses";
36
37
    // ================================================================================================================
38
    //   Instance Variables
39
    // ================================================================================================================
40
41
    /**
42
     * The resource's URL.
43
     *
44
     * @var string
45
     */
46
    protected $url;
47
48
    /**
49
     * The pulse's unique identifier.
50
     *
51
     * @var int
52
     */
53
    protected $id;
54
55
    /**
56
     * The pulse's name.
57
     *
58
     * @var string
59
     */
60
    protected $name;
61
62
    /**
63
     * The board's subscribers.
64
     *
65
     * @var PulseUser[]
66
     */
67
    protected $subscribers;
68
69
    /**
70
     * The amount of updates a pulse has.
71
     *
72
     * @var int
73
     */
74
    protected $updates_count;
75
76
    /**
77
     * The ID of the parent board.
78
     *
79
     * @var int
80
     */
81
    protected $board_id;
82
83
    /**
84
     * Creation time.
85
     *
86
     * @var \DateTime
87
     */
88
    protected $created_at;
89
90
    /**
91
     * Last update time.
92
     *
93
     * @var \DateTime
94
     */
95
    protected $updated_at;
96
97
    /**
98
     * The ID of the group this pulse belongs to
99
     *
100
     * @var string
101
     */
102
    protected $group_id;
103
104
    /**
105
     * @var PulseColumn[]
106
     */
107
    protected $column_structure;
108
109
    /**
110
     * An array containing all of the values a pulse has for each column
111
     *
112
     * @var mixed
113
     */
114
    protected $raw_column_values;
115
116
    /**
117
     * An array containing objects extended from PulseColumnValue storing all of the values for each column
118
     *
119
     * @var array
120
     */
121
    protected $column_values;
122
123
    /**
124
     * The common URL path for retrieving objects relating a pulse such as subscribers, notes, or updates
125
     *
126
     * @var string
127
     */
128
    private $urlSyntax = "%s/%s/%s.json";
129
130
    // ================================================================================================================
131
    //   Overloaded functions
132
    // ================================================================================================================
133
134
    protected function initializeValues ()
135
    {
136
        $this->column_values     = array();
137
        $this->column_structure  = array();
138
        $this->raw_column_values = array();
139
    }
140
141
    // ================================================================================================================
142
    //   Getter functions
143
    // ================================================================================================================
144
145
    /**
146
     * The resource's URL.
147
     *
148
     * @return string
149
     */
150
    public function getUrl()
151
    {
152
        return $this->url;
153
    }
154
155
    /**
156
     * The pulse's unique identifier.
157
     *
158
     * @return int
159
     */
160
    public function getId()
161
    {
162
        return $this->id;
163
    }
164
165
    /**
166
     * The pulse's name.
167
     *
168
     * @return string
169
     */
170
    public function getName()
171
    {
172
        return $this->name;
173
    }
174
175
    /**
176
     * The amount of updates a pulse has.
177
     *
178
     * @return int
179
     */
180
    public function getUpdatesCount()
181
    {
182
        return $this->updates_count;
183
    }
184
185
    /**
186
     * The ID of the parent board.
187
     *
188
     * @return int
189
     */
190
    public function getBoardId()
191
    {
192
        return $this->board_id;
193
    }
194
195
    /**
196
     * Creation time.
197
     *
198
     * @return \DateTime
199
     */
200
    public function getCreatedAt()
201
    {
202
        return $this->created_at;
203
    }
204
205
    /**
206
     * Last update time.
207
     *
208
     * @return \DateTime
209
     */
210
    public function getUpdatedAt()
211
    {
212
        return $this->updated_at;
213
    }
214
215
    /**
216
     * Get the ID of the group this Pulse is a part of. If this value is not available, an API call will be made to
217
     * find the group ID via brute force.
218
     *
219
     * **Note** The group ID is cached if it is not available. To update the cached value, use $forceFetch to force an
220
     * API call to get a new value.
221
     *
222
     * **Warning** An API call is always slower than using the cached value.
223
     *
224
     * @param bool $forceFetch Force an API call to get an updated group ID if it has been changed
225
     * @since 0.1.0
226
     * @return string
227
     */
228
    public function getGroupId($forceFetch = false)
229
    {
230
        if (empty($this->group_id) || $forceFetch)
231
        {
232
            $parentBoard = new PulseBoard($this->board_id);
233
            $pulses = $parentBoard->getPulses();
234
235
            foreach ($pulses as $pulse)
236
            {
237
                if ($this->getId() === $pulse->getId())
238
                {
239
                    $this->group_id = $pulse->getGroupId();
240
                    break;
241
                }
242
            }
243
        }
244
245
        return $this->group_id;
246
    }
247
248
    // ================================================================================================================
249
    //   Pulse functions
250
    // ================================================================================================================
251
252
    /**
253
     * Delete the current Pulse
254
     *
255
     * @api
256
     * @throws \allejo\DaPulse\Exceptions\InvalidObjectException
257
     */
258 View Code Duplication
    public function deletePulse ()
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...
259
    {
260
        $this->checkInvalid();
261
262
        $deleteURL = sprintf("%s/%d.json", self::apiEndpoint(), $this->getId());
263
264
        self::sendDelete($deleteURL);
265
266
        $this->deletedObject = true;
267
    }
268
269
    public function duplicatePulse ($group_id = null, $owner_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...
Coding Style Naming introduced by
The parameter $owner_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...
270
    {
271
        $url = sprintf("%s/%s/pulses/%s/duplicate.json", parent::apiEndpoint("boards"), $this->getBoardId(), $this->getId());
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (apiEndpoint() instead of duplicatePulse()). 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...
272
        $postParams = array();
273
274
        if ($owner_id instanceof PulseUser)
275
        {
276
            $owner_id = $owner_id->getId();
277
        }
278
279
        self::setIfNotNullOrEmpty($postParams, "group_id", $group_id);
280
        self::setIfNotNullOrEmpty($postParams, "owner_id", $owner_id);
281
282
        $result = self::sendPost($url, $postParams);
283
        $this->pulseInjection($result);
284
285
        return (new Pulse($result['pulse']));
286
    }
287
288 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...
289
    {
290
        $parentBoard = new PulseBoard($this->getBoardId());
291
292
        // Inject some information so a Pulse object can survive on its own
293
        $result["pulse"]["group_id"] = $result["board_meta"]["group_id"];
294
        $result["pulse"]["column_structure"] = $parentBoard->getColumns();
295
        $result["pulse"]["raw_column_values"] = $result["column_values"];
296
    }
297
298
    // ================================================================================================================
299
    //   Column data functions
300
    // ================================================================================================================
301
302
    /**
303
     * Access a pulse's specific column to either access their value or to modify the value.
304
     *
305
     * See the related functions to see the appropriate replacements.
306
     *
307
     * @todo This function only exists for legacy applications. Remove in 0.1.1
0 ignored issues
show
Coding Style introduced by
Comment refers to a TODO task

This check looks TODO comments that have been left in the code.

``TODO``s show that something is left unfinished and should be attended to.

Loading history...
308
     *
309
     * @api
310
     * @deprecated 0.0.1 This function will be removed by 0.1.1. New stricter functions are available
311
     *
312
     * @param string $columnId The ID of the column to access. It's typically a slugified version of the column title
313
     *
314
     * @see Pulse::getStatusColumn()  getColorColumn()
315
     * @see Pulse::getDateColumn()   getDateColumn()
316
     * @see Pulse::getPersonColumn() getPersonColumn()
317
     * @see Pulse::getTextColumn()   getTextColumn()
318
     * @since 0.1.0
319
     * @throws InvalidObjectException The specified column exists but modification of its value is unsupported either
320
     *                                by this library or the DaPulse API.
321
     * @throws InvalidColumnException   The specified column ID does not exist for this Pulse
322
     * @return PulseColumnValue The returned object will be a child of this abstract class.
323
     */
324
    public function getColumnValue ($columnId)
325
    {
326
        if (!isset($this->column_values) || !array_key_exists($columnId, $this->column_values))
327
        {
328
            $key = ArrayUtilities::array_search_column($this->raw_column_values, 'cid', $columnId);
329
330
            $data = $this->raw_column_values[$key];
331
            $type = $this->column_structure[$key]->getType();
332
333
            $data['column_id'] = $data['cid'];
334
            $data['board_id'] = $this->getBoardId();
335
            $data['pulse_id'] = $this->getId();
336
337
            $this->column_values[$columnId] = PulseColumnValue::_createColumnType($type, $data);
338
        }
339
340
        return $this->column_values[$columnId];
341
    }
342
343
    /**
344
     * Access a color type column value belonging to this pulse in order to read it or modify.
345
     *
346
     * This function should only be used to access color type values; an exception will be thrown otherwise.
347
     *
348
     * @api
349
     *
350
     * @param string $columnId The ID of the column to access. This is typically a slugified version of the column name
351
     *
352
     * @since 0.1.0
353
     * @throws InvalidColumnException The specified column is not a "color" type column
354
     * @throws InvalidObjectException The specified column exists but modification of its value is unsupported either
355
     *                                by this library or the DaPulse API.
356
     * @throws InvalidColumnException   The specified column ID does not exist for this Pulse
357
     * @return PulseColumnStatusValue A column object with access to its contents
358
     */
359
    public function getStatusColumn ($columnId)
360
    {
361
        return $this->getColumn($columnId, PulseColumn::Status);
362
    }
363
364
    /**
365
     * Access a date type column value belonging to this pulse in order to read it or modify.
366
     *
367
     * This function should only be used to access data type values; an exception will be thrown otherwise.
368
     *
369
     * @api
370
     * @param string $columnId The ID of the column to access. This is typically a slugified version of the column name
371
     * @since 0.1.0
372
     * @throws InvalidColumnException The specified column is not a "date" type column
373
     * @throws InvalidObjectException The specified column exists but modification of its value is unsupported either
374
     *                                by this library or the DaPulse API.
375
     * @throws InvalidColumnException   The specified column ID does not exist for this Pulse
376
     * @return PulseColumnDateValue A column object with access to its contents
377
     */
378
    public function getDateColumn ($columnId)
379
    {
380
        return $this->getColumn($columnId, PulseColumn::Date);
381
    }
382
383
    /**
384
     * Access a person type column value belonging to this pulse in order to read it or modify.
385
     *
386
     * This function should only be used to access person type values; an exception will be thrown otherwise.
387
     *
388
     * @api
389
     * @param string $columnId The ID of the column to access. This is typically a slugified version of the column name
390
     * @since 0.1.0
391
     * @throws InvalidColumnException The specified column is not a "person" type column
392
     * @throws InvalidObjectException The specified column exists but modification of its value is unsupported either
393
     *                                by this library or the DaPulse API.
394
     * @throws InvalidColumnException   The specified column ID does not exist for this Pulse
395
     * @return PulseColumnPersonValue A column object with access to its contents
396
     */
397
    public function getPersonColumn ($columnId)
398
    {
399
        return $this->getColumn($columnId, PulseColumn::Person);
400
    }
401
402
    /**
403
     * Access a text type column value belonging to this pulse in order to read it or modify.
404
     *
405
     * This function should only be used to access text type values; an exception will be thrown otherwise.
406
     *
407
     * @api
408
     * @param string $columnId The ID of the column to access. This is typically a slugified version of the column name
409
     * @since 0.1.0
410
     * @throws InvalidColumnException The specified column is not a "text" type column
411
     * @throws InvalidObjectException The specified column exists but modification of its value is unsupported either
412
     *                                by this library or the DaPulse API.
413
     * @throws InvalidColumnException   The specified column ID does not exist for this Pulse
414
     * @return PulseColumnTextValue A column object with access to its contents
415
     */
416
    public function getTextColumn ($columnId)
417
    {
418
        return $this->getColumn($columnId, PulseColumn::Text);
419
    }
420
421
    /**
422
     * Build a pulse's column object if it doesn't exist or return the existing column.
423
     *
424
     * @param string $columnId   The ID of the column to access. This is typically a slugified version of the column
425
     *                           title
426
     * @param string $columnType The type of column being accessed: 'text', 'color', 'person', or 'date'
427
     *
428
     * @since 0.1.0
429
     *
430
     * @throws InvalidColumnException The specified column is not the same type as specified in `$columnType`
431
     * @throws InvalidObjectException The specified column exists but modification of its value is unsupported either
432
     *                                by this library or the DaPulse API.
433
     * @throws InvalidColumnException   The specified column ID does not exist for this Pulse
434
     *
435
     * @return PulseColumnValue The returned object will be a child of this abstract class.
436
     */
437
    private function getColumn ($columnId, $columnType)
438
    {
439
        if (!isset($this->column_values) || !array_key_exists($columnId, $this->column_values))
440
        {
441
            $key = ArrayUtilities::array_search_column($this->raw_column_values, 'cid', $columnId);
442
443
            // We can't find the key, this means that we got our information from accessing a Pulse directly instead of
444
            // getting it through a PulseBoard. This isn't as robust as accessing a PulseBoard but it's more efficient.
445
            // We make a separate API call to get the value of a column.
446
            if ($key === false)
447
            {
448
                $url = sprintf("%s/%d/columns/%s/value.json", parent::apiEndpoint("boards"), $this->getBoardId(), $columnId);
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (apiEndpoint() instead of getColumn()). 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...
449
                $params = array(
450
                    "pulse_id" => $this->getId()
451
                );
452
453
                try
454
                {
455
                    $results = parent::sendGet($url, $params);
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (sendGet() instead of getColumn()). Are you sure this is correct? If so, you might want to change this to $this->sendGet().

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...
456
                }
457
                catch (HttpException $e)
458
                {
459
                    throw new InvalidColumnException("The '$columnId' column could not be found");
460
                }
461
462
                // Store our value inside of jsonResponse so all of the respective objects can treat the data the same
463
                // as when accessed through a PulseBoard
464
                $data['jsonResponse']['value'] = $results['value'];
0 ignored issues
show
Coding Style Comprehensibility introduced by
$data was never initialized. Although not strictly required by PHP, it is generally a good practice to add $data = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
465
            }
466
            else
467
            {
468
                $data = $this->raw_column_values[$key];
469
                $type = $this->column_structure[$key]->getType();
470
471
                if ($type !== $columnType)
472
                {
473
                    throw new InvalidColumnException("The '$columnId' column was expected to be '$columnType' but was '$type' instead.");
474
                }
475
            }
476
477
            $data['column_id'] = $columnId;
478
            $data['board_id'] = $this->getBoardId();
479
            $data['pulse_id'] = $this->getId();
480
481
            $this->column_values[$columnId] = PulseColumnValue::_createColumnType($columnType, $data);
482
        }
483
484
        return $this->column_values[$columnId];
485
    }
486
487
    // ================================================================================================================
488
    //   Subscribers functions
489
    // ================================================================================================================
490
491
    /**
492
     * Subscribe a user to a pulse
493
     *
494
     * @api
495
     *
496
     * @param  int|PulseUser $user_id  The user that will be subscribed
497
     * @param  bool|null     $as_admin True to make them an admin of the Pulse
498
     *
499
     * @since  0.1.0
500
     *
501
     * @throws HttpException Subscribing a user failed; access the exception for more information.
502
     */
503
    public function addSubscriber ($user_id, $as_admin = 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...
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...
504
    {
505
        if ($user_id instanceof PulseUser)
506
        {
507
            $user_id = $user_id->getId();
508
        }
509
510
        $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...
511
        $params = array(
512
            "user_id" => $user_id
513
        );
514
515
        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...
516
        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...
517
    }
518
519
    /**
520
     * Access a pulse's subscribers
521
     *
522
     * To modify the amount of data returned with pagination, use the following values in the array to configure your
523
     * pagination or offsets.
524
     *
525
     * ```php
526
     * $params = array(
527
     *     "page"     => 1,  // (int) Page offset to fetch
528
     *     "per_page" => 10, // (int) Number of results per page
529
     *     "offset"   => 5,  // (int) Instead of starting at result 0, start counting from result 5
530
     * );
531
     * ```
532
     *
533
     * @api
534
     * @param array $params GET parameters passed to with the query to modify the data returned.
535
     * @since 0.1.0
536
     * @return PulseUser[]
537
     */
538
    public function getSubscribers ($params = array())
539
    {
540
        $url = sprintf($this->urlSyntax, parent::apiEndpoint(), $this->id, "subscribers");
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...
541
542
        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...
543
    }
544
545
    /**
546
     * Unsubscribe a person from a pulse
547
     *
548
     * @api
549
     *
550
     * @param int|PulseUser $user_id The user that will be subscribed
551
     *
552
     * @since 0.1.0
553
     *
554
     * @throws HttpException Removing a user failed; access the exception for more information.
555
     */
556 View Code Duplication
    public function removeSubscriber ($user_id)
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...
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...
557
    {
558
        if ($user_id instanceof PulseUser)
559
        {
560
            $user_id = $user_id->getId();
561
        }
562
563
        $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...
564
565
        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...
566
    }
567
568
    // ================================================================================================================
569
    //   Notes functions
570
    // ================================================================================================================
571
572
    /**
573
     * Create a new note in this project
574
     *
575
     * @api
576
     * @param  string   $title         The title of the note
577
     * @param  string   $content       The body of the note
578
     * @param  bool     $owners_only   Set to true if only pulse owners can edit this note.
579
     * @param  int|null $user_id       The id of the user to be marked as the note’s last updater
580
     * @param  bool     $create_update Indicates whether to create an update on the pulse notifying subscribers on the
581
     *                                 changes (required user_id to be set).
582
     * @since  0.1.0
583
     * @return PulseNote
584
     */
585
    public function addNote ($title, $content, $owners_only = false, $user_id = NULL, $create_update = false)
0 ignored issues
show
Coding Style Naming introduced by
The parameter $owners_only 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 $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 $create_update 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...
586
    {
587
        $url        = sprintf($this->urlSyntax, parent::apiEndpoint(), $this->id, "notes");
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (apiEndpoint() instead of addNote()). 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...
588
        $postParams = array(
589
            "id"            => $this->id,
590
            "title"         => $title,
591
            "content"       => $content,
592
            "owners_only"   => $owners_only,
593
            "create_update" => $create_update
594
        );
595
596
        self::setIfNotNullOrEmpty($postParams, "user_id", $user_id);
597
598
        if ($create_update && is_null($user_id))
599
        {
600
            throw new \InvalidArgumentException("The user_id value must be set if an update is to be created");
601
        }
602
603
        $noteResult = self::sendPost($url, $postParams);
604
605
        return (new PulseNote($noteResult));
606
    }
607
608
    /**
609
     * Return all of the notes belonging to this project
610
     *
611
     * @api
612
     * @since  0.1.0
613
     * @return PulseNote[]
614
     */
615
    public function getNotes ()
616
    {
617
        $url = sprintf($this->urlSyntax, parent::apiEndpoint(), $this->id, "notes");
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (apiEndpoint() instead of getNotes()). 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...
618
619
        return parent::fetchJsonArrayToObjectArray($url, "PulseNote");
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (fetchJsonArrayToObjectArray() instead of getNotes()). 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...
620
    }
621
622
    // ================================================================================================================
623
    //   Updates functions
624
    // ================================================================================================================
625
626
    /**
627
     * Get all of the updates that belong this Pulse
628
     *
629
     * @api
630
     * @since 0.1.0
631
     * @return PulseUpdate[]
632
     */
633
    public function getUpdates ()
634
    {
635
        $url = sprintf($this->urlSyntax, parent::apiEndpoint(), $this->id, "updates");
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (apiEndpoint() instead of getUpdates()). 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...
636
637
        return parent::fetchJsonArrayToObjectArray($url, "PulseUpdate");
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (fetchJsonArrayToObjectArray() instead of getUpdates()). 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...
638
    }
639
640
    // ================================================================================================================
641
    //   Static functions
642
    // ================================================================================================================
643
644
    /**
645
     * Get all of the pulses that belong to the organization across all boards.
646
     *
647
     * To modify the amount of data returned with pagination, use the following values in the array to configure your
648
     * pagination or offsets.
649
     *
650
     * ```php
651
     * $params = array(
652
     *     "page"     => 1,          // (int) Page offset to fetch
653
     *     "per_page" => 10,         // (int) Number of results per page
654
     *     "offset"   => 5,          // (int) Instead of starting at result 0, start counting from result 5
655
     *     "order_by_latest" => true // (bool) Order the pulses with the most recent first
656
     * );
657
     * ```
658
     *
659
     * @api
660
     * @param array $params GET parameters passed to with the query to modify the data returned.
661
     * @since 0.1.0
662
     * @return Pulse[]
663
     */
664
    public static function getPulses ($params = array())
665
    {
666
        $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 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...
667
668
        return parent::fetchJsonArrayToObjectArray($url, "Pulse", $params);
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (fetchJsonArrayToObjectArray() instead of getPulses()). 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...
669
    }
670
}