Account   A
last analyzed

Complexity

Total Complexity 13

Size/Duplication

Total Lines 158
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 28
dl 0
loc 158
ccs 34
cts 34
cp 1
rs 10
c 1
b 0
f 0
wmc 13

12 Methods

Rating   Name   Duplication   Size   Complexity  
A getName() 0 3 1
A getFavorite() 0 3 1
A getRated() 0 3 1
A getUsername() 0 3 1
A getWatchList() 0 3 1
A getLanguage() 0 3 1
A getCountry() 0 3 1
A getIncludeAdult() 0 3 1
A __construct() 0 13 2
A getId() 0 3 1
A getList() 0 6 1
A getGravatarHash() 0 3 1
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;
16
17
use VfacTmdb\Account\Rated;
18
use VfacTmdb\Account\WatchList;
19
use VfacTmdb\Exceptions\ServerErrorException;
20
use VfacTmdb\Interfaces\TmdbInterface;
21
use VfacTmdb\Account\Favorite;
22
23
/**
24
 * Account class
25
 * @package Tmdb
26
 * @author Vincent Faliès <[email protected]>
27
 * @copyright Copyright (c) 2017
28
 */
29
class Account
30
{
31
    /**
32
     * Tmdb object
33
     * @var TmdbInterface
34
     */
35
    private $tmdb = null;
36
    /**
37
     * Logger object
38
     * @var \Psr\Log\LoggerInterface
39
     */
40
    private $logger = null;
41
    /**
42
     * Session id string
43
     * @var string
44
     */
45
    private $session_id = null;
46
    /**
47
     * Data
48
     * @var \stdClass
49
     */
50
    private $data = null;
51
    /**
52
     * Configuration
53
     * @var \stdClass
54
     */
55
    protected $conf;
56
    /**
57
     * Account Id
58
     * @var int
59
     */
60
    protected $account_id;
61
62
    /**
63
     * Constructor
64
     * @param TmdbInterface $tmdb
65
     * @param string $session_id
66
     */
67 108
    public function __construct(TmdbInterface $tmdb, string $session_id)
68
    {
69 108
        $this->tmdb       = $tmdb;
70 108
        $this->logger     = $tmdb->getLogger();
71 108
        $this->conf       = $this->tmdb->getConfiguration();
72 108
        $this->session_id = $session_id;
73
74
        // Get details account
75 108
        $this->data       = $this->tmdb->getRequest('account', array('session_id' => $this->session_id));
76 108
        if (!isset($this->data->id)) {
77 3
            throw new ServerErrorException('Invalid response for details account');
78
        }
79 105
        $this->account_id = $this->data->id;
80 105
    }
81
82
    /**
83
     * Get an account list
84
     * @param  string $type    class name of the type of list (possible value : Favorite, Rated, WatchList)
85
     * @param  array  $options
86
     * @return mixed
87
     */
88 84
    private function getList(string $type, array $options = array())
89
    {
90 84
        $this->logger->debug("Starting getting account $type elements", array('options' => $options));
91 84
        $list = new $type($this->tmdb, $this->session_id, $this->account_id, $options);
92
93 84
        return $list;
94
    }
95
96
    /**
97
     * Get account favorite elements
98
     * @param array $options
99
     * @return Favorite
100
     */
101 24
    public function getFavorite(array $options = array()) : Favorite
102
    {
103 24
        return $this->getList(Favorite::class, $options);
104
    }
105
106
    /**
107
     * Get account rated elements
108
     * @param array $options
109
     * @return Rated
110
     */
111 36
    public function getRated(array $options = array()) : Rated
112
    {
113 36
        return $this->getList(Rated::class, $options);
114
    }
115
116
    /**
117
     * Get account watchlist elements
118
     * @param array $options
119
     * @return WatchList
120
     */
121 24
    public function getWatchList(array $options = array()) : WatchList
122
    {
123 24
        return $this->getList(WatchList::class, $options);
124
    }
125
126
    /**
127
     * Get account id
128
     * @return int account id
129
     */
130 48
    public function getId() : int
131
    {
132 48
        return $this->data->id;
133
    }
134
135
    /**
136
     * Get account language
137
     * @return string language code in standard ISO 639_1
138
     */
139 3
    public function getLanguage() : string
140
    {
141 3
        return $this->data->iso_639_1;
142
    }
143
144
    /**
145
     * Get country code
146
     * @return string country code in standard ISO 3166_1
147
     */
148 3
    public function getCountry() : string
149
    {
150 3
        return $this->data->iso_3166_1;
151
    }
152
153
    /**
154
     * Get account name
155
     * @return string account name
156
     */
157 3
    public function getName() : string
158
    {
159 3
        return $this->data->name;
160
    }
161
162
    /**
163
     * Get account username
164
     * @return string account username
165
     */
166 3
    public function getUsername() : string
167
    {
168 3
        return $this->data->username;
169
    }
170
171
    /**
172
     * Get Gravatar hash
173
     * @return string gravatar hash
174
     */
175 3
    public function getGravatarHash() : string
176
    {
177 3
        return $this->data->avatar->gravatar->hash;
178
    }
179
180
    /**
181
     * Get if account include adult content
182
     * @return bool
183
     */
184 3
    public function getIncludeAdult() : bool
185
    {
186 3
        return $this->data->include_adult;
187
    }
188
}
189