GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — feature/video-support ( 96814b )
by Brad
05:36
created

FooGallery_Pro_Video_Base::url_exists()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * Base class for video imports and queries
4
 * Date: 17/04/2018
5
 */
6
if ( ! class_exists( 'FooGallery_Pro_Video_Base' ) ) {
7
8
	class FooGallery_Pro_Video_Base {
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
9
10
		protected function error_response($message = "Unknown Error", $title = "An Error Occurred") {
11
			return array(
12
				"mode" => "error",
13
				"title" => $title,
14
				"message" => $message
15
			);
16
		}
17
18
		protected function get_json($url) {
19
			$remote = wp_remote_get($url);
20
			if (is_wp_error($remote)) {
21
				return $this->error_response("Error fetching JSON: " . $remote->get_error_message());
22
			}
23
			// get the json string from the body of the response
24
			$body = wp_remote_retrieve_body($remote);
25
			// decode it into an object
26
			$json = json_decode($body);
27
			if (!is_object($json) && !is_array($json)){
28
				return $this->error_response("Error fetching JSON: Invalid response body, unable to decode.");
29
			}
30
			return $json;
31
		}
32
33
		protected function is_error($response) {
34
			return is_array($response) && $response["mode"] === "error";
35
		}
36
37
		protected function url_exists($url){
38
			$remote = wp_safe_remote_head($url);
39
			return !is_wp_error($remote) && wp_remote_retrieve_response_code($remote) === 200;
40
		}
41
42
		protected function get_mime_type($url){
43
			$remote = wp_safe_remote_head($url);
44
			if (is_wp_error($remote)) {
45
				return false;
46
			}
47
			if ( !empty($remote) && is_array($remote["response"]) && $remote["response"]["code"] === 200 ){
48
				return wp_remote_retrieve_header($remote, "content-type");
49
			}
50
			return false;
51
		}
52
	}
53
}