Video   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 55
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 1
dl 55
loc 55
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 4 4 1
A getVideo() 4 4 1
A getTop() 4 4 1
A getChannelVideos() 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\TwitchRequest;
6
use jofner\SDK\TwitchTV\TwitchSDKException;
7
8
/**
9
 * Videos 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 Video
16
{
17
    /** @var TwitchRequest */
18
    protected $request;
19
20
    const URI_VIDEO = 'videos/';
21
    const URI_VIDEO_TOP = 'videos/top';
22
    const URI_VIDEO_CHANNEL = 'channels/%s/videos';
23
24
    /**
25
     * Video constructor
26
     * @param TwitchRequest $request
27
     */
28
    public function __construct(TwitchRequest $request)
29
    {
30
        $this->request = $request;
31
    }
32
33
    /**
34
     * Returns a video object
35
     * @see https://github.com/justintv/Twitch-API/blob/master/v3_resources/videos.md#get-videosid
36
     * @param string $id
37
     * @return \stdClass
38
     * @throws TwitchSDKException
39
     */
40
    public function getVideo($id)
41
    {
42
        return $this->request->request(self::URI_VIDEO . $id);
43
    }
44
45
    /**
46
     * Returns a list of videos created in a given time period sorted by number of views, most popular first
47
     * @see https://github.com/justintv/Twitch-API/blob/master/v3_resources/videos.md#get-videostop
48
     * @param string $queryString
49
     * @return \stdClass
50
     * @throws TwitchSDKException
51
     */
52
    public function getTop($queryString)
53
    {
54
        return $this->request->request(self::URI_VIDEO_TOP . $queryString);
55
    }
56
57
    /**
58
     * Returns a list of videos ordered by time of creation, starting with the most recent from :channel
59
     * @see https://github.com/justintv/Twitch-API/blob/master/v3_resources/videos.md#get-channelschannelvideos
60
     * @param string $channel
61
     * @param string $queryString
62
     * @return \stdClass
63
     * @throws TwitchSDKException
64
     */
65
    public function getChannelVideos($channel, $queryString)
66
    {
67
        return $this->request->request(sprintf(self::URI_VIDEO_CHANNEL, $channel) . $queryString);
68
    }
69
}
70