Completed
Push — master ( 33fd23...1adc69 )
by Johnny
05:23
created

Channels::getChannelByName()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 33
Code Lines 27

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 33
ccs 0
cts 30
cp 0
rs 8.8571
cc 2
eloc 27
nc 2
nop 1
crap 6
1
<?php
2
namespace Redbox\Twitch\Resource;
3
use Redbox\Twitch\Exception;
4
use Redbox\Twitch\Entity;
5
6
class Channels extends ResourceAbstract
7
{
8
    public function getChannel($args = array())
9
    {
10
        $response = $this->call('getChannel', $args);
11
12
        $channel = new Entity\Channel;
13
14
        if (isset($response->profile_banner_background_color)) {
15
            $channel->setProfileBannerBackgroundColor($response->profile_banner_background_color);
16
            $channel->setBroadcasterLanguage($response->broadcaster_language);
17
            $channel->setProfileBanner($response->profile_banner);
18
            $channel->setVideoBanner($response->video_banner);
19
            $channel->setDisplayName($response->display_name);
20
            $channel->setCreatedAt($response->created_at);
21
            $channel->setUpdatedAt($response->updated_at);
22
            $channel->setBackground($response->background);
23
            $channel->setStreamKey($response->stream_key);
24
            $channel->setFollowers($response->followers);
25
            $channel->setLanguage($response->language);
26
            $channel->setPartner($response->partner);
27
            $channel->setBanner($response->banner);
28
            $channel->setMature($response->mature);
29
            $channel->setStatus($response->status);
30
            $channel->setDelay($response->delay);
31
            $channel->setViews($response->views);
32
            $channel->setEmail($response->email);
33
            $channel->setGame($response->game);
34
            $channel->setName($response->name);
35
            $channel->setLogo($response->logo);
36
            $channel->setUrl($response->url);
37
        }
38
39
        return $channel;
40
    }
41
42
    public function getChannelByName($args = array())
43
    {
44
        $response = $this->call('getChannelByName', $args);
45
46
        $channel = new Entity\Channel;
47
48
        if (isset($response->profile_banner_background_color)) {
49
            $channel->setProfileBannerBackgroundColor($response->profile_banner_background_color);
50
            $channel->setBroadcasterLanguage($response->broadcaster_language);
51
            $channel->setProfileBanner($response->profile_banner);
52
            $channel->setVideoBanner($response->video_banner);
53
            $channel->setDisplayName($response->display_name);
54
            $channel->setCreatedAt($response->created_at);
55
            $channel->setUpdatedAt($response->updated_at);
56
            $channel->setBackground($response->background);
57
            $channel->setStreamKey($response->stream_key);
58
            $channel->setFollowers($response->followers);
59
            $channel->setLanguage($response->language);
60
            $channel->setPartner($response->partner);
61
            $channel->setBanner($response->banner);
62
            $channel->setMature($response->mature);
63
            $channel->setStatus($response->status);
64
            $channel->setDelay($response->delay);
65
            $channel->setViews($response->views);
66
            $channel->setEmail($response->email);
67
            $channel->setGame($response->game);
68
            $channel->setName($response->name);
69
            $channel->setLogo($response->logo);
70
            $channel->setUrl($response->url);
71
        }
72
73
        return $channel;
74
    }
75
76
    public function getChannelVideos($args = array())
77
    {
78
        $response = $this->call('getChannelVideos', $args);
79
80
        $videos = [];
81
82
        if (is_object($response) === true) {
83
            if (isset($response->videos) === true) {
84
                foreach($response->videos as $vid) {
85
                    $video = new Entity\Video();
86
                    $video->setTitle($vid->title);
87
                    $video->setDescription($vid->description);
88
                    $video->setBroadcastId($vid->broadcast_id);
89
                    $video->setStatus($vid->status);
90
                    $video->setTagList($vid->tag_list);
91
                    $video->setRecordedAt($vid->recorded_at);
92
                    $video->setGame($vid->game);
93
                    $video->setLength($vid->length);
94
                    if (isset($vid->delete_at)) $video->setDeleteAt($vid->delete_at);
95
                    if (isset($vid->vod_type)) $video->setVodType($vid->vod_type);
96
                    $video->setIsMuted($vid->is_muted);
97
                    $video->setPreview($vid->preview);
98
                    $video->setThumbnails($vid->thumbnails);
99
                    $video->setResolutions($vid->resolutions);
100
                    $video->setBroadcastType($vid->broadcast_type);
101
                    $video->setCreatedAt($vid->created_at);
102
                    $video->setChannel($vid->channel);
103
                    $video->setFps($vid->fps);
104
                    $video->setViews($vid->views);
105
                    $video->setUrl($vid->url);
106
                    $video->setId($vid->_id);
107
                    $videos[] = $video;
108
                }
109
            }
110
        }
111
        return $videos;
112
113
    }
114
115
    public function getChannelEditors($args = array())
116
    {
117
        $response = $this->call('getChannelEditors', $args);
118
119
        $editors = [];
120
121
        if (is_object($response) === true) {
122
            if (isset($response->users) === true) {
123
                foreach($response->users as $editor) {
124
                    $user = new Entity\User;
125
                    $user->setDisplayName($editor->display_name);
126
                    $user->setName($editor->name);
127
                    $user->setType($editor->type);
128
                    $user->setType($editor->type);
129
                    $user->setBio($editor->bio);
130
                    $user->setCreatedAt($editor->created_at);
131
                    $user->setUpdatedAt($editor->updated_at);
132
                    $user->setLogo($editor->logo);
133
                    $user->setId($editor->_id);
134
                    $editors[] = $user;
135
                }
136
            }
137
        }
138
139
        return $editors;
140
    }
141
142
    public function updateChannelByName($args = array())
143
    {
144
        $response = $this->call('updateChannelByName', $args);
0 ignored issues
show
Unused Code introduced by
$response is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
145
        
146
    }
147
148
}