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.

FooGallery_Pro_Video_Self_Hosted   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 86
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 86
rs 10
c 0
b 0
f 0
wmc 7
lcom 1
cbo 1

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A handles() 0 3 1
A fetch() 0 28 5
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 14 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_Self_Hosted") ){
11
12
	require_once dirname(__FILE__) . '/class-foogallery-pro-video-base.php';
13
14
	class FooGallery_Pro_Video_Self_Hosted 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...
15
16
		// region Properties
17
18
		/**
19
		 * The regular expression used to match a self-hosted video URL.
20
		 * @var string
21
		 */
22
		public $regex_pattern;
23
		/**
24
		 * The array of supported MIME types for self-hosted videos.
25
		 * @var array
26
		 */
27
		public $mime_types;
28
29
		// endregion
30
31
		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...
32
			$this->regex_pattern = '/\/(?<name>[^\/]+?)\.(?<ext>mp4|ogg|ogv|webm)(?:$|\?|#|,)/i';
33
			$this->mime_types = array("video/mp4","video/ogg","video/ogv","video/webm");
34
		}
35
36
		/**
37
		 * Takes a URL and checks if this class handles it.
38
		 *
39
		 * @param string $url The URL to check.
40
		 * @param array &$matches Optional. If matches is provided, it is passed to the `preg_match` call used to check the URL.
41
		 * @return int Returns 1 if the URL is handled, 0 if it is not, or FALSE if an error occurred.
42
		 */
43
		function handles($url, &$matches = array()){
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...
44
			return preg_match($this->regex_pattern, $url, $matches);
45
		}
46
47
		/**
48
		 * Takes the supplied URL and fetches a self-hosted video object.
49
		 *
50
		 * @param string $url The URL to retrieve the video object for.
51
		 *
52
		 * @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...
53
		 * 	"mode" => "self-hosted",
54
		 * 	"id" => string,
55
		 * 	"thumbnail" => string,
56
		 * 	"title" => string,
57
		 * 	"description" => string,
58
		 * 	"urls" => array(
59
		 * 		"mp4" => string,
60
		 * 		"ogg" => string,
61
		 * 		"webm" => string
62
		 * 	)
63
		 * )
64
		 * @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...
65
		 * 	"mode" => "error",
66
		 * 	"title" => string,
67
		 * 	"message" => string
68
		 * )
69
		 */
70
		function fetch($url){
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...
71
			$matches = array();
72
			if ($this->handles($url, $matches)){
73
				$mime_type = $this->get_mime_type($url);
74
				if ($mime_type === false){
75
					return $this->error_response("Unable to retrieve the MIME type for the supplied URL.");
76
				}
77
				if (!in_array($mime_type, $this->mime_types)){
78
					return $this->error_response("The MIME type for the supplied URL is not supported.");
79
				}
80
				$result = array(
81
					"mode" => "self-hosted",
82
					"id" => $matches["name"] . "." . $matches["ext"],
83
					"thumbnail" => "",
84
					"title" => $matches["name"],
85
					"description" => "",
86
					"urls" => array(
87
						"mp4" => "",
88
						"ogg" => "",
89
						"webm" => ""
90
					)
91
				);
92
				$type = $matches["ext"] === "ogv" ? "ogg" : $matches["ext"];
93
				$result["urls"][$type] = $url;
94
				return $result;
95
			}
96
			return $this->error_response("The supplied URL is not supported.");
97
		}
98
99
	}
100
101
}