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_oEmbed::fetch()   B

Complexity

Conditions 8
Paths 7

Size

Total Lines 34

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 8
nc 7
nop 1
dl 0
loc 34
rs 8.1315
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 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_oEmbed" ) ) {
11
12
	require_once dirname( __FILE__ ) . '/class-foogallery-pro-video-base.php';
13
14
	class FooGallery_Pro_Video_oEmbed 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
		/**
17
		 * Takes a URL and attempts to return a result generated from its oEmbed data.
18
		 *
19
		 * @param string $url The url to fetch.
20
		 *
21
		 * @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...
22
		 *  "mode" => "embed",
23
		 *    "videos" => array(
24
		 *        array(
25
		 *            "provider" => string,
26
		 *            "id" => string,
27
		 *            "url" => string,
28
		 *            "thumbnail" => string,
29
		 *            "title" => string,
30
		 *            "description" => string,
31
		 *            "html" => string
32
		 *        )
33
		 *    )
34
		 * )
35
		 * @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...
36
		 *    "mode" => "error",
37
		 *    "title" => string,
38
		 *    "message" => string
39
		 * )
40
		 */
41
		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...
42
			// check if the url is not empty and is not false
43
			if ( empty( $url ) || $url === false ) {
44
				return $this->error_response( "Invalid url supplied." );
45
			}
46
47
			$data = foogallery_oembed_get_data( $url );
48
			if ( $data === false ) {
49
				return $this->error_response( "Unable to retrieve any data from the supplied URL." );
50
			}
51
			if ( strtolower( $data->type ) !== "video" ) {
52
				return $this->error_response( "The data returned for the supplied URL was not a video." );
53
			}
54
55
			$provider = sanitize_title($data->provider_name, "oembed");
56
57
			$video = array(
58
				"provider" => $provider,
59
				"id" => $this->get_id($provider, $url),
60
				"url" => $url,
61
				"thumbnail" => $data->thumbnail_url,
62
				"title" => $data->title,
63
				"description" => !empty($data->description) ? $data->description : ""
64
			);
65
66
			if (empty($data->thumbnail_url) || empty($data->title)) {
67
				$video["mode"] = "oembed";
68
				return $video;
69
			}
70
			return array(
71
				"mode" => "embed",
72
				"videos" => array($video)
73
			);
74
		}
75
76
		/**
77
		 * Gets a unique ID for the supplied provider and url.
78
		 *
79
		 * @param string $provider The provider for the current URL.
80
		 * @param string $url      The URL to the oEmbed video.
81
		 *
82
		 * @return string
83
		 */
84
		private function get_id( $provider, $url ) {
0 ignored issues
show
Unused Code introduced by
The parameter $url is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
85
			switch ( $provider ) {
86
				default:
0 ignored issues
show
Unused Code introduced by
default: return hash('crc32', $url, false); does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
87
					// this is setup so in the future we can handle different providers accordingly
88
					// but by default a ID is simply generated by hashing the url. This works fine as
89
					// the ID for oEmbed videos is just used to generate the uploaded filename and if
90
					// there is a duplicate WordPress will auto-append a count to the name in any case.
91
					return hash( 'crc32', $url, false );
92
			}
93
		}
94
	}
95
}