Total Complexity | 42 |
Total Lines | 252 |
Duplicated Lines | 0 % |
Changes | 0 |
Complex classes like client often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use client, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
9 | class client extends Google_Client |
||
10 | { |
||
11 | /** |
||
12 | * Google Client Instances. |
||
13 | * |
||
14 | * @var \Google_Client |
||
|
|||
15 | */ |
||
16 | private $Client; |
||
17 | /** |
||
18 | * Filemanager instance. |
||
19 | * |
||
20 | * @var \Filemanager\file |
||
21 | */ |
||
22 | private $filemanager; |
||
23 | private $token_folder; |
||
24 | private $configuration; |
||
25 | |||
26 | public function __construct(array $config = ['token' => ['folder' => __DIR__ . '/token']]) |
||
27 | { |
||
28 | parent::__construct($config); |
||
29 | $this->filemanager = new \Filemanager\file(); |
||
30 | if (isset($config['token']['folder'])) { |
||
31 | $token_folder = $config['token']['folder']; |
||
32 | $this->token_folder = $token_folder; |
||
33 | file::folder($token_folder, null, null, true); |
||
34 | file::file($token_folder . '/.htaccess', 'deny from all'); |
||
35 | file::file($token_folder . '/.gitignore', "*\n!.gitignore\n!.htaccess"); |
||
36 | } |
||
37 | $this->configuration = $config; |
||
38 | } |
||
39 | |||
40 | /** |
||
41 | * Check user google is login. |
||
42 | * |
||
43 | * @return bool |
||
44 | */ |
||
45 | public function is_login() |
||
46 | { |
||
47 | return isset($_SESSION['google']['login']) && !empty($_SESSION['google']['login']) && isset($_SESSION['google']['login']['email']); |
||
48 | } |
||
49 | |||
50 | /** |
||
51 | * Revoke token. |
||
52 | * |
||
53 | * @return $this |
||
54 | */ |
||
55 | public function revoke() |
||
56 | { |
||
57 | $this->revokeToken(); |
||
58 | |||
59 | $this; |
||
60 | } |
||
61 | |||
62 | /** |
||
63 | * Get current origin url. |
||
64 | * |
||
65 | * @return string |
||
66 | */ |
||
67 | public function getOrigin(string $path = null) |
||
68 | { |
||
69 | return (isset($_SERVER['HTTPS']) && 'on' === $_SERVER['HTTPS'] ? 'https' : 'http') . "://$_SERVER[HTTP_HOST]$path"; |
||
70 | } |
||
71 | |||
72 | public function get_token_folder() |
||
75 | } |
||
76 | |||
77 | public function set_token_folder(string $path) |
||
78 | { |
||
79 | if ($path = realpath($path)) { |
||
80 | $this->token_folder = $path; |
||
81 | } |
||
82 | |||
83 | return $this; |
||
84 | } |
||
85 | |||
86 | public function set_scope($scopes) |
||
87 | { |
||
88 | if (is_string($scopes)) { |
||
89 | if ($this->is_url($scopes)) { |
||
90 | $this->addScope($scopes); |
||
91 | } else { |
||
92 | throw new \MVC\Exception('Scope is URL format', 1); |
||
93 | |||
94 | return null; |
||
95 | } |
||
96 | } elseif (is_array($scopes)) { |
||
97 | $this->setScopes($scopes); |
||
98 | } |
||
99 | |||
100 | return $this; |
||
101 | } |
||
102 | |||
103 | /** |
||
104 | * Set access token offline. |
||
105 | * |
||
106 | * @param bool $offline |
||
107 | * |
||
108 | * @return client |
||
109 | */ |
||
110 | public function set_offline($offline = true) |
||
111 | { |
||
112 | if ($offline) { |
||
113 | $this->setAccessType('offline'); |
||
114 | $this->setApprovalPrompt('force'); |
||
115 | } else { |
||
116 | $this->setApprovalPrompt('auto'); |
||
117 | } |
||
118 | |||
119 | return $this; |
||
120 | } |
||
121 | |||
122 | /** |
||
123 | * Set default credentials. |
||
124 | * |
||
125 | * @return client |
||
126 | */ |
||
127 | public function setCredentials(string $client, string $secret, string $key) |
||
137 | } |
||
138 | |||
139 | /** |
||
140 | * Check if current instance is valid. |
||
141 | * |
||
142 | * @return bool |
||
143 | */ |
||
144 | public function isValid() |
||
145 | { |
||
146 | return $this->getAccessToken() && !$this->isAccessTokenExpired(); |
||
147 | } |
||
148 | |||
149 | public function is_url($string) |
||
150 | { |
||
151 | return filter_var($string, FILTER_VALIDATE_URL); |
||
152 | } |
||
153 | |||
154 | /** |
||
155 | * Check user has subscribed to youtube channel. |
||
156 | * |
||
157 | * @param string $cid channel id |
||
158 | * @param bool $only_get_url = return URL channel |
||
159 | */ |
||
160 | public function check_subscriber(string $cid = 'UCGNaoefvJRfd15fo-LQ0zvg', bool $only_get_url = false) |
||
161 | { |
||
162 | if (!$only_get_url) { |
||
163 | $service = new \Google_Service_YouTube($this); |
||
164 | $response = $service->subscriptions->listSubscriptions( |
||
165 | 'snippet,contentDetails', |
||
166 | array_filter(['forChannelId' => $cid, 'mine' => true]) |
||
167 | ); |
||
168 | |||
169 | $result = count($response['items']); |
||
170 | $output = []; |
||
171 | if ($result > 0) { |
||
172 | $output['success'] = true; |
||
173 | $output['data'] = $response['items']; |
||
174 | $_SESSION['subscribed'] = 1; |
||
175 | } else { |
||
176 | $output['error'] = true; |
||
177 | $output['data'] = 'Belum Subscribe'; |
||
178 | $output['msg'] = 'Belum Subscribe'; |
||
179 | $_SESSION['subscribed'] = 0; |
||
180 | } |
||
181 | } else { |
||
182 | $output = 'https://www.youtube.com/channel/' . $cid; |
||
183 | } |
||
184 | |||
185 | return $output; |
||
186 | } |
||
187 | |||
188 | public function auto_login() |
||
224 | } |
||
225 | } |
||
226 | } |
||
227 | |||
228 | /** |
||
229 | * Get current user login ($_SESSION['login']). |
||
230 | * |
||
231 | * @return array |
||
232 | */ |
||
233 | public function login_data() |
||
234 | { |
||
235 | return isset($_SESSION['login']) ? \ArrayHelper\helper::unset($_SESSION['login'], ['password']) : []; |
||
236 | } |
||
237 | |||
238 | /** |
||
239 | * Get current google user data. |
||
240 | * |
||
241 | * @return void |
||
242 | */ |
||
243 | public function userdata() |
||
244 | { |
||
245 | return isset($_SESSION['google']['login']) ? \ArrayHelper\helper::unset($_SESSION['google']['login'], ['password']) : []; |
||
246 | } |
||
247 | |||
248 | /** |
||
249 | * Fetch user information from google. |
||
250 | * |
||
251 | * @return array |
||
252 | */ |
||
253 | public function fetch_user() |
||
261 | } |
||
262 | } |
||
263 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths