Rated::removeTVShowEpisodeRate()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 3
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
/**
3
 * This file is part of the Tmdb package.
4
 *
5
 * (c) Vincent Faliès <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 *
10
 * @author Vincent Faliès <[email protected]>
11
 * @copyright Copyright (c) 2017
12
 */
13
14
15
namespace VfacTmdb\Account;
16
17
use VfacTmdb\Results;
18
use VfacTmdb\Exceptions\TmdbException;
19
use VfacTmdb\Abstracts\Account;
20
21
/**
22
 * Class to manipulate account rated
23
 * @package Tmdb
24
 * @author Vincent Faliès <[email protected]>
25
 * @copyright Copyright (c) 2017
26
 */
27
class Rated extends Account
28
{
29
30
    /**
31
     * Get movies rated
32
     * @return \Generator|Results\Movie
33
     */
34 3
    public function getMovies() : \Generator
35
    {
36 3
        return $this->getAccountListItems('rated', 'movies', Results\Movie::class);
37
    }
38
39
    /**
40
     * Get TV shows rated
41
     * @return \Generator|Results\TVShow
42
     */
43 3
    public function getTVShows() : \Generator
44
    {
45 3
        return $this->getAccountListItems('rated', 'tv', Results\TVShow::class);
46
    }
47
48
    /**
49
     * Get TV episodes rated
50
     * @return \Generator|Results\TVEpisode
51
     */
52 3
    public function getTVEpisodes() : \Generator
53
    {
54 3
        return $this->getAccountListItems('rated', 'tv/episodes', Results\TVEpisode::class);
55
    }
56
57
    /**
58
     * Add movie rate
59
     * @param  int   $movie_id
60
     * @param  float $rate
61
     * @return Rated
62
     */
63 6
    public function addMovieRate(int $movie_id, float $rate) : Rated
64
    {
65 6
        return $this->addRate('movie/' . $movie_id . '/rating', $rate);
66
    }
67
68
    /**
69
     * Remove movie rate
70
     * @param  int   $movie_id
71
     * @return Rated
72
     */
73 6
    public function removeMovieRate(int $movie_id) : Rated
74
    {
75 6
        return $this->removeRate('movie/' . $movie_id . '/rating');
76
    }
77
78
    /**
79
     * Add TVShow rate
80
     * @param  int   $tv_id
81
     * @param  float $rate
82
     * @return Rated
83
     */
84 3
    public function addTVShowRate(int $tv_id, float $rate) : Rated
85
    {
86 3
        return $this->addRate('tv/' . $tv_id . '/rating', $rate);
87
    }
88
89
    /**
90
     * Remove TVShow rate
91
     * @param  int   $tv_id
92
     * @return Rated
93
     */
94 3
    public function removeTVShowRate(int $tv_id) : Rated
95
    {
96 3
        return $this->removeRate('tv/' . $tv_id . '/rating');
97
    }
98
99
    /**
100
     * Add TVShow episode rate
101
     * @param  int   $tv_id
102
     * @param  int   $season_number
103
     * @param  int   $episode_number
104
     * @param  float $rate
105
     * @return Rated
106
     */
107 3
    public function addTVShowEpisodeRate(int $tv_id, int $season_number, int $episode_number, float $rate) : Rated
108
    {
109 3
        return $this->addRate('tv/' . $tv_id . '/season/' . $season_number . '/episode/' . $episode_number . '/rating', $rate);
110
    }
111
112
    /**
113
     * Remove TVSHow episode rate
114
     * @param  int   $tv_id
115
     * @param  int   $season_number
116
     * @param  int   $episode_number
117
     * @return Rated
118
     */
119 3
    public function removeTVShowEpisodeRate(int $tv_id, int $season_number, int $episode_number) : Rated
120
    {
121 3
        return $this->removeRate('tv/' . $tv_id . '/season/' . $season_number . '/episode/' . $episode_number . '/rating');
122
    }
123
124
    /**
125
     * Add rate
126
     * @param  string $action uri action
127
     * @param  float  $rate
128
     * @return Rated
129
     */
130 12
    private function addRate(string $action, float $rate) : Rated
131
    {
132
        try {
133 12
            $params = [];
134 12
            $params['value'] = $rate;
135
136 12
            $this->tmdb->postRequest($action, $this->options, $params);
137
138 9
            return $this;
139 3
        } catch (TmdbException $e) {
140 3
            throw $e;
141
        }
142
    }
143
144
    /**
145
     * Remove Rate
146
     * @param  string $action uri action
147
     * @return Rated
148
     */
149 12
    private function removeRate(string $action) : Rated
150
    {
151
        try {
152 12
            $this->tmdb->deleteRequest($action, $this->options);
153
154 9
            return $this;
155 3
        } catch (TmdbException $e) {
156 3
            throw $e;
157
        }
158
    }
159
}
160