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 — master ( 9c0c8a...f2b063 )
by Brad
05:17 queued 02:45
created

FooGallery_Pro_Video_Query::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 10
rs 9.9332
c 0
b 0
f 0
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 18 and the first side effect is on line 12.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
3
/**
4
 * Created by PhpStorm.
5
 * User: steve
6
 * Date: 4/17/2018
7
 * Time: 10:09 PM
8
 */
9
10
if ( !class_exists("FooGallery_Pro_Video_Query") ){
11
12
	require_once dirname(__FILE__) . '/class-foogallery-pro-video-base.php';
13
	require_once dirname(__FILE__) . '/class-foogallery-pro-video-self-hosted.php';
14
	require_once dirname(__FILE__) . '/class-foogallery-pro-video-oembed.php';
15
	require_once dirname(__FILE__) . '/class-foogallery-pro-video-youtube.php';
16
	require_once dirname(__FILE__) . '/class-foogallery-pro-video-vimeo.php';
17
18
	class FooGallery_Pro_Video_Query extends 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...
19
20
		public $self_hosted;
21
		public $oembed;
22
		public $youtube;
23
		public $vimeo;
24
25
		function __construct() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
26
27
			$this->self_hosted = new FooGallery_Pro_Video_Self_Hosted();
28
			$this->oembed = new FooGallery_Pro_Video_oEmbed();
29
			$this->youtube = new FooGallery_Pro_Video_YouTube();
30
			$this->vimeo = new FooGallery_Pro_Video_Vimeo();
31
32
			add_action('wp_ajax_fgi_query', array($this, 'ajax'));
33
34
		}
35
36
		/**
37
		 * Gets the query arguments from the variables supplied to the script via HTTP POST.
38
		 *
39
		 * @return array(
0 ignored issues
show
Documentation introduced by
The doc-type array( could not be parsed: Expected "|" or "end of type", but got "(" at position 5. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
40
		 * 	"query" => string,
41
		 * 	"page" => number,
42
		 * 	"offset" => number,
43
		 * 	"nonce" => string
44
		 * )
45
		 */
46
		public function get_args() {
47
			return array(
48
				"query" => !empty($_POST["query"]) ? trim($_POST["query"]) : null,
49
				"page" => !empty($_POST["page"]) ? (int)$_POST["page"] : 1,
50
				"offset" => !empty($_POST["offset"]) ? (int)$_POST["offset"] : 0,
51
				"nonce" => !empty($_POST["fgi_nonce"]) ? $_POST["fgi_nonce"] : null
52
			);
53
		}
54
55
		/**
56
		 * The AJAX handler for the query side of the plugin that returns videos to the front-end so the user can decide what to import.
57
		 */
58
		public function ajax() {
59
			$args = $this->get_args();
60
			if (wp_verify_nonce($args["nonce"], "fgi_nonce")){
61
				if (empty($args["query"]) || mb_strlen($args["query"], "UTF-8") < 3) {
62
					wp_send_json_error("The 'query' argument is required and must be a minimum of 3 characters in length.");
63
					return;
64
				}
65
				$response = $this->handle_query($args["query"], $args["page"], $args["offset"]);
66
				// regardless of the request all successful queries contain the original query in the response
67
				$response["query"] = $args["query"];
68
				wp_send_json_success($response);
69
			}
70
			die();
71
		}
72
73
		/**
74
		 * @param $query
75
		 * @param int $page
76
		 * @param int $offset
77
		 * @return array
78
		 */
79
		public function handle_query($query, $page = 1, $offset = 0) {
80
			// parse the query to test if it is a valid url
81
			$url = wp_http_validate_url($query);
82
83
			// if we have a valid url then try fetch the required data
84
			if ($url !== false) {
85
				// handle YouTube specific urls as we parse playlists etc.
86
				if ($this->youtube->handles($url)) {
87
					return $this->youtube->fetch($url);
88
				}
89
				// handle Vimeo specific urls as we parse albums etc.
90
				if ($this->vimeo->handles($url)) {
91
					return $this->vimeo->fetch($url, $page, $offset);
92
				}
93
				// check if this is a self hosted video
94
				if ($this->self_hosted->handles($url)){
95
					return $this->self_hosted->fetch($url);
96
				}
97
				// if we get here let the url be handled by the built in WP_oEmbed class
98
				return $this->oembed->fetch($url);
99
			}
100
101
			// if we get here the query was a not a url
102
			return $this->youtube->query($query, $page, $offset);
103
		}
104
	}
105
106
}