Completed
Push — develop ( 2ce0a7...a053c0 )
by Vladimir
04:14
created

PulseUser   A

Complexity

Total Complexity 26

Size/Duplication

Total Lines 407
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 11
Bugs 0 Features 0
Metric Value
wmc 26
c 11
b 0
f 0
lcom 2
cbo 1
dl 0
loc 407
ccs 6
cts 6
cp 1
rs 10

21 Methods

Rating   Name   Duplication   Size   Complexity  
A getNewsFeed() 0 6 1
A getPosts() 0 6 1
A getUnreadFeed() 0 6 1
A getUsers() 0 6 1
B _isCastable() 0 7 5
A getUrl() 0 6 1
A getId() 0 4 1
A getName() 0 6 1
A getEmail() 0 6 1
A getPhotoUrl() 0 6 1
A getTitle() 0 6 1
A getPosition() 0 6 1
A getPhone() 0 6 1
A getLocation() 0 6 1
A getStatus() 0 6 1
A getBirthday() 0 6 1
A getIsGuest() 0 6 1
A getSkills() 0 6 1
A getCreatedAt() 0 7 1
A getUpdatedAt() 0 7 1
A _castToInt() 0 6 2
1
<?php
2
3
/**
4
 * @copyright 2017 Vladimir Jimenez
5
 * @license   https://github.com/allejo/PhpPulse/blob/master/LICENSE.md MIT
6
 */
7
8
namespace allejo\DaPulse;
9
10
use allejo\DaPulse\Objects\ApiObject;
11
12
/**
13
 * The PulseUser class contains all of the functions related to accessing information about a user
14
 *
15
 * @package allejo\DaPulse
16
 * @since   0.1.0
17
 */
18
class PulseUser extends ApiObject
19
{
20
    /**
21
     * {@inheritdoc}
22
     */
23
    const API_PREFIX = "users";
24
25
    /**
26
     * The resource's URL.
27
     *
28
     * @var string
29
     */
30
    protected $url;
31
32
    /**
33
     * The user's name.
34
     *
35
     * @var string
36
     */
37
    protected $name;
38
39
    /**
40
     * The user's email.
41
     *
42
     * @var string
43
     */
44
    protected $email;
45
46
    /**
47
     * The user's photo_url.
48
     *
49
     * @var string
50
     */
51
    protected $photo_url;
52
53
    /**
54
     * The user's title.
55
     *
56
     * @var string
57
     */
58
    protected $title;
59
60
    /**
61
     * The user's position.
62
     *
63
     * @var string
64
     */
65
    protected $position;
66
67
    /**
68
     * The user's phone.
69
     *
70
     * @var string
71
     */
72
    protected $phone;
73
74
    /**
75
     * The user's location.
76
     *
77
     * @var string
78
     */
79
    protected $location;
80
81
    /**
82
     * The user's status.
83
     *
84
     * @var string
85
     */
86
    protected $status;
87
88
    /**
89
     * The user's birthday.
90
     *
91
     * @var string
92
     */
93
    protected $birthday;
94
95
    /**
96
     * True if the user is guest, false otherwise
97
     *
98
     * @var bool
99
     */
100
    protected $is_guest;
101
102
    /**
103
     * The user's skills.
104
     *
105
     * @var string[]
106
     */
107
    protected $skills;
108
109
    /**
110
     * Creation time.
111
     *
112
     * @var \DateTime
113
     */
114
    protected $created_at;
115
116
    /**
117
     * Last update time.
118
     *
119
     * @var \DateTime
120
     */
121
    protected $updated_at;
122
123
    /**
124
     * The membership type of this user with respect to a specific Pulse or PulseBoard. This value will not be set if
125
     * a PulseUser object is created standalone and not by another object which supports subscribers or membership.
126
     *
127
     * @var mixed
128
     */
129
    protected $membership;
130
131
    /**
132
     * The URL pattern used for all calls
133
     *
134
     * @var string
135
     */
136
    private $urlSyntax = "%s/%s/%s.json";
137
138
    // ================================================================================================================
139
    //   Getter functions
140
    // ================================================================================================================
141
142
    /**
143
     * The resource's URL.
144
     *
145
     * @return string
146
     */
147
    public function getUrl ()
148
    {
149
        $this->lazyLoad();
150
151
        return $this->url;
152
    }
153
154
    /**
155
     * The user's unique identifier.
156
     *
157
     * @return int
158
     */
159
    public function getId ()
160
    {
161
        return $this->id;
162
    }
163
164
    /**
165
     * The user's name.
166 3
     *
167
     * @return string
168 3
     */
169
    public function getName ()
170
    {
171
        $this->lazyLoad();
172
173
        return $this->name;
174
    }
175
176
    /**
177
     * The user's email.
178
     *
179
     * @return string
180
     */
181
    public function getEmail ()
182
    {
183
        $this->lazyLoad();
184
185
        return $this->email;
186
    }
187
188
    /**
189
     * The user's photo_url.
190
     *
191
     * @return string
192
     */
193
    public function getPhotoUrl ()
194
    {
195
        $this->lazyLoad();
196
197
        return $this->photo_url;
198
    }
199
200
    /**
201
     * The user's title.
202
     *
203
     * @return string
204
     */
205
    public function getTitle ()
206
    {
207
        $this->lazyLoad();
208
209
        return $this->title;
210
    }
211
212
    /**
213
     * The user's position.
214
     *
215
     * @return string
216
     */
217
    public function getPosition ()
218
    {
219
        $this->lazyLoad();
220
221
        return $this->position;
222
    }
223
224
    /**
225
     * The user's phone.
226
     *
227
     * @return string
228
     */
229
    public function getPhone ()
230
    {
231
        $this->lazyLoad();
232
233
        return $this->phone;
234
    }
235
236
    /**
237
     * The user's location.
238
     *
239
     * @return string
240
     */
241
    public function getLocation ()
242
    {
243
        $this->lazyLoad();
244
245
        return $this->location;
246
    }
247
248
    /**
249
     * The user's status.
250
     *
251
     * @return string
252
     */
253
    public function getStatus ()
254
    {
255
        $this->lazyLoad();
256
257
        return $this->status;
258
    }
259
260
    /**
261
     * The user's birthday.
262
     *
263
     * @return string
264
     */
265
    public function getBirthday ()
266
    {
267
        $this->lazyLoad();
268
269
        return $this->birthday;
270
    }
271
272
    /**
273
     * True if the user is guest, false otherwise
274
     *
275
     * @return bool
276
     */
277
    public function getIsGuest ()
278
    {
279
        $this->lazyLoad();
280
281
        return $this->is_guest;
282
    }
283
284
    /**
285
     * The user's skills.
286
     *
287
     * @return string[]
288
     */
289
    public function getSkills ()
290
    {
291
        $this->lazyLoad();
292
293
        return $this->skills;
294
    }
295
296
    /**
297
     * Creation time.
298
     *
299
     * @return \DateTime
300
     */
301
    public function getCreatedAt ()
302
    {
303
        $this->lazyLoad();
304
        self::lazyCast($this->created_at, '\DateTime');
305
306
        return $this->created_at;
307
    }
308
309
    /**
310
     * Last update time.
311
     *
312
     * @return \DateTime
313
     */
314
    public function getUpdatedAt ()
315
    {
316
        $this->lazyLoad();
317
        self::lazyCast($this->updated_at, '\DateTime');
318
319
        return $this->updated_at;
320
    }
321
322
    /**
323
     * Get the user's newsfeed
324
     *
325
     * @param  array $params GET parameters that need to be passed in the URL
326
     *
327
     * @since  0.1.0
328
     *
329
     * @return PulseUpdate[] An array of PulseUpdates that make up the user's newsfeed
330
     */
331
    public function getNewsFeed ($params = array())
332
    {
333
        $url = sprintf($this->urlSyntax, parent::apiEndpoint(), $this->id, "newsfeed");
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (apiEndpoint() instead of getNewsFeed()). 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...
334
335
        return parent::fetchAndCastToObjectArray($url, "PulseUpdate", $params);
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (fetchAndCastToObjectArray() instead of getNewsFeed()). Are you sure this is correct? If so, you might want to change this to $this->fetchAndCastToObjectArray().

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...
336
    }
337
338
    /**
339
     * Get the user's posts
340
     *
341
     * @param  array $params GET parameters that need to be passed in the URL
342
     *
343
     * @since  0.1.0
344
     *
345
     * @return PulseUpdate[] An array of PulseUpdates for each of the posts
346
     */
347
    public function getPosts ($params = array())
348
    {
349
        $url = sprintf($this->urlSyntax, parent::apiEndpoint(), $this->id, "posts");
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (apiEndpoint() instead of getPosts()). 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...
350
351
        return parent::fetchAndCastToObjectArray($url, "PulseUpdate", $params);
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (fetchAndCastToObjectArray() instead of getPosts()). Are you sure this is correct? If so, you might want to change this to $this->fetchAndCastToObjectArray().

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...
352
    }
353
354
    /**
355
     * Get the user's unread posts
356
     *
357
     * @param  array $params GET parameters that need to be passed in the URL
358
     *
359
     * @since  0.1.0
360
     *
361
     * @return PulseUpdate[] An array of PulseUpdates for each of the posts
362
     */
363
    public function getUnreadFeed ($params = array())
364
    {
365
        $url = sprintf($this->urlSyntax, parent::apiEndpoint(), $this->id, "unread_feed");
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (apiEndpoint() instead of getUnreadFeed()). 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...
366
367
        return parent::fetchAndCastToObjectArray($url, "PulseUpdate", $params);
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (fetchAndCastToObjectArray() instead of getUnreadFeed()). Are you sure this is correct? If so, you might want to change this to $this->fetchAndCastToObjectArray().

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...
368
    }
369
370
    /**
371
     * Get all of the users
372
     *
373
     * @param  array $params GET parameters that need to be passed in the URL
374
     *
375
     * @since  0.1.0
376
     *
377
     * @return PulseUser[] An array of PulseUsers for each of the users
378
     */
379
    public static function getUsers ($params = array())
380
    {
381
        $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 getUsers()). 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
        return parent::fetchAndCastToObjectArray($url, "PulseUser", $params);
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (fetchAndCastToObjectArray() instead of getUsers()). Are you sure this is correct? If so, you might want to change this to $this->fetchAndCastToObjectArray().

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...
384
    }
385
386
    // =================================================================================================================
387
    //   Convenience functions
388
    // =================================================================================================================
389
390
    /**
391
     * Check whether a given value can be casted or used to get a user ID
392
     *
393
     * @internal
394
     *
395
     * @param int|PulseUser $user
396
     *
397
     * @since 0.3.0
398
     *
399
     * @throws \InvalidArgumentException if $user is not an integer, is not positive, or is not a PulseUser object
400
     */
401 10
    public static function _isCastable ($user)
402
    {
403 10
        if ((!is_int($user) || (is_int($user) && $user < 1)) && !($user instanceof PulseUser))
404
        {
405 5
            throw new \InvalidArgumentException('$user is expected to be a positive integer or a PulseUser object');
406
        }
407 5
    }
408
409
    /**
410
     * @internal
411
     *
412
     * @param  int|PulseUser $user
413
     *
414
     * @since  0.3.0
415
     *
416
     * @return int
417
     */
418
    public static function _castToInt ($user)
419
    {
420
        self::_isCastable($user);
421
422
        return ($user instanceof PulseUser) ? $user->getId() : $user;
423
    }
424
}