User   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 66
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 1
dl 66
loc 66
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 4 4 1
A getUser() 4 4 1
A getUserAuth() 4 4 1
A getFollowedStreams() 4 4 1
A getFollowedVideos() 4 4 1

How to fix   Duplicated Code   

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:

1
<?php
2
3
namespace jofner\SDK\TwitchTV\Methods;
4
5
use jofner\SDK\TwitchTV\TwitchSDKException;
6
use jofner\SDK\TwitchTV\TwitchRequest;
7
8
/**
9
 * Users method class for TwitchTV API SDK for PHP
10
 *
11
 * @author Josef Ohnheiser <[email protected]>
12
 * @license https://github.com/jofner/Twitch-SDK/blob/master/LICENSE.md MIT
13
 * @homepage https://github.com/jofner/Twitch-SDK
14
 */
15 View Code Duplication
class User
16
{
17
    /** @var TwitchRequest */
18
    protected $request;
19
20
    const URI_USER = 'users/';
21
    const URI_USER_AUTH = 'user';
22
    const URI_STREAMS_FOLLOWED_AUTH = 'streams/followed';
23
    const URI_VIDEOS_FOLLOWED_AUTH = 'videos/followed';
24
25
    public function __construct(TwitchRequest $request)
26
    {
27
        $this->request = $request;
28
    }
29
30
    /**
31
     * Get the specified user
32
     * @see https://github.com/justintv/Twitch-API/blob/master/v3_resources/users.md#get-usersuser
33
     * @param string $username
34
     * @return \stdClass
35
     * @throws TwitchSDKException
36
     */
37
    public function getUser($username)
38
    {
39
        return $this->request->request(self::URI_USER . $username);
40
    }
41
42
    /**
43
     * Get the authenticated user
44
     *  - requires scope 'user_read'
45
     * @see https://github.com/justintv/Twitch-API/blob/master/v3_resources/users.md#get-user
46
     * @param string $queryString
47
     * @return \stdClass
48
     * @throws TwitchSDKException
49
     */
50
    public function getUserAuth($queryString)
51
    {
52
        return $this->request->request(self::URI_USER_AUTH . $queryString);
53
    }
54
55
    /**
56
     * List the live streams that the authenticated user is following
57
     *  - requires scope 'user_read'
58
     * @see https://github.com/justintv/Twitch-API/blob/master/v3_resources/users.md#get-streamsfollowed
59
     * @param string $queryString
60
     * @return \stdClass
61
     * @throws TwitchSDKException
62
     */
63
    public function getFollowedStreams($queryString)
64
    {
65
        return $this->request->request(self::URI_STREAMS_FOLLOWED_AUTH . $queryString);
66
    }
67
68
    /**
69
     * List of videos that the authenticated user is following
70
     *  - requires scope 'user_read'
71
     * @see https://github.com/justintv/Twitch-API/blob/master/v3_resources/users.md#get-videosfollowed
72
     * @param string $queryString
73
     * @return \stdClass
74
     * @throws TwitchSDKException
75
     */
76
    public function getFollowedVideos($queryString)
77
    {
78
        return $this->request->request(self::URI_VIDEOS_FOLLOWED_AUTH . $queryString);
79
    }
80
}
81